Hi,
I have a midlet suite with two midlets. One of those midlets opens (and afterwards closes) a connection to the secure element. The midlet suite is signed.
Access to the secure element works, but when the user exits the application and restarts it immediately from the midlet suite menu, Connector.open() blocks indefinately.
The user has to fully exit the midlet suite before connections to the SE work again.
Opening and closing the connection multiple times before exiting the application works perfect too.
I have a little demo program with two midlets in a midlet suite to illustrate this issue:
OpenCloseForm.java
TestConnectSecureElement.javaCode:import java.io.IOException; import javax.microedition.contactless.sc.ISO14443Connection; import javax.microedition.io.Connector; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.Item; import javax.microedition.lcdui.StringItem; public class OpenCloseSEForm extends Form implements CommandListener { private static final Command EXITCOMMAND = new Command("quit", Command.EXIT,5); private static final Command DOITCOMMAND = new Command("Open and Close SE", Command.OK, 0); public OpenCloseSEForm(String arg0) { super(arg0); this.addCommand(DOITCOMMAND); this.addCommand(EXITCOMMAND); this.setCommandListener(this); } public void commandAction(Command arg0, Displayable arg1) { if (arg0.equals(DOITCOMMAND)) { new Thread(){ public void run() { tryOpenCloseSE(); }}.start(); } else if (arg0.equals(EXITCOMMAND)) { TestConnectSecureElement.getMIDlet().notifyDestroyed(); } } private void log(String msg) { StringItem item = new StringItem("", msg); item.setLayout(Item.LAYOUT_2|Item.LAYOUT_NEWLINE_AFTER); this.append(item); System.out.println(msg); } private void tryOpenCloseSE() { log("open SE"); ISO14443Connection connection = null; try { connection = (ISO14443Connection) Connector.open(System.getProperty("internal.se.url")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); log("Exception opening SE"); } log("connection " + connection); if (connection != null) { try { connection.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); log("Exception closing SE"); } } log("connection closed"); } }
Dummy.javaCode:import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class TestConnectSecureElement extends MIDlet { private static MIDlet theMIDlet = null; public TestConnectSecureElement() { TestConnectSecureElement.theMIDlet = this; } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { System.out.println("Destroy"); } protected void pauseApp() { System.out.println("Pause"); } protected void startApp() throws MIDletStateChangeException { System.out.println("Start"); Display disp = Display.getDisplay(this); disp.setCurrent(new OpenCloseSEForm("Test Open and Close SE")); } public static MIDlet getMIDlet() { return theMIDlet; } }
If you create a midlet suite with these three source files, build and sign it, you can easily reproduce the issue:Code:import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class Dummy extends MIDlet { protected void destroyApp(boolean arg0) throws MIDletStateChangeException { System.out.println("Destroy"); } protected void pauseApp() { System.out.println("Pause"); } protected void startApp() throws MIDletStateChangeException { System.out.println("Start"); } }
Start the midlet suite, start TestConnectSecureElement. Use the Open and close SE button a few times. You see it works nicely. Use quit. Immediately restart the midlet from the midlet suite menu. Opening the SE now blocks.
Any suggestions, ideas workaround? Something I missed or a bug? I have this with the 3.12 firmware, I'd appreciate if someone could check if this is still the case with the 5.11 firmware.
If you pm me an email address, I can send you the jad/jar and the eclipse project.
thnx
regards
Tim

Reply With Quote

