1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <vibrator-impl/Vibrator.h>
18 #include "CustomVibrator.h"
19 
20 #include <android-base/logging.h>
21 #include <android/binder_manager.h>
22 #include <android/binder_process.h>
23 
24 using aidl::android::hardware::tests::extension::vibrator::CustomVibrator;
25 using aidl::android::hardware::vibrator::Vibrator;
26 
main()27 int main() {
28     // these are threads in addition to the one we are joining below, so this
29     // service will have a single thread
30     ABinderProcess_setThreadPoolMaxThreadCount(0);
31 
32     // making the core service
33     std::shared_ptr<Vibrator> vib = ndk::SharedRefBase::make<Vibrator>();
34     ndk::SpAIBinder vibBinder = vib->asBinder();
35 
36     // making the extension service
37     std::shared_ptr<CustomVibrator> cvib = ndk::SharedRefBase::make<CustomVibrator>();
38 
39     // need to attach the extension to the same binder we will be registering
40     CHECK(STATUS_OK == AIBinder_setExtension(vibBinder.get(), cvib->asBinder().get()));
41 
42     const std::string instance = std::string() + Vibrator::descriptor + "/default";
43     CHECK(STATUS_OK == AServiceManager_addService(vibBinder.get(), instance.c_str()));
44 
45     ABinderProcess_joinThreadPool();
46     return EXIT_FAILURE;  // should not reach
47 }
48