Package nfc.sample.nfctransaction.ui

Examples of nfc.sample.nfctransaction.ui.NfcTransScreen


        if(btn.getMsbState() == Constants.BTN_SELECT_OFF) {
            Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command exiting because button is in OFF state");
            return;
        }
        Settings settings = Settings.getInstance();
        NfcTransScreen screen = NfcTransScreen.getInstance();
        Utilities.log("XXXX " + Thread.currentThread().getName() + " selecting applet");
        APDUConnection apduConn = null;
        // this is an example and completely proprietary APDU included solely to demonstrate the basic use of JSR-177
        // Decode:
        // 0x80 : CLASS = proprietary
        // 0x01 : INS   = invented command! Interpretation will require the selected applet to understand this command
        // 0x00 : P1    = null
        // 0x00 : P1    = null
        byte[] command = settings.getAPDU();
        try {
            // Open an APDUConnection to our applet. This results in an ISO 7816-4 SELECT command being sent by the JSR-177 API
            String connection_string = Utilities.makeApduConnectionString(settings.getRegisteredAIDAsString());
            Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: opening APDUConnection to " + connection_string);
            apduConn = (APDUConnection) Connector.open(connection_string);
            Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: APDUConnection opened");
            screen.setUserMessage("Selected AID OK");
            // Send the APDU and wait for a response - expect an error here unless your applet supports the command that was sent
            Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: sending APDU");
            byte[] ret = apduConn.exchangeAPDU(command);
            String resp_string = ByteArrayUtilities.byteArrayToHex(ret);
            Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command: response=" + resp_string);
            screen.setUserMessage("APDU response=" + resp_string);
            // Close the logical channel connection
            apduConn.close();
        } catch(Exception e) {
            Utilities.log("XXXX " + Thread.currentThread().getName() + " ISO 7816-4 command failed:" + e.getClass().getName() + ":" + e.getMessage());
            screen.setUserMessage("Error. Select failed: check log");
        }
    }
View Full Code Here


                }
            }
        } else {
            Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " launched with no arguments");
            app.setRunning_in_background(false);
            NfcTransScreen screen = NfcTransScreen.getInstance();
            app.pushScreen(screen);
            screen.startRtsMonitorThread();
            screen.init();
            UiApplication.getApplication().requestForeground();
            Utilities.log("XXXX " + pid + ":" + Thread.currentThread().getName() + " entering event dispatcher");
            app.enterEventDispatcher();
        }
    }
View Full Code Here

  private NfcService nfc_service = NfcService.getInstance();
  private CardEmulation ce = CardEmulation.getInstance();

  public void execute(ReadOnlyCommandMetadata metadata, Object context) {
    NfcTransScreen screen = NfcTransScreen.getInstance();
    Utilities.log("XXXX " + Thread.currentThread().getName() + " toggling card emulation");
    boolean nfc_enabled = false;
    try {
      nfc_enabled = nfc_service.isNfcEnabled();
      screen.setNfcLed(Utilities.ledBooleanToInt(nfc_enabled));
    } catch (NFCException e) {
      Utilities.log("XXXX " + Thread.currentThread().getName() + " exception when establishing NFC service status: " + e.getClass().getName() + ":"
          + e.getMessage());
      screen.setUserMessage("Failed to establish NFC service status");
      screen.setNfcLed(Constants.LED_ERR);
      return;
    }

    if (!nfc_enabled) {
      Utilities.log("XXXX " + Thread.currentThread().getName() + " NFC seems to be OFF so prompting user to enable it");
      screen.setUserMessage("NFC is off");
      try {
        nfc_service.promptToEnableNFC();
        screen.setCeButtonState(ce.isCeEnabled(SecureElement.BATTERY_ON_MODE));
      } catch (NFCException e) {
        Utilities.log("XXXX " + Thread.currentThread().getName() + " exception when prompting to enable NFC: " + e.getClass().getName() + ":"
            + e.getMessage());
        screen.setUserMessage("Failed when prompting to enable NFC");
      }
      return;
    }

    boolean ce_enabled = false;
    try {
      ce_enabled = ce.isCeEnabled(SecureElement.BATTERY_ON_MODE);
    } catch (NFCException e1) {
      Utilities
          .log("XXXX " + Thread.currentThread().getName() + " exception when checking CE status: " + e1.getClass().getName() + ":" + e1.getMessage());
      screen.setUserMessage("Error: could not establish CE status");
      screen.setCemLed(Constants.LED_ERR);
      return;
    }
    if (!ce_enabled) {
      try {
        if (nfc_service.isNfcEnabled()) {
          Utilities.log("XXXX " + Thread.currentThread().getName() + " NFC is ON so setting technology types");
          // Route ISO14443x to the Secure Element
          // for battery on, device on mode
          ce_enabled = ce.setRoutingOn(ce.getCurrentTechnologyTypes());
          if (ce_enabled) {
            screen.setCeButtonState(true);
            screen.setSelectButtonState(true);
            screen.setUserMessage("Card emulation enabled OK");
            screen.setCemLed(Constants.LED_ON);
          } else {
            screen.setUserMessage("Card emulation not enabled");
          }
        } else {
          Utilities.log("XXXX " + Thread.currentThread().getName() + " NFC seems to be OFF so prompting user to enable it");
          screen.setUserMessage("NFC is off");
          nfc_service.promptToEnableNFC();
        }
      } catch (NFCException e) {
        Utilities.log("XXXX " + Thread.currentThread().getName() + " exception when setting SE routing: " + e.getClass().getName() + ":"
            + e.getMessage());
        screen.setUserMessage("Failed to set NFC routing");
        return;
      }
    } else {
      try {
        // Remove routing
        Utilities.log("XXXX " + Thread.currentThread().getName() + " NFC removing NFC SIM SE routing");
        ce_enabled = ce.setRoutingOff();
        if (!ce_enabled) {
          screen.setCeButtonState(false);
          screen.setSelectButtonState(false);
          screen.setUserMessage("Card emulation disabled OK");
          screen.setCemLed(Constants.LED_OFF);
        } else {
          screen.setUserMessage("Card emulation not disabled");
        }
      } catch (NFCException e) {
        Utilities.log("XXXX " + Thread.currentThread().getName() + " exception when setting SE routing: " + e.getClass().getName() + ":"
            + e.getMessage());
        screen.setUserMessage("Failed to set NFC routing");
        return;
      }
    }

  }
View Full Code Here

public class ClearCommand extends AlwaysExecutableCommand {

  public void execute(ReadOnlyCommandMetadata metadata, Object context) {
    synchronized(UiApplication.getUiApplication().getEventLock()) {
      NfcTransScreen screen = NfcTransScreen.getInstance();
      screen.clearLastAIDs();
      Utilities.log("XXXX " + Thread.currentThread().getName() + " AID field cleared");
    }

  }
View Full Code Here

TOP

Related Classes of nfc.sample.nfctransaction.ui.NfcTransScreen

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.