keep history after reset to GRK39D
diff --git a/core/java/android/nfc/INfcAdapterExtras.aidl b/core/java/android/nfc/INfcAdapterExtras.aidl
index 0c2a2fd..8677a50 100755
--- a/core/java/android/nfc/INfcAdapterExtras.aidl
+++ b/core/java/android/nfc/INfcAdapterExtras.aidl
@@ -16,6 +16,7 @@
 
 package android.nfc;
 
+import android.nfc.ApduList;
 import android.os.Bundle;
 
 
@@ -28,5 +29,6 @@
     Bundle transceive(in byte[] data_in);
     int getCardEmulationRoute();
     void setCardEmulationRoute(int route);
-    void authenticate(in byte[] token);
+    void registerTearDownApdus(String packageName, in ApduList apdu);
+    void unregisterTearDownApdus(String packageName);
 }
diff --git a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
index 99cbb86..6001be9 100644
--- a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
+++ b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
@@ -18,6 +18,7 @@
 
 import android.annotation.SdkConstant;
 import android.annotation.SdkConstant.SdkConstantType;
+import android.nfc.ApduList;
 import android.nfc.INfcAdapterExtras;
 import android.nfc.NfcAdapter;
 import android.os.RemoteException;
@@ -67,11 +68,7 @@
 
     /** get service handles */
     private static void initService() {
-        final INfcAdapterExtras service = sAdapter.getNfcAdapterExtrasInterface();
-        if (service != null) {
-            // Leave stale rather than receive a null value.
-            sService = service;
-        }
+        sService = sAdapter.getNfcAdapterExtrasInterface();
     }
 
     /**
@@ -88,19 +85,18 @@
             if (sSingleton == null) {
                 try {
                     sAdapter = adapter;
+                    sRouteOff = new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null);
                     sSingleton = new NfcAdapterExtras();
                     sEmbeddedEe = new NfcExecutionEnvironment(sSingleton);
-                    sRouteOff = new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null);
                     sRouteOnWhenScreenOn = new CardEmulationRoute(
                             CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, sEmbeddedEe);
                     initService();
                 } finally {
-                    if (sService == null) {
-                        sRouteOnWhenScreenOn = null;
-                        sRouteOff = null;
+                    if (sSingleton == null) {
+                        sService = null;
                         sEmbeddedEe = null;
-                        sSingleton = null;
-                        sAdapter = null;
+                        sRouteOff = null;
+                        sRouteOnWhenScreenOn = null;
                     }
                 }
             }
@@ -212,18 +208,17 @@
         return sEmbeddedEe;
     }
 
-    /**
-     * Authenticate the client application.
-     *
-     * Some implementations of NFC Adapter Extras may require applications
-     * to authenticate with a token, before using other methods.
-     *
-     * @param a implementation specific token
-     * @throws a {@link java.lang.SecurityException} if authentication failed
-     */
-    public void authenticate(byte[] token) {
+    public void registerTearDownApdus(String packageName, ApduList apdus) {
         try {
-            sService.authenticate(token);
+            sService.registerTearDownApdus(packageName, apdus);
+        } catch (RemoteException e) {
+            attemptDeadServiceRecovery(e);
+        }
+    }
+
+    public void unregisterTearDownApdus(String packageName) {
+        try {
+            sService.unregisterTearDownApdus(packageName);
         } catch (RemoteException e) {
             attemptDeadServiceRecovery(e);
         }
diff --git a/nfc-extras/java/com/android/nfc_extras/NfcExecutionEnvironment.java b/nfc-extras/java/com/android/nfc_extras/NfcExecutionEnvironment.java
index 63c2de2..eb2f6f8 100644
--- a/nfc-extras/java/com/android/nfc_extras/NfcExecutionEnvironment.java
+++ b/nfc-extras/java/com/android/nfc_extras/NfcExecutionEnvironment.java
@@ -55,64 +55,6 @@
      */
     public static final String EXTRA_AID = "com.android.nfc_extras.extra.AID";
 
-    /**
-     * Broadcast action: A filtered APDU was received.
-     *
-     * <p>This happens when an APDU of interest was matched by the Nfc adapter,
-     * for instance as the result of matching an externally-configured filter.
-     *
-     * <p>The filter configuration mechanism is not currently defined.
-     *
-     * <p>Always contains the extra field {@link EXTRA_APDU_BYTES}.
-     *
-     * @hide
-     */
-    public static final String ACTION_APDU_RECEIVED =
-        "com.android.nfc_extras.action.APDU_RECEIVED";
-
-    /**
-     * Mandatory byte array extra field in {@link #ACTION_APDU_RECEIVED}.
-     *
-     * <p>Contains the bytes of the received APDU.
-     *
-     * @hide
-     */
-    public static final String EXTRA_APDU_BYTES =
-        "com.android.nfc_extras.extra.APDU_BYTES";
-
-    /**
-     * Broadcast action: An EMV card removal event was detected.
-     *
-     * @hide
-     */
-    public static final String ACTION_EMV_CARD_REMOVAL =
-        "com.android.nfc_extras.action.EMV_CARD_REMOVAL";
-
-    /**
-     * Broadcast action: An adapter implementing MIFARE Classic via card
-     * emulation detected that a block has been accessed.
-     *
-     * <p>This may only be issued for the first block that the reader
-     * authenticates to.
-     *
-     * <p>May contain the extra field {@link #EXTRA_MIFARE_BLOCK}.
-     *
-     * @hide
-     */
-    public static final String ACTION_MIFARE_ACCESS_DETECTED =
-        "com.android.nfc_extras.action.MIFARE_ACCESS_DETECTED";
-
-    /**
-     * Optional integer extra field in {@link #ACTION_MIFARE_ACCESS_DETECTED}.
-     *
-     * <p>Provides the block number being accessed.  If not set, the block
-     * number being accessed is unknown.
-     *
-     * @hide
-     */
-    public static final String EXTRA_MIFARE_BLOCK =
-        "com.android.nfc_extras.extra.MIFARE_BLOCK";
-
     NfcExecutionEnvironment(NfcAdapterExtras extras) {
         mExtras = extras;
     }