Skip to content

Commit 97d0bf2

Browse files
committed
Merge pull request blackberry#24 from mdwoolley/master
NfcTransactionHandler now delays JSR177 access until SIM is unlocked
2 parents 53f6f8f + 2ff7fb0 commit 97d0bf2

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

NFC/NfcTransactionHandler/src/nfc/sample/nfctransaction/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import net.rim.device.api.ui.Color;
1818

1919
public class Constants {
20-
public static String VERSION = "1.1.5";
20+
public static String VERSION = "1.2.0";
2121

2222
public static final int SE_SIM=0;
2323
public static final int SE_EMB=1;

NFC/NfcTransactionHandler/src/nfc/sample/nfctransaction/NfcTransHandlerApp.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.rim.device.api.system.ApplicationManager;
2828
import net.rim.device.api.system.ApplicationManagerException;
2929
import net.rim.device.api.system.Backlight;
30+
import net.rim.device.api.system.GPRSInfo;
3031
import net.rim.device.api.system.RuntimeStore;
3132
import net.rim.device.api.ui.UiApplication;
3233
import net.rim.device.api.util.ByteArrayUtilities;
@@ -67,6 +68,9 @@ public static void main(String[] args) {
6768

6869
Backlight.enable(true, 10);
6970

71+
// Essential that the SIM is unlocked (PIN) and initialised before we can proceed to use JSR177
72+
waitForSimInitialisation();
73+
7074
CardEmulation.registerTransactionListener(app);
7175

7276
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " TransactionListener is exiting and will be restarted when a transaction occurs");
@@ -91,6 +95,23 @@ public static void main(String[] args) {
9195
}
9296
}
9397

98+
private static void waitForSimInitialisation() {
99+
100+
int mcc = GPRSInfo.getHomeMCC();
101+
int mnc = GPRSInfo.getHomeMNC();
102+
Utilities.log("XXXX MCC="+mcc+",MNC="+mnc);
103+
while (mcc == -1) {
104+
try {
105+
Thread.sleep(3000);
106+
} catch(InterruptedException e) {
107+
}
108+
mcc = GPRSInfo.getHomeMCC();
109+
mnc = GPRSInfo.getHomeMNC();
110+
Utilities.log("XXXX MCC="+mcc+",MNC="+mnc);
111+
}
112+
Utilities.log("XXXX SIM initialised.... proceeding");
113+
}
114+
94115
private static void dumpArgs(String[] args) {
95116
for(int i = 0; i < args.length; i++) {
96117
Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " args[" + i + "]=" + args[i]);

NFC/NfcTransactionHandler/src/nfc/sample/nfctransaction/commands/Iso7816Command.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void execute(ReadOnlyCommandMetadata metadata, Object context) {
5959
// Open an APDUConnection to our applet. This results in an ISO 7816-4 SELECT command being sent by the JSR-177 API
6060
String connection_string = Utilities.makeApduConnectionString(settings.getRegistered_aid());
6161
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: opening APDUConnection to " + connection_string);
62-
apduConn = (APDUConnection) Connector.open(Constants.CONNECTION_STRING);
62+
apduConn = (APDUConnection) Connector.open(connection_string);
6363
Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: APDUConnection opened");
6464
screen.setUserMessage("Selected AID OK");
6565
// Send the APDU and wait for a response - expect an error here unless your applet supports the command that was sent

0 commit comments

Comments
 (0)