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 #pragma once 18 #include "NfcJniUtil.h" 19 #include "nfa_wlc_api.h" 20 21 /***************************************************************************** 22 ** 23 ** Name: NativeWlcManager 24 ** 25 ** Description: Manage Wlc activities at stack level. 26 ** 27 *****************************************************************************/ 28 class NativeWlcManager { 29 public: 30 /******************************************************************************* 31 ** 32 ** Function: getInstance 33 ** 34 ** Description: Get the singleton of this object. 35 ** 36 ** Returns: Reference to this object. 37 ** 38 *******************************************************************************/ 39 static NativeWlcManager& getInstance(); 40 41 /******************************************************************************* 42 ** 43 ** Function: initialize 44 ** 45 ** Description: Reset member variables. 46 ** native: Native data. 47 ** 48 ** Returns: None 49 ** 50 *******************************************************************************/ 51 void initialize(nfc_jni_native_data* native); 52 53 /******************************************************************************* 54 ** 55 ** Function: registerJniFunctions 56 ** 57 ** Description: Register WLC JNI functions. 58 ** 59 ** Returns: None 60 ** 61 *******************************************************************************/ 62 int registerJniFunctions(JNIEnv* e); 63 64 /******************************************************************************* 65 ** 66 ** Function: notifyWlcCompletion 67 ** 68 ** Description: Notify end of WLC procedure. 69 ** wpt_end_condition: End condition from NFCC. 70 ** 71 ** Returns: None 72 ** 73 *******************************************************************************/ 74 void notifyWlcCompletion(uint8_t wpt_end_condition); 75 76 private: 77 // Fields below are final after initialize() 78 nfc_jni_native_data* mNativeData; 79 80 bool mIsWlcEnabled = false; 81 82 /******************************************************************************* 83 ** 84 ** Function: NativeWlcManager 85 ** 86 ** Description: Initialize member variables. 87 ** 88 ** Returns: None 89 ** 90 *******************************************************************************/ 91 NativeWlcManager(); 92 93 /******************************************************************************* 94 ** 95 ** Function: ~NativeWlcManager 96 ** 97 ** Description: Release all resources. 98 ** 99 ** Returns: None 100 ** 101 *******************************************************************************/ 102 ~NativeWlcManager(); 103 104 /******************************************************************************* 105 ** 106 ** Function: wlcManagementCallback 107 ** 108 ** Description: Callback function for the stack. 109 ** event: event ID. 110 ** eventData: event's data. 111 ** 112 ** Returns: None 113 ** 114 *******************************************************************************/ 115 static void wlcManagementCallback(tNFA_WLC_EVT wlcEvent, 116 tNFA_WLC_EVT_DATA* eventData); 117 118 static const JNINativeMethod sMethods[]; 119 120 static jboolean com_android_nfc_wlc_startWlcP(JNIEnv* e, jobject, jint mode); 121 static jboolean com_android_nfc_wlc_chargeWlcListener(JNIEnv* e, jobject, 122 jint power_adj_req, 123 jint wpt_time_int); 124 }; 125