• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #define LOG_TAG "VehicleService"
18 
19 #include <DefaultVehicleHal.h>
20 #include <FakeVehicleHardware.h>
21 
22 #include <android/binder_manager.h>
23 #include <android/binder_process.h>
24 #include <utils/Log.h>
25 
26 using ::android::hardware::automotive::vehicle::DefaultVehicleHal;
27 using ::android::hardware::automotive::vehicle::fake::FakeVehicleHardware;
28 
main(int,char * [])29 int main(int /* argc */, char* /* argv */[]) {
30     std::unique_ptr<FakeVehicleHardware> hardware = std::make_unique<FakeVehicleHardware>();
31     std::shared_ptr<DefaultVehicleHal> vhal =
32             ::ndk::SharedRefBase::make<DefaultVehicleHal>(std::move(hardware));
33 
34     ALOGI("Registering as service...");
35     binder_exception_t err = AServiceManager_addService(
36             vhal->asBinder().get(), "android.hardware.automotive.vehicle.IVehicle/default");
37     if (err != EX_NONE) {
38         ALOGE("failed to register android.hardware.automotive.vehicle service, exception: %d", err);
39         return 1;
40     }
41 
42     if (!ABinderProcess_setThreadPoolMaxThreadCount(4)) {
43         ALOGE("%s", "failed to set thread pool max thread count");
44         return 1;
45     }
46     ABinderProcess_startThreadPool();
47 
48     ALOGI("Vehicle Service Ready");
49 
50     ABinderProcess_joinThreadPool();
51 
52     ALOGI("Vehicle Service Exiting");
53 
54     return 0;
55 }
56