1 /* 2 * Copyright (C) 2023 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 "IvnAndroidDeviceImpl" 18 19 #include "IvnAndroidDeviceService.h" 20 21 #include <android-base/logging.h> 22 #include <android/binder_manager.h> 23 #include <android/binder_process.h> 24 #include <stdlib.h> 25 26 constexpr char SERVICE_NAME[] = "android.hardware.automotive.ivn.IIvnAndroidDevice/default"; 27 constexpr char DEFAULT_CONFIG_DIR[] = "/vendor/etc/automotive/IvnConfig/DefaultConfig.json"; 28 main(int,char * [])29int main(int /* argc */, char* /* argv */[]) { 30 LOG(INFO) << "Registering IvnAndroidDeviceService as service..."; 31 auto service = 32 ndk::SharedRefBase::make<android::hardware::automotive::ivn::IvnAndroidDeviceService>( 33 DEFAULT_CONFIG_DIR); 34 if (!service->init()) { 35 LOG(ERROR) << "Failed to init IvnAndroidDeviceService"; 36 exit(1); 37 } 38 39 binder_exception_t err = AServiceManager_addService(service->asBinder().get(), SERVICE_NAME); 40 if (err != EX_NONE) { 41 LOG(ERROR) << "Failed to register IvnAndroidDeviceService service, exception: " << err; 42 exit(1); 43 } 44 45 if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) { 46 LOG(ERROR) << "Failed to set thread pool max thread count"; 47 exit(1); 48 } 49 ABinderProcess_startThreadPool(); 50 51 LOG(INFO) << "IvnAndroidDeviceService Ready"; 52 53 ABinderProcess_joinThreadPool(); 54 55 LOG(ERROR) << "IvnAndroidDeviceService init failed! Should not reach here"; 56 57 return 0; 58 } 59