Ejemplo n.º 1
0
  /** Returns the singleton, or throws if NFC is not available. */
  static synchronized NfcAdapter getSingleton() {
    if (!sIsInitialized) {
      sIsInitialized = true;

      /* is this device meant to have NFC */
      if (!hasNfcFeature()) {
        Log.v(TAG, "this device does not have NFC support");
        throw new UnsupportedOperationException();
      }

      sService = getServiceInterface();
      if (sService == null) {
        Log.e(TAG, "could not retrieve NFC service");
        throw new UnsupportedOperationException();
      }
      try {
        sTagService = sService.getNfcTagInterface();
      } catch (RemoteException e) {
        Log.e(TAG, "could not retrieve NFC Tag service");
        throw new UnsupportedOperationException();
      }
      sSingleton = new NfcAdapter();
    }
    if (sSingleton == null) {
      throw new UnsupportedOperationException();
    }
    return sSingleton;
  }
Ejemplo n.º 2
0
  /**
   * NFC service dead - attempt best effort recovery
   *
   * @hide
   */
  public void attemptDeadServiceRecovery(Exception e) {
    Log.e(TAG, "NFC service dead - attempting to recover", e);
    INfcAdapter service = getServiceInterface();
    if (service == null) {
      Log.e(TAG, "could not retrieve NFC service during service recovery");
      // nothing more can be done now, sService is still stale, we'll hit
      // this recovery path again later
      return;
    }
    // assigning to sService is not thread-safe, but this is best-effort code
    // and on a well-behaved system should never happen
    sService = service;
    try {
      sTagService = service.getNfcTagInterface();
    } catch (RemoteException ee) {
      Log.e(TAG, "could not retrieve NFC tag service during service recovery");
      // nothing more can be done now, sService is still stale, we'll hit
      // this recovery path again later
    }

    return;
  }