1 /******************************************************************************
2 *
3 * Copyright 2019-2020 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 #define LOG_TAG "nxpnfc@2.0-service"
20 #include <android/hardware/nfc/1.1/INfc.h>
21 #include <unistd.h>
22 #include <vendor/nxp/nxpnfc/2.0/INxpNfc.h>
23
24 #include <hidl/LegacySupport.h>
25 #include "Nfc.h"
26 #include "NxpNfc.h"
27 #include "eSEClientExtns.h"
28
29 // Generated HIDL files
30 using android::OK;
31 using android::sp;
32 using android::status_t;
33 using android::hardware::configureRpcThreadpool;
34 using android::hardware::joinRpcThreadpool;
35 using android::hardware::nfc::V1_2::INfc;
36 using android::hardware::nfc::V1_2::implementation::Nfc;
37 using vendor::nxp::nxpnfc::V2_0::INxpNfc;
38 using vendor::nxp::nxpnfc::V2_0::implementation::NxpNfc;
39
main()40 int main() {
41 status_t status;
42
43 sp<INfc> nfc_service = nullptr;
44 sp<INxpNfc> nxp_nfc_service = nullptr;
45
46 ALOGD("NFC HAL Service 1.2 is starting.");
47 nfc_service = new Nfc();
48 if (nfc_service == nullptr) {
49 ALOGE("Can not create an instance of NFC HAL Iface, exiting.");
50 return -1;
51 }
52
53 configureRpcThreadpool(1, true /*callerWillJoin*/);
54 initializeEseClient();
55 checkEseClientUpdate();
56 try {
57 status = nfc_service->registerAsService();
58 if (status != OK) {
59 LOG_ALWAYS_FATAL("Could not register service for NFC HAL Iface (%d).",
60 status);
61 return -1;
62 }
63 } catch (const std::length_error& le) {
64 ALOGE(
65 "Could not register ese_wired_service service due to exception "
66 "reason %s ",
67 le.what());
68 }
69
70 ALOGI("NXP NFC Extn Service 1.0 is starting.");
71 nxp_nfc_service = new NxpNfc();
72 if (nxp_nfc_service == nullptr) {
73 ALOGE("Can not create an instance of NXP NFC Extn Iface, exiting.");
74 return -1;
75 }
76 try {
77 status = nxp_nfc_service->registerAsService();
78 if (status != OK) {
79 ALOGE("Could not register service for NXP NFC Extn Iface (%d).", status);
80 }
81 } catch (const std::__1::system_error& e) {
82 ALOGE(
83 "Could not register nxp_nfc_service service due to exception reason "
84 "%s ",
85 e.what());
86 } catch (const std::length_error& le) {
87 ALOGE(
88 "Could not register ese_wired_service service due to exception "
89 "reason %s ",
90 le.what());
91 }
92
93 ALOGE("Before calling JCOP JCOS_doDownload");
94 perform_eSEClientUpdate();
95 ALOGE("After calling JCOS_doDownload");
96 ALOGI("NFC service is ready");
97 joinRpcThreadpool();
98 return 1;
99 }
100