示例#1
0
  /**
   * Create a new instance of PassportLink. All CardTerminals will be listed. Upon a request all
   * terminals will be checked for the presence of a passport. The first terminal to respond will be
   * chosen for as long as the passport is present.
   */
  public PassportLink() {
    Security.insertProviderAt(PROVIDER, 4);

    _cardManager = CardManager.getInstance();
    _cardTerminals = _cardManager.getTerminals();
    _activeCardTerminal = null;
    _cardTerminal = null;
    _activeCardService = null;
    _activePassportService = null;

    Vector<CardTerminal> terminalsToRemove = new Vector<CardTerminal>();
    for (CardTerminal cardTerminalLoop : _cardTerminals) {
      if (cardTerminalLoop.getName().toUpperCase().contains("EMULATOR")) {
        Interfacer.getLogger().log("Removing emulator terminal.");
        terminalsToRemove.add(cardTerminalLoop);
      }
      Interfacer.getLogger().log("terminal name: " + cardTerminalLoop.getName());
    }

    for (CardTerminal removeTerminal : terminalsToRemove)
      _cardManager.getTerminals().remove(removeTerminal);
  }
示例#2
0
  private synchronized boolean activateTerminal() {
    Interfacer.getLogger().log("ACTIVATE TERMINAL");
    // select which terminal to use
    if (_cardTerminal != null) _activeCardTerminal = _cardTerminal;
    else {
      while (_activeCardTerminal == null) {
        try {
          for (CardTerminal cardTerminalLoop : _cardTerminals) {
            if (cardTerminalLoop.isCardPresent()
                && !cardTerminalLoop.getName().toUpperCase().contains("EMULATOR")) {
              _activeCardTerminal = cardTerminalLoop;
              break;
            }
          }
          if (_activeCardTerminal == null) {
            Interfacer.getLogger().log("INSERT CARD (s)");
            Thread.sleep(1000);
          }
        } catch (Exception e) {
        }
      }
    }
    Interfacer.getLogger().log("ACTIVE TERMINAL: " + _activeCardTerminal.getName());
    try {
      // wait for a card to be put in the terminal
      while (!_activeCardTerminal.isCardPresent()
          && !_activeCardTerminal.getName().toUpperCase().contains("EMULATOR")) {
        Interfacer.getLogger().log("INSERT CARD (s)");
        Thread.sleep(1000);
      }

      if (_activePassportService == null) {
        _activeCardService = new TerminalCardService(_activeCardTerminal);
        _activePassportService = new PassportService(_activeCardService);
        _activePassportService.open();
      }
      Interfacer.getLogger().log("CARD INSERTED AT: " + _activeCardTerminal.getName());
      return true;
    } catch (Exception e) {
      e.printStackTrace();
    }

    // something went wrong if we reached this point, clear the selected terminal
    Interfacer.getLogger().log("NO TERMINAL COULD BE ACTIVATED");
    return false;
  }