use of net.rim.device.api.io.nfc.se.SecureElementManager in project Samples-for-Java by blackberry.
the class NfcMidlet2 method removeTransactionListener.
public void removeTransactionListener() {
SecureElementManager sem = SecureElementManager.getInstance();
if (sem == null) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " removeTransactionListener instance is null - exiting");
return;
}
Utilities.log("XXXX " + Thread.currentThread().getName() + " removeTransactionListener SecureElement instance of type SIM");
SecureElement se = null;
try {
se = sem.getSecureElement(SecureElement.SIM);
} catch (Exception e1) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " removeTransactionListener when getting SE: " + e1.getClass().getName() + ":" + e1.getMessage());
}
if (se == null) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " removeTransactionListener(SIM) is null - exiting");
return;
}
try {
myListener = getTransactionListener();
Utilities.log("XXXX " + Thread.currentThread().getName() + " TransactionListener=" + myListener);
if (myListener != null) {
se.removeTransactionListener(myListener);
Utilities.log("XXXX " + Thread.currentThread().getName() + " removeTransactionListener listener OK");
}
} catch (Exception e) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " removeTransactionListener when removing TransactionListener:" + e.getClass().getName() + ":" + e.getMessage());
}
Utilities.log("XXXX " + Thread.currentThread().getName() + " removed TransactionListener from RuntimeStore");
runtimeStore.remove(TRANSACTION_LISTENER);
}
use of net.rim.device.api.io.nfc.se.SecureElementManager in project Samples-for-Java by blackberry.
the class CardEmulation method registerTransactionListener.
public static void registerTransactionListener(TransactionListener tl) {
int pid = ApplicationManager.getApplicationManager().getProcessId(ApplicationDescriptor.currentApplicationDescriptor());
Settings settings = Settings.getInstance();
SecureElementManager sem = SecureElementManager.getInstance();
if (sem == null) {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " SecureElementManager instance is null - exiting");
System.exit(0);
}
SecureElement[] sec_elements = null;
try {
sec_elements = sem.getSecureElements();
} catch (NFCException e2) {
e2.printStackTrace();
}
if (sec_elements == null) {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " SecureElement[] is null - exiting");
System.exit(0);
}
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " device has " + sec_elements.length + " SEs");
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " getting SecureElement instance");
SecureElement se = null;
try {
if (settings.isSimSeSelected()) {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " Obtaining SecureElement in SIM");
se = sem.getSecureElement(SecureElement.SIM);
} else {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " Obtaining embedded SecureElement");
se = sem.getSecureElement(SecureElement.EMBEDDED);
}
} catch (NFCException e1) {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " exception when getting SE: " + e1.getClass().getName() + ":" + e1.getMessage());
}
if (se == null) {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " SecureElement is null - exiting");
System.exit(0);
}
// register our app as a transaction listener
try {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " adding transaction listener for AID:" + settings.getRegisteredAIDAsString());
se.addTransactionListener(tl, new byte[][] { settings.getRegisteredAID() });
_tl = tl;
} catch (NFCException e) {
if (!e.getMessage().startsWith("TransactionListener has already been added")) {
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " exception when adding transaction listener: " + e.getClass().getName() + ":" + e.getMessage());
System.exit(0);
}
}
}
use of net.rim.device.api.io.nfc.se.SecureElementManager in project Samples-for-Java by blackberry.
the class NfcMidlet2 method addTransactionListener.
public void addTransactionListener() {
SecureElementManager sem = SecureElementManager.getInstance();
if (sem == null) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:SecureElementManager instance is null - exiting");
return;
}
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:getting SecureElement instance of type SIM");
SecureElement se = null;
try {
se = sem.getSecureElement(SecureElement.SIM);
} catch (Exception e1) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when getting SE: " + e1.getClass().getName() + ":" + e1.getMessage());
}
if (se == null) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:SecureElement(SIM) is null - exiting");
return;
}
myListener = getTransactionListener();
try {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:adding transaction listener");
try {
se.addTransactionListener(myListener, MY_AID);
} catch (NFCException e) {
if (e.getMessage().startsWith("TransactionListener has already been added") || e.getMessage().startsWith("AID has already been registered")) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:already registered - ignoring");
}
}
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:added transaction listener OK");
} catch (Exception e) {
if (!e.getMessage().startsWith("TransactionListener has already been added") && !e.getMessage().startsWith("AID has already been registered")) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when adding transaction listener: " + e.getClass().getName() + ":" + e.getMessage());
return;
} else {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when adding transaction listener: " + e.getClass().getName() + ":" + e.getMessage());
return;
}
}
try {
se.setTechnologyTypes(SecureElement.BATTERY_ON_MODE, TechnologyType.ISO14443B);
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:NFC routing established OK");
} catch (NFCException e) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " addTransactionListener:exception when setting technology types: " + e.getClass().getName() + ":" + e.getMessage());
}
try {
runtimeStore.replace(TRANSACTION_LISTENER, myListener);
} catch (IllegalArgumentException e) {
Utilities.log("XXXX " + Thread.currentThread().getName() + " RuntimeStore.replace exception: " + e.getClass().getName() + ":" + e.getMessage());
}
}
Aggregations