83 lines
2.5 KiB
Java
83 lines
2.5 KiB
Java
|
package net.sf.scuba.smartcards;
|
||
|
|
||
|
import android.nfc.tech.IsoDep;
|
||
|
import java.io.IOException;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class IsoDepCardService extends CardService {
|
||
|
private static final long serialVersionUID = -8123218195642784731L;
|
||
|
private int apduCount = 0;
|
||
|
private IsoDep nfc;
|
||
|
|
||
|
@Override // net.sf.scuba.smartcards.CardService
|
||
|
public byte[] getATR() {
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public IsoDepCardService(IsoDep isoDep) {
|
||
|
this.nfc = isoDep;
|
||
|
}
|
||
|
|
||
|
@Override // net.sf.scuba.smartcards.CardService
|
||
|
public void open() throws CardServiceException {
|
||
|
if (isOpen()) {
|
||
|
return;
|
||
|
}
|
||
|
try {
|
||
|
this.nfc.connect();
|
||
|
if (!this.nfc.isConnected()) {
|
||
|
throw new CardServiceException("failed to connect");
|
||
|
}
|
||
|
this.state = 1;
|
||
|
} catch (IOException e) {
|
||
|
throw new CardServiceException(e.toString());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // net.sf.scuba.smartcards.CardService
|
||
|
public boolean isOpen() {
|
||
|
if (this.nfc.isConnected()) {
|
||
|
this.state = 1;
|
||
|
return true;
|
||
|
}
|
||
|
this.state = 0;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
@Override // net.sf.scuba.smartcards.CardService
|
||
|
public ResponseAPDU transmit(CommandAPDU commandAPDU) throws CardServiceException {
|
||
|
try {
|
||
|
if (!this.nfc.isConnected()) {
|
||
|
throw new CardServiceException("Not connected");
|
||
|
}
|
||
|
byte[] transceive = this.nfc.transceive(commandAPDU.getBytes());
|
||
|
if (transceive == null || transceive.length < 2) {
|
||
|
throw new CardServiceException("Failed response");
|
||
|
}
|
||
|
ResponseAPDU responseAPDU = new ResponseAPDU(transceive);
|
||
|
int i = this.apduCount + 1;
|
||
|
this.apduCount = i;
|
||
|
notifyExchangedAPDU(i, commandAPDU, responseAPDU);
|
||
|
return responseAPDU;
|
||
|
} catch (IOException e) {
|
||
|
throw new CardServiceException(e.getMessage());
|
||
|
} catch (Exception e2) {
|
||
|
throw new CardServiceException(e2.getMessage());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // net.sf.scuba.smartcards.CardService
|
||
|
public boolean isExtendedAPDULengthSupported() {
|
||
|
return this.nfc.isExtendedLengthApduSupported();
|
||
|
}
|
||
|
|
||
|
@Override // net.sf.scuba.smartcards.CardService
|
||
|
public void close() {
|
||
|
try {
|
||
|
this.nfc.close();
|
||
|
this.state = 0;
|
||
|
} catch (IOException unused) {
|
||
|
}
|
||
|
}
|
||
|
}
|