handle securityexceptions
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user