1 /*
2 * Copyright (C) 2022 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 "EmulatedVehicleService"
18
19 #include <DefaultVehicleHal.h>
20 #include <EmulatedVehicleHardware.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::EmulatedVehicleHardware;
28
main(int,char * [])29 int main(int /* argc */, char* /* argv */[]) {
30 ALOGI("Starting thread pool...");
31 if (!ABinderProcess_setThreadPoolMaxThreadCount(4)) {
32 ALOGE("%s", "failed to set thread pool max thread count");
33 return 1;
34 }
35 ABinderProcess_startThreadPool();
36
37 std::unique_ptr<EmulatedVehicleHardware> hardware = std::make_unique<EmulatedVehicleHardware>();
38 std::shared_ptr<DefaultVehicleHal> vhal =
39 ::ndk::SharedRefBase::make<DefaultVehicleHal>(std::move(hardware));
40
41 ALOGI("Emulator Vehicle Service: Registering as service...");
42 binder_exception_t err = AServiceManager_addService(
43 vhal->asBinder().get(), "android.hardware.automotive.vehicle.IVehicle/default");
44 if (err != EX_NONE) {
45 ALOGE("failed to register android.hardware.automotive.vehicle service, exception: %d", err);
46 return 1;
47 }
48
49 ALOGI("Emulator Vehicle Service Ready");
50
51 ABinderProcess_joinThreadPool();
52
53 ALOGI("Emulator Vehicle Service Exiting");
54
55 return 0;
56 }
57