Browse Source

fix: ensure logical channel is closed on select DF failure (#257)

Reviewed-on: https://gitea.angry.im/PeterCxy/OpenEUICC/pulls/257
Co-authored-by: septs <github@septs.pw>
Co-committed-by: septs <github@septs.pw>
septs 2 months ago
parent
commit
938e298ca3

+ 3 - 2
app-common/src/main/java/im/angry/openeuicc/core/usb/UsbApduInterface.kt

@@ -53,6 +53,7 @@ class UsbApduInterface(
 
 
         val channelId = resp[0].toInt()
         val channelId = resp[0].toInt()
         Log.d(TAG, "channelId = $channelId")
         Log.d(TAG, "channelId = $channelId")
+        channels.add(channelId)
 
 
         // Then, select AID
         // Then, select AID
         val selectAid = selectByDfCmd(aid, channelId.toByte())
         val selectAid = selectByDfCmd(aid, channelId.toByte())
@@ -60,11 +61,11 @@ class UsbApduInterface(
 
 
         if (!isSuccessResponse(selectAidResp)) {
         if (!isSuccessResponse(selectAidResp)) {
             Log.d(TAG, "Select DF failed : ${selectAidResp.encodeHex()}")
             Log.d(TAG, "Select DF failed : ${selectAidResp.encodeHex()}")
+            logicalChannelClose(channelId)
+            Log.d(TAG, "Closed logical channel $channelId due to select DF failure")
             return -1
             return -1
         }
         }
 
 
-        channels.add(channelId)
-
         return channelId
         return channelId
     }
     }