1 /*
2  * Copyright (C) 2024 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 #include <map>
17 #include <string>
18 #include <vector>
19 
20 #include "NfcJniUtil.h"
21 #include "nfa_ee_api.h"
22 
23 using namespace std;
24 
25 #define MAX_NUM_NFCEE 0x06
26 
27 struct mNfceeData {
28   uint16_t mNfceeID[MAX_NUM_NFCEE];
29   tNFA_EE_STATUS mNfceeStatus[MAX_NUM_NFCEE];
30   tNFA_TECHNOLOGY_MASK mNfceeTechMask[MAX_NUM_NFCEE];
31   uint8_t mNfceePresent;
32 };
33 
34 /*****************************************************************************
35 **
36 **  Name:           NfceeManager
37 **
38 **  Description:    Manages NFC Execution Environments (NFCEE) by providing
39 **                  methods to initialize JNI elements,retrieve active NFCEE
40 **                  lists, and fetch NFCEE information from the NFC stack.
41 **
42 *****************************************************************************/
43 class NfceeManager {
44  public:
45   /*******************************************************************************
46   **
47   ** Function:        NfceeManager
48   **
49   ** Description:     Initialize member variables.
50   **
51   ** Returns:         None
52   **
53   *******************************************************************************/
54   NfceeManager();
55 
56   /*******************************************************************************
57   **
58   ** Function:        ~NfceeManager
59   **
60   ** Description:     Release all resources.
61   **
62   ** Returns:         None
63   **
64   *******************************************************************************/
65   ~NfceeManager();
66 
67   /*******************************************************************************
68   **
69   ** Function:        getInstance
70   **
71   ** Description:     Get the singleton of this object.
72   **
73   ** Returns:         Reference to this object.
74   **
75   *******************************************************************************/
76   static NfceeManager& getInstance();
77 
78   /*******************************************************************************
79   **
80   ** Function:        getActiveNfceeList
81   **
82   ** Description:     Get the list of Activated NFCEE.
83   **                  e: Java Virtual Machine.
84   **
85   ** Returns:         List of Activated NFCEE.
86   **
87   *******************************************************************************/
88   jobject getActiveNfceeList(JNIEnv* e);
89 
90   /*******************************************************************************
91   **
92   ** Function:        getNFCEeInfo
93   **
94   ** Description:     Get latest information about execution environments from
95   *stack.
96   **
97   ** Returns:         True if at least 1 EE is available.
98   **
99   *******************************************************************************/
100   bool getNFCEeInfo();
101 
102  private:
103   static NfceeManager sNfceeManager;
104   string eseName;
105   string uiccName;
106   tNFA_EE_INFO mEeInfo[MAX_NUM_NFCEE];
107   uint8_t mNumEePresent;
108   uint8_t mActualNumEe;
109   mNfceeData mNfceeData_t;
110   const char* mHashMapClassName = "java/util/HashMap";
111 };
112