Browse Source

OmapiApduInterface: Log all APDU exchanges

Peter Cai 1 year ago
parent
commit
87ea017b36

+ 16 - 1
app-common/src/main/java/im/angry/openeuicc/core/OmapiApduInterface.kt

@@ -3,6 +3,7 @@ package im.angry.openeuicc.core
 import android.se.omapi.Channel
 import android.se.omapi.SEService
 import android.se.omapi.Session
+import android.util.Log
 import im.angry.openeuicc.util.*
 import net.typeblog.lpac_jni.ApduInterface
 
@@ -10,6 +11,10 @@ class OmapiApduInterface(
     private val service: SEService,
     private val port: UiccPortInfoCompat
 ): ApduInterface {
+    companion object {
+        const val TAG = "OmapiApduInterface"
+    }
+
     private lateinit var session: Session
     private lateinit var lastChannel: Channel
 
@@ -44,7 +49,17 @@ class OmapiApduInterface(
             "Unknown channel"
         }
 
-        return lastChannel.transmit(tx)
+        Log.d(TAG, "OMAPI APDU: ${tx.encodeHex()}")
+
+        try {
+            return lastChannel.transmit(tx).also {
+                Log.d(TAG, "OMAPI APDU response: ${it.encodeHex()}")
+            }
+        } catch (e: Exception) {
+            Log.e(TAG, "OMAPI APDU exception")
+            e.printStackTrace()
+            throw e
+        }
     }
 
 }