what-the-bank/sources/net/sf/scuba/smartcards/CardService.java

98 lines
3.5 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package net.sf.scuba.smartcards;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
/* loaded from: classes6.dex */
public abstract class CardService implements Serializable {
protected static final int SESSION_STARTED_STATE = 1;
protected static final int SESSION_STOPPED_STATE = 0;
private static final Map<String, String> objectToServiceMap;
private static final long serialVersionUID = 5618527358158494957L;
private Collection<APDUListener> apduListeners = new HashSet();
protected int state = 0;
public abstract void close();
public abstract byte[] getATR() throws CardServiceException;
public boolean isExtendedAPDULengthSupported() {
return false;
}
public abstract boolean isOpen();
public abstract void open() throws CardServiceException;
public abstract ResponseAPDU transmit(CommandAPDU commandAPDU) throws CardServiceException;
static {
HashMap hashMap = new HashMap();
objectToServiceMap = hashMap;
hashMap.put("javax.smartcardio.CardTerminal", "net.sf.scuba.smartcards.TerminalCardService");
hashMap.put("sun.security.smartcardio.TerminalImpl", "net.sf.scuba.smartcards.TerminalCardService");
hashMap.put("android.nfc.tech.IsoDep", "net.sf.scuba.smartcards.IsoDepCardService");
}
public static CardService getInstance(Object obj) {
Class<?> cls;
String value;
if (obj == null) {
throw new IllegalArgumentException();
}
String canonicalName = obj.getClass().getCanonicalName();
for (Map.Entry<String, String> entry : objectToServiceMap.entrySet()) {
try {
cls = Class.forName(entry.getKey());
value = entry.getValue();
} catch (ClassNotFoundException unused) {
continue;
}
if (cls.isInstance(obj)) {
try {
return (CardService) Class.forName(value).getConstructor(cls).newInstance(obj);
} catch (Exception e) {
throw new IllegalArgumentException(e);
break;
}
}
continue;
}
StringBuilder sb = new StringBuilder("Could not find a CardService for object of class \"");
sb.append(canonicalName);
sb.append("\"");
throw new IllegalArgumentException(sb.toString());
}
public void addAPDUListener(APDUListener aPDUListener) {
Collection<APDUListener> collection = this.apduListeners;
if (collection != null) {
collection.add(aPDUListener);
}
}
public void removeAPDUListener(APDUListener aPDUListener) {
Collection<APDUListener> collection = this.apduListeners;
if (collection != null) {
collection.remove(aPDUListener);
}
}
/* JADX INFO: Access modifiers changed from: protected */
public void notifyExchangedAPDU(int i, CommandAPDU commandAPDU, ResponseAPDU responseAPDU) {
Collection<APDUListener> collection = this.apduListeners;
if (collection == null || collection.size() <= 0) {
return;
}
APDUEvent aPDUEvent = new APDUEvent(this, "RAW", i, commandAPDU, responseAPDU);
Iterator<APDUListener> it = this.apduListeners.iterator();
while (it.hasNext()) {
it.next().exchangedAPDU(aPDUEvent);
}
}
}