}
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);