@onekeyfe/react-native-lite-card 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactNativeLiteCard.podspec +2 -0
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/LoggerManager.kt +2 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +40 -28
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/broadcast/NfcStatusChangeBroadcastReceiver.kt +2 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +7 -5
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +5 -5
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/utils/LogUtil.kt +17 -3
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/utils/MiUtil.kt +5 -5
- package/ios/Classes/OKNFCBridge.mm +22 -6
- package/ios/Classes/OKNFTLite/OKLiteV1.m +19 -18
- package/ios/Classes/OKNFTLite/OKNFCManager.m +24 -10
- package/ios/Classes/Utils/LCLogger.h +16 -0
- package/ios/Classes/Utils/LCLogger.m +42 -0
- package/ios/Classes/Utils/OKNFCUtility.m +6 -5
- package/ios/ReactNativeLiteCard.mm +2 -0
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -82,4 +82,5 @@ dependencies {
|
|
|
82
82
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
83
83
|
implementation 'com.google.code.gson:gson:2.10.1'
|
|
84
84
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
|
85
|
+
implementation project(":onekeyfe_react-native-native-logger")
|
|
85
86
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
package com.onekeyfe.reactnativelitecard
|
|
2
2
|
|
|
3
|
-
import android.util.Log
|
|
4
3
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
4
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
6
5
|
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
7
7
|
import com.onekeyfe.reactnativelitecard.utils.sendEvent
|
|
8
8
|
|
|
9
9
|
class LoggerManager(private val context: ReactApplicationContext) :
|
|
@@ -29,7 +29,7 @@ class LoggerManager(private val context: ReactApplicationContext) :
|
|
|
29
29
|
|
|
30
30
|
@ReactMethod
|
|
31
31
|
public fun logInfo(message: String) {
|
|
32
|
-
|
|
32
|
+
OneKeyLog.info("LiteCard", message)
|
|
33
33
|
sendEvent(context, LOG_EVENT_INFO, message)
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -4,7 +4,7 @@ import android.content.Intent
|
|
|
4
4
|
import android.nfc.NfcAdapter
|
|
5
5
|
import android.nfc.Tag
|
|
6
6
|
import android.nfc.tech.IsoDep
|
|
7
|
-
import
|
|
7
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
8
8
|
import androidx.annotation.IntDef
|
|
9
9
|
import androidx.fragment.app.FragmentActivity
|
|
10
10
|
import kotlinx.coroutines.*
|
|
@@ -90,18 +90,18 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
90
90
|
putString("type", "unknown")
|
|
91
91
|
}
|
|
92
92
|
emitOnNFCActiveConnection(dataMap.copy())
|
|
93
|
-
|
|
93
|
+
OneKeyLog.debug("LiteCard","Unknown device")
|
|
94
94
|
return
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
OneKeyLog.debug("LiteCard",isoDep.toString())
|
|
98
98
|
launch(Dispatchers.IO) {
|
|
99
99
|
mNFCConnectedChannel.trySend(isoDep)
|
|
100
100
|
try {
|
|
101
101
|
// 处理主动触发 NFC
|
|
102
102
|
delay(100)
|
|
103
103
|
if (!mNFCConnectedChannel.isEmpty) {
|
|
104
|
-
|
|
104
|
+
OneKeyLog.error("LiteCard","There is no way to use NFC")
|
|
105
105
|
// mNFCConnectedChannel.receive()
|
|
106
106
|
val startRequest = OneKeyLiteCard.initRequest(isoDep)
|
|
107
107
|
val dataMap = Arguments.createMap().apply {
|
|
@@ -114,7 +114,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
114
114
|
emitOnNFCActiveConnection(dataMap.copy())
|
|
115
115
|
}
|
|
116
116
|
} catch (e: Exception) {
|
|
117
|
-
e.
|
|
117
|
+
OneKeyLog.error("LiteCard", "NFC connection failed: ${e.message}")
|
|
118
118
|
// 未知设备或连接失败
|
|
119
119
|
val dataMap = Arguments.createMap().apply {
|
|
120
120
|
putInt("code", -1)
|
|
@@ -208,12 +208,12 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
208
208
|
val topActivity = Utils.getTopActivity() ?: return
|
|
209
209
|
NfcPermissionUtils.checkPermission(topActivity) {
|
|
210
210
|
try {
|
|
211
|
-
|
|
211
|
+
OneKeyLog.debug("LiteCard","NFC permission check success")
|
|
212
212
|
val isoDep = acquireDevice() ?: return
|
|
213
213
|
val executeResult = execute(isoDep)
|
|
214
214
|
callback?.invoke(null, executeResult, mCurrentCardState.createArguments())
|
|
215
215
|
} catch (e: NFCExceptions) {
|
|
216
|
-
|
|
216
|
+
OneKeyLog.error("LiteCard", "NFC device execute error: ${e.message}")
|
|
217
217
|
callback?.invoke(e.createArguments(), null, mCurrentCardState.createArguments())
|
|
218
218
|
} finally {
|
|
219
219
|
releaseDevice()
|
|
@@ -221,7 +221,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
221
221
|
return
|
|
222
222
|
}
|
|
223
223
|
// 没有 NFC 使用权限
|
|
224
|
-
|
|
224
|
+
OneKeyLog.debug("LiteCard","NFC device not permission")
|
|
225
225
|
callback?.invoke(NFCExceptions.NotNFCPermission().createArguments(), null, null)
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -245,11 +245,11 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
245
245
|
|
|
246
246
|
override fun getLiteInfo(callback: Callback?) {
|
|
247
247
|
launch {
|
|
248
|
-
|
|
248
|
+
OneKeyLog.debug("LiteCard","getLiteInfo")
|
|
249
249
|
handleOperation<Any>(callback) { isoDep ->
|
|
250
|
-
|
|
250
|
+
OneKeyLog.debug("LiteCard","getLiteInfo Obtain the device")
|
|
251
251
|
val cardInfo = OneKeyLiteCard.getCardInfo(isoDep)
|
|
252
|
-
|
|
252
|
+
OneKeyLog.debug("LiteCard","getLiteInfo result obtained")
|
|
253
253
|
cardInfo.createArguments()
|
|
254
254
|
}
|
|
255
255
|
}
|
|
@@ -264,7 +264,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
264
264
|
val isNfcExists = NfcUtils.isNfcExits(topActivity)
|
|
265
265
|
if (!isNfcExists) {
|
|
266
266
|
// 没有 NFC 设备
|
|
267
|
-
|
|
267
|
+
OneKeyLog.debug("LiteCard","NFC device not found")
|
|
268
268
|
callback?.invoke(NFCExceptions.NotExistsNFC().createArguments(), null, null)
|
|
269
269
|
return
|
|
270
270
|
}
|
|
@@ -272,7 +272,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
272
272
|
val isNfcEnable = NfcUtils.isNfcEnable(topActivity)
|
|
273
273
|
if (!isNfcEnable) {
|
|
274
274
|
// 没有打开 NFC 开关
|
|
275
|
-
|
|
275
|
+
OneKeyLog.debug("LiteCard","NFC device not enable")
|
|
276
276
|
callback?.invoke(NFCExceptions.NotEnableNFC().createArguments(), null, null)
|
|
277
277
|
return
|
|
278
278
|
}
|
|
@@ -281,7 +281,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
281
281
|
return
|
|
282
282
|
}
|
|
283
283
|
// 没有 NFC 使用权限
|
|
284
|
-
|
|
284
|
+
OneKeyLog.debug("LiteCard","NFC device not permission")
|
|
285
285
|
callback?.invoke(NFCExceptions.NotNFCPermission().createArguments(), null, null)
|
|
286
286
|
}
|
|
287
287
|
|
|
@@ -291,9 +291,17 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
291
291
|
overwrite: Boolean,
|
|
292
292
|
callback: Callback?
|
|
293
293
|
) {
|
|
294
|
+
if (pwd.isNullOrEmpty() || pwd.length != 6 || !pwd.all { it.isDigit() }) {
|
|
295
|
+
callback?.invoke(NFCExceptions.InputPasswordEmptyException().createArguments(), null, null)
|
|
296
|
+
return
|
|
297
|
+
}
|
|
298
|
+
if (mnemonic.isNullOrEmpty()) {
|
|
299
|
+
callback?.invoke(NFCExceptions.ExecFailureException().createArguments(), null, null)
|
|
300
|
+
return
|
|
301
|
+
}
|
|
294
302
|
launch {
|
|
295
303
|
handleOperation(callback) { isoDep ->
|
|
296
|
-
|
|
304
|
+
OneKeyLog.debug("LiteCard","setMnemonic Obtain the device")
|
|
297
305
|
val isSuccess =
|
|
298
306
|
OneKeyLiteCard.setMnemonic(
|
|
299
307
|
mCurrentCardState,
|
|
@@ -303,7 +311,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
303
311
|
overwrite
|
|
304
312
|
)
|
|
305
313
|
if (!isSuccess) throw NFCExceptions.ExecFailureException()
|
|
306
|
-
|
|
314
|
+
OneKeyLog.debug("LiteCard","setMnemonic result success")
|
|
307
315
|
true
|
|
308
316
|
}
|
|
309
317
|
}
|
|
@@ -313,10 +321,14 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
313
321
|
pwd: String,
|
|
314
322
|
callback: Callback?
|
|
315
323
|
) {
|
|
324
|
+
if (pwd.isEmpty() || pwd.length != 6 || !pwd.all { it.isDigit() }) {
|
|
325
|
+
callback?.invoke(NFCExceptions.InputPasswordEmptyException().createArguments(), null, null)
|
|
326
|
+
return
|
|
327
|
+
}
|
|
316
328
|
launch {
|
|
317
|
-
|
|
329
|
+
OneKeyLog.debug("LiteCard","getMnemonicWithPin")
|
|
318
330
|
handleOperation(callback) { isoDep ->
|
|
319
|
-
|
|
331
|
+
OneKeyLog.debug("LiteCard","getMnemonicWithPin Obtain the device")
|
|
320
332
|
OneKeyLiteCard.getMnemonicWithPin(mCurrentCardState, isoDep, pwd)
|
|
321
333
|
}
|
|
322
334
|
}
|
|
@@ -328,9 +340,9 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
328
340
|
callback: Callback?
|
|
329
341
|
) {
|
|
330
342
|
launch {
|
|
331
|
-
|
|
343
|
+
OneKeyLog.debug("LiteCard","changePin")
|
|
332
344
|
handleOperation(callback) { isoDep ->
|
|
333
|
-
|
|
345
|
+
OneKeyLog.debug("LiteCard","changePin Obtain the device")
|
|
334
346
|
OneKeyLiteCard.changPin(mCurrentCardState, isoDep, oldPin, newPin)
|
|
335
347
|
}
|
|
336
348
|
}
|
|
@@ -338,12 +350,12 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
338
350
|
|
|
339
351
|
override fun reset(callback: Callback?) {
|
|
340
352
|
launch {
|
|
341
|
-
|
|
353
|
+
OneKeyLog.debug("LiteCard","reset")
|
|
342
354
|
handleOperation(callback) { isoDep ->
|
|
343
|
-
|
|
355
|
+
OneKeyLog.debug("LiteCard","reset Obtain the device")
|
|
344
356
|
val isSuccess = OneKeyLiteCard.reset(isoDep)
|
|
345
357
|
if (!isSuccess) throw NFCExceptions.ExecFailureException()
|
|
346
|
-
|
|
358
|
+
OneKeyLog.debug("LiteCard","reset result success")
|
|
347
359
|
true
|
|
348
360
|
}
|
|
349
361
|
}
|
|
@@ -357,7 +369,7 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
357
369
|
|
|
358
370
|
override fun intoSetting() {
|
|
359
371
|
launch {
|
|
360
|
-
|
|
372
|
+
OneKeyLog.debug("LiteCard","intoSetting")
|
|
361
373
|
Utils.getTopActivity()?.let {
|
|
362
374
|
NfcUtils.intentToNfcSetting(it)
|
|
363
375
|
}
|
|
@@ -401,10 +413,10 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
401
413
|
try {
|
|
402
414
|
OneKeyLiteCard.startNfc(it) {
|
|
403
415
|
mNFCState.set(NFCState.Started)
|
|
404
|
-
|
|
416
|
+
OneKeyLog.debug("LiteCard","NFC starting success")
|
|
405
417
|
}
|
|
406
418
|
} catch (e: Exception) {
|
|
407
|
-
|
|
419
|
+
OneKeyLog.error("LiteCard", "startNfc failed: ${e.message}")
|
|
408
420
|
}
|
|
409
421
|
}
|
|
410
422
|
}
|
|
@@ -416,9 +428,9 @@ class ReactNativeLiteCardModule(val reactContext: ReactApplicationContext) :
|
|
|
416
428
|
try {
|
|
417
429
|
OneKeyLiteCard.stopNfc(it as FragmentActivity)
|
|
418
430
|
mNFCState.set(NFCState.Dead)
|
|
419
|
-
|
|
431
|
+
OneKeyLog.debug("LiteCard","NFC 已关闭")
|
|
420
432
|
} catch (e: Exception) {
|
|
421
|
-
|
|
433
|
+
OneKeyLog.error("LiteCard", "stopNfc failed: ${e.message}")
|
|
422
434
|
}
|
|
423
435
|
}
|
|
424
436
|
}
|
|
@@ -5,7 +5,7 @@ import android.content.Context
|
|
|
5
5
|
import android.content.Intent
|
|
6
6
|
import android.content.IntentFilter
|
|
7
7
|
import android.nfc.NfcAdapter
|
|
8
|
-
import
|
|
8
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
9
9
|
|
|
10
10
|
open class NfcStatusChangeBroadcastReceiver : BroadcastReceiver() {
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ open class NfcStatusChangeBroadcastReceiver : BroadcastReceiver() {
|
|
|
15
15
|
val state =
|
|
16
16
|
intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF)
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
OneKeyLog.debug("LiteCard", "nfc state broadcast receiver, state is $state")
|
|
19
19
|
when (state) {
|
|
20
20
|
NfcAdapter.STATE_OFF -> onNfcOff()
|
|
21
21
|
NfcAdapter.STATE_ON -> onNfcOn()
|
|
@@ -2,8 +2,8 @@ package com.onekeyfe.reactnativelitecard.onekeyLite
|
|
|
2
2
|
|
|
3
3
|
import android.app.Activity
|
|
4
4
|
import android.nfc.tech.IsoDep
|
|
5
|
-
import android.util.Log
|
|
6
5
|
import androidx.fragment.app.FragmentActivity
|
|
6
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
7
7
|
import androidx.lifecycle.Lifecycle
|
|
8
8
|
import com.google.gson.Gson
|
|
9
9
|
import kotlinx.coroutines.Dispatchers
|
|
@@ -20,9 +20,10 @@ import com.onekeyfe.reactnativelitecard.utils.NfcPermissionUtils
|
|
|
20
20
|
object OneKeyLiteCard {
|
|
21
21
|
const val TAG = "OneKeyLiteCard"
|
|
22
22
|
|
|
23
|
-
private val mCommandGenerator by lazy
|
|
23
|
+
private val mCommandGenerator by lazy {
|
|
24
24
|
CommandGenerator()
|
|
25
25
|
}
|
|
26
|
+
@Volatile
|
|
26
27
|
private var mCardConnection: Connection? = null
|
|
27
28
|
|
|
28
29
|
suspend fun startNfc(activity: FragmentActivity, callback: ((Boolean) -> Unit)? = null) =
|
|
@@ -52,7 +53,7 @@ object OneKeyLiteCard {
|
|
|
52
53
|
callback?.invoke(true)
|
|
53
54
|
return@withContext
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
OneKeyLog.error("LiteCard","startNfc Not NFC permission")
|
|
56
57
|
callback?.invoke(false)
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -110,7 +111,7 @@ object OneKeyLiteCard {
|
|
|
110
111
|
): Boolean {
|
|
111
112
|
if (cardState == null) throw NFCExceptions.ConnectionFailException()
|
|
112
113
|
|
|
113
|
-
printLog(TAG, "--> setMnemonic: cardState:${
|
|
114
|
+
printLog(TAG, "--> setMnemonic: isNewCard:${cardState?.isNewCard}, hasBackup:${cardState?.hasBackup}")
|
|
114
115
|
|
|
115
116
|
if (!overwrite) {
|
|
116
117
|
// 不是覆写要验证是否已经已经存有备份
|
|
@@ -146,7 +147,8 @@ object OneKeyLiteCard {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
if (mnemonic.isNullOrEmpty()) throw NFCExceptions.ExecFailureException()
|
|
151
|
+
return mCardConnection?.backupData(mnemonic) == true
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
@Throws(NFCExceptions::class)
|
|
@@ -140,7 +140,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
140
140
|
|
|
141
141
|
printLog(TAG, "0. ---> getDeviceCertificate begin")
|
|
142
142
|
val certInfo = getDeviceCertificate() ?: return false
|
|
143
|
-
printLog(TAG, "0. <--- getDeviceCertificate end
|
|
143
|
+
printLog(TAG, "0. <--- getDeviceCertificate end")
|
|
144
144
|
|
|
145
145
|
printLog(TAG, "1. ---> nativeGPCInitialize begin")
|
|
146
146
|
val param = SecureChanelParam.objectFromData(
|
|
@@ -303,7 +303,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
303
303
|
mCardType, CommandType.SETUP_NEW_PIN, hasOpenSafeChannel, "DFFE0B8204080006$pinHex"
|
|
304
304
|
)
|
|
305
305
|
val res = command.send(this)
|
|
306
|
-
printLog(TAG, "<--- setupNewPin end: ${res.getCode()}
|
|
306
|
+
printLog(TAG, "<--- setupNewPin end: ${res.getCode()} area:${mCommandArea}")
|
|
307
307
|
|
|
308
308
|
if (!res.isSuccess()) {
|
|
309
309
|
return false
|
|
@@ -326,7 +326,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
326
326
|
)
|
|
327
327
|
val res = command.send(this)
|
|
328
328
|
|
|
329
|
-
printLog(TAG, "<--- changePin end: ${res.getCode()}
|
|
329
|
+
printLog(TAG, "<--- changePin end: ${res.getCode()} area:${mCommandArea}")
|
|
330
330
|
|
|
331
331
|
return if (res.isConnectFailure()) {
|
|
332
332
|
NfcConstant.INTERRUPT_STATUS
|
|
@@ -356,7 +356,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
356
356
|
mCardType, CommandType.VERIFY_PIN, hasOpenSafeChannel, "06$pinHex"
|
|
357
357
|
)
|
|
358
358
|
val res = command.send(this)
|
|
359
|
-
printLog(TAG, "<--- startVerifyPin end: ${res.getCode()}
|
|
359
|
+
printLog(TAG, "<--- startVerifyPin end: ${res.getCode()} area:${mCommandArea}")
|
|
360
360
|
|
|
361
361
|
return if (res.isConnectFailure()) {
|
|
362
362
|
NfcConstant.INTERRUPT_STATUS
|
|
@@ -385,7 +385,7 @@ class Connection(val isoDep: IsoDep, private val mCommandGenerator: CommandGener
|
|
|
385
385
|
mCardType, CommandType.BACKUP_DATA, hasOpenSafeChannel, mnemonic
|
|
386
386
|
)
|
|
387
387
|
val res = command.send(this)
|
|
388
|
-
printLog(TAG, "<--- backupData end: ${res.getCode()}
|
|
388
|
+
printLog(TAG, "<--- backupData end: ${res.getCode()} area:${mCommandArea}")
|
|
389
389
|
|
|
390
390
|
if (!res.isSuccess()) {
|
|
391
391
|
return false
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
package com.onekeyfe.reactnativelitecard.utils
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import com.
|
|
3
|
+
import android.content.pm.ApplicationInfo
|
|
4
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
5
5
|
|
|
6
6
|
object LogUtil {
|
|
7
|
+
// Only enable detailed NFC/APDU logging in debug builds
|
|
8
|
+
// Uses FLAG_DEBUGGABLE from the host app's ApplicationInfo at runtime,
|
|
9
|
+
// rather than the library's BuildConfig which won't reflect the host's build type.
|
|
10
|
+
private val isDebug: Boolean by lazy {
|
|
11
|
+
try {
|
|
12
|
+
val app = Utils.getApp()
|
|
13
|
+
app != null && (app.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0
|
|
14
|
+
} catch (_: Exception) {
|
|
15
|
+
false
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
@JvmStatic
|
|
8
20
|
fun printLog(tag: String, msg: String) {
|
|
9
|
-
if (
|
|
21
|
+
if (isDebug) {
|
|
22
|
+
OneKeyLog.debug(tag, msg)
|
|
23
|
+
}
|
|
10
24
|
}
|
|
11
25
|
}
|
|
@@ -6,8 +6,8 @@ import android.content.Intent
|
|
|
6
6
|
import android.net.Uri
|
|
7
7
|
import android.os.Build
|
|
8
8
|
import android.provider.Settings
|
|
9
|
-
import android.util.Log
|
|
10
9
|
import androidx.annotation.IntDef
|
|
10
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
11
11
|
import androidx.annotation.RequiresApi
|
|
12
12
|
import com.onekeyfe.reactnativelitecard.utils.MiUtil.PermissionResult.Companion.PERMISSION_ASK
|
|
13
13
|
import com.onekeyfe.reactnativelitecard.utils.MiUtil.PermissionResult.Companion.PERMISSION_DENIED
|
|
@@ -59,13 +59,13 @@ object MiUtil {
|
|
|
59
59
|
//the ops of NFC is 10016,check /data/system/appops/xxx.xml
|
|
60
60
|
val invoke = checkOpNoThrowMethod.invoke(mAppOps, 10016, uid, pkg)
|
|
61
61
|
if (invoke == null) {
|
|
62
|
-
|
|
62
|
+
OneKeyLog.debug("LiteCard",
|
|
63
63
|
"MIUI check permission checkOpNoThrowMethod(AppOpsManager) invoke result is null"
|
|
64
64
|
)
|
|
65
65
|
return PERMISSION_UNKNOWN
|
|
66
66
|
}
|
|
67
67
|
val result = invoke.toString()
|
|
68
|
-
|
|
68
|
+
OneKeyLog.debug("LiteCard",
|
|
69
69
|
"MIUI check permission checkOpNoThrowMethod(AppOpsManager) invoke result = $result"
|
|
70
70
|
)
|
|
71
71
|
when (result) {
|
|
@@ -74,7 +74,7 @@ object MiUtil {
|
|
|
74
74
|
"5" -> return PERMISSION_ASK
|
|
75
75
|
}
|
|
76
76
|
} catch (e: Exception) {
|
|
77
|
-
|
|
77
|
+
OneKeyLog.debug("LiteCard", "check nfc permission fail: ${e.message}")
|
|
78
78
|
}
|
|
79
79
|
return PERMISSION_UNKNOWN
|
|
80
80
|
}
|
|
@@ -86,7 +86,7 @@ object MiUtil {
|
|
|
86
86
|
context.startActivity(intent)
|
|
87
87
|
true
|
|
88
88
|
} catch (e: Exception) {
|
|
89
|
-
|
|
89
|
+
OneKeyLog.debug("LiteCard", "open app setting fail: ${e.message}")
|
|
90
90
|
false
|
|
91
91
|
}
|
|
92
92
|
}
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
#import "OKNFCBridge.h"
|
|
20
|
+
#import "LCLogger.h"
|
|
20
21
|
|
|
21
22
|
@implementation OKNFCBridge
|
|
22
23
|
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
NSString *hexStr = [NSString stringWithCString:c_apdu encoding:NSUTF8StringEncoding];
|
|
48
|
+
JUB_FreeMemory(c_apdu);
|
|
47
49
|
NSData *APDUData = [hexStr dataFromHexString];
|
|
48
50
|
NFCISO7816APDU *apdu = [[NFCISO7816APDU alloc] initWithData:APDUData];
|
|
49
51
|
return apdu;
|
|
@@ -84,6 +86,8 @@
|
|
|
84
86
|
return NO;
|
|
85
87
|
}
|
|
86
88
|
|
|
89
|
+
JUB_FreeMemory(value);
|
|
90
|
+
|
|
87
91
|
JUB_UINT16 wRet = 0;
|
|
88
92
|
JUB_CHAR_PTR pDecResp = nullptr;
|
|
89
93
|
rv = JUB_GPC_ParseAPDUResponse(c_data,&wRet, &pDecResp);
|
|
@@ -130,7 +134,9 @@
|
|
|
130
134
|
return nil;
|
|
131
135
|
}
|
|
132
136
|
|
|
133
|
-
|
|
137
|
+
NSString *result = [NSString stringWithFormat:@"%s", mutualAuthData];
|
|
138
|
+
JUB_FreeMemory(mutualAuthData);
|
|
139
|
+
return result;
|
|
134
140
|
}
|
|
135
141
|
|
|
136
142
|
+ (BOOL)openChannel:(NSData *)authRes {
|
|
@@ -139,10 +145,10 @@
|
|
|
139
145
|
|
|
140
146
|
rv = JUB_GPC_OpenSecureChannel(authResp);
|
|
141
147
|
if (JUBR_OK != rv) {
|
|
142
|
-
|
|
148
|
+
[LCLogger error:@"JUB_GPC_OpenSecureChannel failed"];
|
|
143
149
|
return NO;
|
|
144
150
|
}
|
|
145
|
-
|
|
151
|
+
[LCLogger debug:@"openChannel success"];
|
|
146
152
|
return YES;
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -161,10 +167,11 @@
|
|
|
161
167
|
JUB_CHAR_PTR subjectID = nullptr;
|
|
162
168
|
rv = JUB_GPC_ParseCertificate(value, &sn, &subjectID);
|
|
163
169
|
if (JUBR_OK != rv) {
|
|
170
|
+
JUB_FreeMemory(value);
|
|
164
171
|
return NO;
|
|
165
172
|
}
|
|
166
173
|
|
|
167
|
-
|
|
174
|
+
[LCLogger debug:@"subjectID parsed"];
|
|
168
175
|
GPC_SCP11_SHAREDINFO shareInfo;
|
|
169
176
|
shareInfo.scpID = (char *)"1107";
|
|
170
177
|
shareInfo.keyUsage = (char *)"3C";
|
|
@@ -178,11 +185,15 @@
|
|
|
178
185
|
|
|
179
186
|
rv = JUB_GPC_Initialize(shareInfo, [NFCConfig envFor:@"crt"].UTF8String, sk);
|
|
180
187
|
|
|
188
|
+
JUB_FreeMemory(value);
|
|
189
|
+
JUB_FreeMemory(sn);
|
|
190
|
+
JUB_FreeMemory(subjectID);
|
|
191
|
+
|
|
181
192
|
if (JUBR_OK != rv) {
|
|
182
193
|
return NO;
|
|
183
194
|
}
|
|
184
195
|
|
|
185
|
-
|
|
196
|
+
[LCLogger debug:@"JUB_GPC_Initialize OK"];
|
|
186
197
|
return YES;
|
|
187
198
|
}
|
|
188
199
|
|
|
@@ -205,6 +216,7 @@
|
|
|
205
216
|
JUB_CHAR_PTR subjectID = nullptr;
|
|
206
217
|
rv = JUB_GPC_ParseCertificate(value, &sn, &subjectID);
|
|
207
218
|
if (JUBR_OK != rv) {
|
|
219
|
+
JUB_FreeMemory(value);
|
|
208
220
|
return NO;
|
|
209
221
|
}
|
|
210
222
|
|
|
@@ -212,7 +224,11 @@
|
|
|
212
224
|
|
|
213
225
|
BOOL identical = [certSN isEqualToString:cardSN];
|
|
214
226
|
|
|
215
|
-
|
|
227
|
+
JUB_FreeMemory(value);
|
|
228
|
+
JUB_FreeMemory(sn);
|
|
229
|
+
JUB_FreeMemory(subjectID);
|
|
230
|
+
|
|
231
|
+
[LCLogger debug:[NSString stringWithFormat:@"certSN verification: %@", identical ? @"PASS" : @"FAIL"]];
|
|
216
232
|
return identical;
|
|
217
233
|
}
|
|
218
234
|
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#import "OKLiteV1.h"
|
|
9
9
|
#import "OKNFCUtility.h"
|
|
10
10
|
#import "OKLiteCommandModal.h"
|
|
11
|
+
#import "LCLogger.h"
|
|
11
12
|
|
|
12
13
|
@interface OKLiteV1()
|
|
13
14
|
|
|
@@ -214,7 +215,7 @@
|
|
|
214
215
|
dispatch_semaphore_signal(sema);
|
|
215
216
|
}];
|
|
216
217
|
|
|
217
|
-
dispatch_semaphore_wait(sema,
|
|
218
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
218
219
|
return success;
|
|
219
220
|
}
|
|
220
221
|
|
|
@@ -344,7 +345,7 @@
|
|
|
344
345
|
selectSuccess = sw1 == OKNFC_SW1_OK;
|
|
345
346
|
dispatch_semaphore_signal(sema);
|
|
346
347
|
}];
|
|
347
|
-
dispatch_semaphore_wait(sema,
|
|
348
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
348
349
|
if (selectSuccess) {
|
|
349
350
|
self.selectNFCApp = app;
|
|
350
351
|
} else {
|
|
@@ -371,7 +372,7 @@
|
|
|
371
372
|
dispatch_semaphore_signal(sema);
|
|
372
373
|
}];
|
|
373
374
|
}];
|
|
374
|
-
dispatch_semaphore_wait(sema,
|
|
375
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
375
376
|
return success;
|
|
376
377
|
}
|
|
377
378
|
|
|
@@ -389,7 +390,7 @@
|
|
|
389
390
|
SN = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
|
|
390
391
|
dispatch_semaphore_signal(sema);
|
|
391
392
|
}];
|
|
392
|
-
dispatch_semaphore_wait(sema,
|
|
393
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
393
394
|
return SN;
|
|
394
395
|
}
|
|
395
396
|
|
|
@@ -425,7 +426,7 @@
|
|
|
425
426
|
result = OKNFCLitePINVerifyResultPass;
|
|
426
427
|
dispatch_semaphore_signal(sema);
|
|
427
428
|
}];
|
|
428
|
-
dispatch_semaphore_wait(sema,
|
|
429
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
429
430
|
return result;
|
|
430
431
|
}
|
|
431
432
|
|
|
@@ -450,26 +451,26 @@
|
|
|
450
451
|
isVerificationPass = YES;
|
|
451
452
|
|
|
452
453
|
if (sw1 != OKNFC_SW1_OK) {
|
|
453
|
-
|
|
454
|
+
[LCLogger error:@"获取证书失败"];
|
|
454
455
|
isVerificationPass = NO;
|
|
455
456
|
dispatch_semaphore_signal(sema);
|
|
456
457
|
return;
|
|
457
458
|
}
|
|
458
459
|
|
|
459
460
|
if (![OKNFCBridge verifySN:self.SN withCert:certData]) {
|
|
460
|
-
|
|
461
|
+
[LCLogger error:@"验证证书失败"];
|
|
461
462
|
isVerificationPass = NO;
|
|
462
463
|
}
|
|
463
464
|
|
|
464
465
|
if (![OKNFCBridge JUB_GPC_Initialize:certData]) {
|
|
465
|
-
|
|
466
|
+
[LCLogger error:@"初始化安全通道失败"];
|
|
466
467
|
isVerificationPass = NO;
|
|
467
468
|
}
|
|
468
469
|
|
|
469
470
|
dispatch_semaphore_signal(sema);
|
|
470
471
|
}];
|
|
471
472
|
|
|
472
|
-
dispatch_semaphore_wait(sema,
|
|
473
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
473
474
|
self.certVerified = isVerificationPass;
|
|
474
475
|
|
|
475
476
|
return isVerificationPass;
|
|
@@ -486,12 +487,12 @@
|
|
|
486
487
|
modal:modal
|
|
487
488
|
completionHandler:^(NSData * _Nonnull responseData, uint8_t sw1, uint8_t sw2, NSError * _Nullable error, NSString * _Nonnull parseRespon) {
|
|
488
489
|
if (sw1 != OKNFC_SW1_OK) {
|
|
489
|
-
|
|
490
|
+
[LCLogger error:@"获取 PIN 状态失败"];
|
|
490
491
|
dispatch_semaphore_signal(sema);
|
|
491
492
|
return;
|
|
492
493
|
}
|
|
493
494
|
if (responseData.toHexString.intValue == 2) {
|
|
494
|
-
|
|
495
|
+
[LCLogger debug:@"未设置 PIN"];
|
|
495
496
|
pinStatus = OKNFC_PIN_UNSET;
|
|
496
497
|
dispatch_semaphore_signal(sema);
|
|
497
498
|
return;
|
|
@@ -509,7 +510,7 @@
|
|
|
509
510
|
}
|
|
510
511
|
}];
|
|
511
512
|
|
|
512
|
-
dispatch_semaphore_wait(sema,
|
|
513
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
513
514
|
return pinStatus;
|
|
514
515
|
}
|
|
515
516
|
|
|
@@ -527,7 +528,7 @@
|
|
|
527
528
|
dispatch_semaphore_signal(sema);
|
|
528
529
|
}];
|
|
529
530
|
|
|
530
|
-
dispatch_semaphore_wait(sema,
|
|
531
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
531
532
|
return success;
|
|
532
533
|
}
|
|
533
534
|
|
|
@@ -551,7 +552,7 @@
|
|
|
551
552
|
dispatch_semaphore_signal(sema);
|
|
552
553
|
}];
|
|
553
554
|
|
|
554
|
-
dispatch_semaphore_wait(sema,
|
|
555
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
555
556
|
return mnc;
|
|
556
557
|
}
|
|
557
558
|
|
|
@@ -568,11 +569,11 @@
|
|
|
568
569
|
return;
|
|
569
570
|
}
|
|
570
571
|
success = YES;
|
|
571
|
-
|
|
572
|
+
[LCLogger debug:@"成功设置 PIN"];
|
|
572
573
|
dispatch_semaphore_signal(sema);
|
|
573
574
|
}];
|
|
574
575
|
|
|
575
|
-
dispatch_semaphore_wait(sema,
|
|
576
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
576
577
|
return success;
|
|
577
578
|
}
|
|
578
579
|
|
|
@@ -597,11 +598,11 @@
|
|
|
597
598
|
return;
|
|
598
599
|
}
|
|
599
600
|
result = OKNFCLiteChangePinResultPass;
|
|
600
|
-
|
|
601
|
+
[LCLogger debug:@"成功修改 PIN"];
|
|
601
602
|
dispatch_semaphore_signal(sema);
|
|
602
603
|
}];
|
|
603
604
|
|
|
604
|
-
dispatch_semaphore_wait(sema,
|
|
605
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
605
606
|
return result;
|
|
606
607
|
}
|
|
607
608
|
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#import "OKNFCBridge.h"
|
|
10
10
|
#import "OKNFCUtility.h"
|
|
11
11
|
#import <CoreNFC/CoreNFC.h>
|
|
12
|
+
#import "LCLogger.h"
|
|
12
13
|
//#import "OKNFCHintViewController.h"
|
|
13
14
|
//#import "OKMnemonic.h"
|
|
14
15
|
#import "NSString+OKAdd.h"
|
|
@@ -82,15 +83,15 @@
|
|
|
82
83
|
#pragma mark - NFCTagReaderSessionDelegate
|
|
83
84
|
|
|
84
85
|
- (void)tagReaderSession:(NFCTagReaderSession *)session didDetectTags:(NSArray<__kindof id<NFCTag>> *)tags {
|
|
85
|
-
|
|
86
|
+
[LCLogger debug:@"tagReaderSession didDetectTags"];
|
|
86
87
|
|
|
87
88
|
id<NFCISO7816Tag> tag = [tags.firstObject asNFCISO7816Tag];
|
|
88
89
|
if (!tag) { return; }
|
|
89
90
|
|
|
90
91
|
[session connectToTag:tag completionHandler:^(NSError * _Nullable error) {
|
|
91
92
|
if (error) {
|
|
92
|
-
NSString *errMsg = [NSString stringWithFormat:@"
|
|
93
|
-
|
|
93
|
+
NSString *errMsg = [NSString stringWithFormat:@"connectToTag error: %@", error.localizedDescription];
|
|
94
|
+
[LCLogger error:errMsg];
|
|
94
95
|
// [kTools debugTipMessage:errMsg];
|
|
95
96
|
[self endNFCSessionWithError:YES];
|
|
96
97
|
return;
|
|
@@ -100,7 +101,7 @@
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
- (void)tagReaderSession:(NFCTagReaderSession *)session didInvalidateWithError:(NSError *)error {
|
|
103
|
-
|
|
104
|
+
[LCLogger debug:[NSString stringWithFormat:@"tagReaderSession didInvalidateWithError: %@", error.localizedDescription]];
|
|
104
105
|
if (error.code == 200 || error.code == 6) {
|
|
105
106
|
switch (self.sessionType) {
|
|
106
107
|
case OKNFCLiteSessionTypeGetInfo:
|
|
@@ -144,7 +145,7 @@
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
- (void)tagReaderSessionDidBecomeActive:(NFCTagReaderSession *)session {
|
|
147
|
-
|
|
148
|
+
[LCLogger debug:@"tagReaderSessionDidBecomeActive"];
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
#pragma mark - Tasks
|
|
@@ -237,7 +238,12 @@
|
|
|
237
238
|
|
|
238
239
|
- (void)_setMnemonic:(BOOL)force {
|
|
239
240
|
SetMnemonicCallback callback = [_completionBlocks objectForKey:kSetMnemonicBlock];
|
|
240
|
-
|
|
241
|
+
NSString *mnemonic = self.exportMnemonic;
|
|
242
|
+
NSString *pin = self.pin;
|
|
243
|
+
// Clear sensitive data from properties immediately
|
|
244
|
+
self.exportMnemonic = nil;
|
|
245
|
+
self.pin = nil;
|
|
246
|
+
[self.lite setMnemonic:mnemonic withPin:pin overwrite:force complete:callback];
|
|
241
247
|
}
|
|
242
248
|
|
|
243
249
|
#pragma mark - getMnemonic
|
|
@@ -254,7 +260,10 @@
|
|
|
254
260
|
|
|
255
261
|
- (void)_getMnemonic {
|
|
256
262
|
GetMnemonicCallback callback = [_completionBlocks objectForKey:kGetMnemonicBlock];
|
|
257
|
-
|
|
263
|
+
NSString *pin = self.pin;
|
|
264
|
+
// Clear sensitive data from property immediately
|
|
265
|
+
self.pin = nil;
|
|
266
|
+
[self.lite getMnemonicWithPin:pin complete:callback];
|
|
258
267
|
}
|
|
259
268
|
|
|
260
269
|
#pragma mark - changePin
|
|
@@ -269,7 +278,12 @@
|
|
|
269
278
|
|
|
270
279
|
- (void)_changePin {
|
|
271
280
|
ChangePinCallback callback = [_completionBlocks objectForKey:kChangePinBlock];
|
|
272
|
-
|
|
281
|
+
NSString *oldPin = self.pin;
|
|
282
|
+
NSString *newPin = self.neoPin;
|
|
283
|
+
// Clear sensitive data from properties immediately
|
|
284
|
+
self.pin = nil;
|
|
285
|
+
self.neoPin = nil;
|
|
286
|
+
[self.lite changePin:oldPin to:newPin complete:callback];
|
|
273
287
|
}
|
|
274
288
|
|
|
275
289
|
#pragma mark - reset
|
|
@@ -306,7 +320,7 @@
|
|
|
306
320
|
|
|
307
321
|
dispatch_semaphore_signal(sema);
|
|
308
322
|
}];
|
|
309
|
-
dispatch_semaphore_wait(sema,
|
|
323
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
310
324
|
|
|
311
325
|
if(success) {
|
|
312
326
|
self.lite = [[OKLiteV1 alloc] initWithDelegate:self];
|
|
@@ -317,7 +331,7 @@
|
|
|
317
331
|
success = sw1 == OKNFC_SW1_OK;
|
|
318
332
|
dispatch_semaphore_signal(sema);
|
|
319
333
|
}];
|
|
320
|
-
dispatch_semaphore_wait(sema,
|
|
334
|
+
dispatch_semaphore_wait(sema, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC));
|
|
321
335
|
if (success) {
|
|
322
336
|
self.lite = [[OKLiteV2 alloc] initWithDelegate:self];
|
|
323
337
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
/// Lightweight logging wrapper that dynamically dispatches to OneKeyLog.
|
|
6
|
+
/// Avoids `@import ReactNativeNativeLogger` which fails when C++ modules are disabled.
|
|
7
|
+
@interface LCLogger : NSObject
|
|
8
|
+
|
|
9
|
+
+ (void)debug:(NSString *)message;
|
|
10
|
+
+ (void)info:(NSString *)message;
|
|
11
|
+
+ (void)warn:(NSString *)message;
|
|
12
|
+
+ (void)error:(NSString *)message;
|
|
13
|
+
|
|
14
|
+
@end
|
|
15
|
+
|
|
16
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#import "LCLogger.h"
|
|
2
|
+
|
|
3
|
+
static NSString *const kTag = @"LiteCard";
|
|
4
|
+
|
|
5
|
+
@implementation LCLogger
|
|
6
|
+
|
|
7
|
+
+ (void)debug:(NSString *)message {
|
|
8
|
+
[self _log:@"debug::" message:message];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
+ (void)info:(NSString *)message {
|
|
12
|
+
[self _log:@"info::" message:message];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
+ (void)warn:(NSString *)message {
|
|
16
|
+
[self _log:@"warn::" message:message];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
+ (void)error:(NSString *)message {
|
|
20
|
+
[self _log:@"error::" message:message];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
#pragma mark - Private
|
|
24
|
+
|
|
25
|
+
+ (void)_log:(NSString *)selectorName message:(NSString *)message {
|
|
26
|
+
Class logClass = NSClassFromString(@"ReactNativeNativeLogger.OneKeyLog");
|
|
27
|
+
if (!logClass) {
|
|
28
|
+
logClass = NSClassFromString(@"OneKeyLog");
|
|
29
|
+
}
|
|
30
|
+
if (!logClass) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
SEL sel = NSSelectorFromString(selectorName);
|
|
34
|
+
if (![logClass respondsToSelector:sel]) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
typedef void (*LogFunc)(id, SEL, NSString *, NSString *);
|
|
38
|
+
LogFunc func = (LogFunc)[logClass methodForSelector:sel];
|
|
39
|
+
func(logClass, sel, kTag, message);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@end
|
|
@@ -6,16 +6,17 @@
|
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
#import "OKNFCUtility.h"
|
|
9
|
+
#import "LCLogger.h"
|
|
9
10
|
|
|
10
11
|
@implementation OKNFCUtility
|
|
11
12
|
|
|
12
13
|
+ (void)logAPDU:(NSString *)name response:(NSData *)responseData sw1:(uint8_t)sw1 sw2:(uint8_t)sw2 error:(NSError *)error {
|
|
13
14
|
BOOL ok = sw1 == OKNFC_SW1_OK;
|
|
14
|
-
NSString *
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
NSString *msg = [NSString stringWithFormat:@"APDU %@: %@ sw1:%d(%x) sw2:%d(%x)", name, ok ? @"OK" : @"FAIL", sw1, sw1, sw2, sw2];
|
|
16
|
+
if (ok) {
|
|
17
|
+
[LCLogger debug:msg];
|
|
18
|
+
} else {
|
|
19
|
+
[LCLogger error:msg];
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
#import "NFCConfig.h"
|
|
4
4
|
#import "OKNFCManager.h"
|
|
5
5
|
#import "OKLiteV1.h"
|
|
6
|
+
#import "LCLogger.h"
|
|
6
7
|
|
|
7
8
|
typedef NS_ENUM(NSInteger, NFCLiteExceptions) {
|
|
8
9
|
NFCLiteExceptionsInitChannel = 1000,// 初始化异常
|
|
@@ -34,6 +35,7 @@ typedef NS_ENUM(NSInteger, NFCLiteExceptions) {
|
|
|
34
35
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
35
36
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
36
37
|
{
|
|
38
|
+
[LCLogger info:@"ReactNativeLiteCard module initialized"];
|
|
37
39
|
return std::make_shared<facebook::react::NativeReactNativeLiteCardSpecJSI>(params);
|
|
38
40
|
}
|
|
39
41
|
|