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 #include <android-base/logging.h> 18 #include <android-base/properties.h> 19 #include <android/binder_manager.h> 20 #include <android/binder_process.h> 21 #include <dlfcn.h> 22 23 #include "Nfc.h" 24 25 #define VENDOR_LIB_PATH "/vendor/lib64/" 26 #define VENDOR_LIB_EXT ".so" 27 28 using ::aidl::android::hardware::nfc::Nfc; 29 30 typedef int (*STEseReset)(void); 31 main()32int main() { 33 void* stdll = nullptr; 34 LOG(INFO) << "NFC AIDL HAL Service is starting up"; 35 36 std::string valueStr = 37 android::base::GetProperty("persist.vendor.nfc.streset", ""); 38 if (valueStr.length() > 0) { 39 stdll = dlopen(valueStr.c_str(), RTLD_NOW); 40 if (!stdll) { 41 valueStr = VENDOR_LIB_PATH + valueStr + VENDOR_LIB_EXT; 42 stdll = dlopen(valueStr.c_str(), RTLD_NOW); 43 } 44 if (stdll) { 45 LOG(INFO) << "ST NFC HAL STReset starting."; 46 STEseReset fn = (STEseReset)dlsym(stdll, "boot_reset"); 47 if (fn) { 48 int ret = fn(); 49 LOG(INFO) << "STReset Result= " << ret; 50 } 51 LOG(INFO) << ("ST NFC HAL STReset Done."); 52 } 53 } 54 if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) { 55 LOG(INFO) << "failed to set thread pool max thread count"; 56 return 1; 57 } 58 std::shared_ptr<Nfc> nfc_service = ndk::SharedRefBase::make<Nfc>(); 59 60 const std::string instance = std::string() + Nfc::descriptor + "/default"; 61 binder_status_t status = AServiceManager_addService( 62 nfc_service->asBinder().get(), instance.c_str()); 63 CHECK(status == STATUS_OK); 64 ABinderProcess_joinThreadPool(); 65 return 0; 66 } 67