Yubico / yubikit-android

Yubico Mobile Android SDK - YubiKit
Apache License 2.0
102 stars 38 forks source link

Catch SecurityException when NFC key is removed #80

Closed AdamVe closed 1 year ago

AdamVe commented 1 year ago

Android 13 introduced the following change:

Stack trace for reference:

java.lang.SecurityException: Permission Denial: Tag ( ID: 27 AB A7 25 01 A7 AB ) is out of date
  at android.nfc.Tag.getTagService(Tag.java:381)
  at android.nfc.tech.BasicTagTechnology.isConnected(BasicTagTechnology.java:63)
  at android.nfc.tech.IsoDep.isConnected(IsoDep.java:40)
  at com.yubico.yubikit.android.transport.nfc.NfcYubiKeyDevice.lambda$remove$0$com-yubico-yubikit-android-transport-nfc-NfcYubiKeyDevice(NfcYubiKeyDevice.java:102)

I couldn't find any official documentation for this, but the commit. #79 has been reproduced on Android 13 device and the issue is coming from that uncaught SecurityException.

This PR adds handling of the exception in the remove method to be able to call the onRemoved runnable. It is safe to ignore this SecurityException and it has no effect on devices running Android < 13.