1 /****************************************************************************** 2 * 3 * Copyright 2022 NXP 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #include <android-base/logging.h> 20 #include <android/binder_manager.h> 21 #include <android/binder_process.h> 22 23 #include <thread> 24 25 #include "Nfc.h" 26 #include "NxpNfc.h" 27 #include "phNxpNciHal_Adaptation.h" 28 #include "phNxpNciHal_Recovery.h" 29 30 using ::aidl::android::hardware::nfc::Nfc; 31 using ::aidl::vendor::nxp::nxpnfc_aidl::INxpNfc; 32 using ::aidl::vendor::nxp::nxpnfc_aidl::NxpNfc; 33 using namespace std; 34 startNxpNfcAidlService()35void startNxpNfcAidlService() { 36 ALOGI("NXP NFC Extn Service is starting."); 37 std::shared_ptr<NxpNfc> nxp_nfc_service = ndk::SharedRefBase::make<NxpNfc>(); 38 const std::string nxpNfcInstName = 39 std::string() + NxpNfc::descriptor + "/default"; 40 ALOGI("NxpNfc Registering service: %s", nxpNfcInstName.c_str()); 41 binder_status_t status = AServiceManager_addService( 42 nxp_nfc_service->asBinder().get(), nxpNfcInstName.c_str()); 43 ALOGI("NxpNfc Registered INxpNfc service status: %d", status); 44 CHECK(status == STATUS_OK); 45 ABinderProcess_joinThreadPool(); 46 } 47 main()48int main() { 49 ALOGI("NFC AIDL HAL starting up"); 50 if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) { 51 ALOGE("failed to set thread pool max thread count"); 52 return 1; 53 } 54 std::shared_ptr<Nfc> nfc_service = ndk::SharedRefBase::make<Nfc>(); 55 56 const std::string nfcInstName = std::string() + Nfc::descriptor + "/default"; 57 binder_status_t status = AServiceManager_addService( 58 nfc_service->asBinder().get(), nfcInstName.c_str()); 59 CHECK(status == STATUS_OK); 60 61 #if (NXP_NFC_RECOVERY == TRUE) 62 phNxpNciHal_RecoverFWTearDown(); 63 #endif 64 thread t1(startNxpNfcAidlService); 65 ABinderProcess_joinThreadPool(); 66 return 0; 67 } 68