handle securityexceptions

This commit is contained in:
Michele Balistreri
2023-02-06 13:01:59 +01:00
parent 78c6dfb6d6
commit ccb353ca82
2 changed files with 20 additions and 7 deletions
@@ -24,14 +24,23 @@ public class NFCCardChannel implements CardChannel {
public APDUResponse send(APDUCommand cmd) throws IOException {
byte[] apdu = cmd.serialize();
Log.d(TAG, String.format("COMMAND CLA: %02X INS: %02X P1: %02X P2: %02X LC: %02X", cmd.getCla(), cmd.getIns(), cmd.getP1(), cmd.getP2(), cmd.getData().length));
byte[] resp = this.isoDep.transceive(apdu);
APDUResponse response = new APDUResponse(resp);
Log.d(TAG, String.format("RESPONSE LEN: %02X, SW: %04X %n-----------------------", response.getData().length, response.getSw()));
return response;
try {
byte[] resp = this.isoDep.transceive(apdu);
APDUResponse response = new APDUResponse(resp);
Log.d(TAG, String.format("RESPONSE LEN: %02X, SW: %04X %n-----------------------", response.getData().length, response.getSw()));
return response;
} catch(SecurityException e) {
throw new IOException("Tag disconnected", e);
}
}
@Override
public boolean isConnected() {
return this.isoDep.isConnected();
try {
return this.isoDep.isConnected();
} catch(SecurityException e) {
return false;
}
}
}
@@ -48,7 +48,11 @@ public class NFCCardManager extends Thread implements NfcAdapter.ReaderCallback
* @return if connected, false otherwise
*/
public boolean isConnected() {
return isoDep != null && isoDep.isConnected();
try {
return isoDep != null && isoDep.isConnected();
} catch (SecurityException e) {
return false;
}
}
@Override
@@ -58,7 +62,7 @@ public class NFCCardManager extends Thread implements NfcAdapter.ReaderCallback
isoDep = IsoDep.get(tag);
isoDep.connect();
isoDep.setTimeout(120000);
} catch (IOException e) {
} catch (IOException | SecurityException e) {
Log.e(TAG, "error connecting to tag");
}
}