Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9a5e57af authored by android-merger's avatar android-merger
Browse files

temporary revert for testing

Revert "Implement dead service recovery in NFC extras library."

This reverts commit cc9ee72b.
parent 95a08eaf
Loading
Loading
Loading
Loading
+8 −30
Original line number Diff line number Diff line
@@ -56,21 +56,13 @@ public final class NfcAdapterExtras {
    public static final String ACTION_RF_FIELD_OFF_DETECTED =
            "com.android.nfc_extras.action.RF_FIELD_OFF_DETECTED";

    // protected by NfcAdapterExtras.class, and final after first construction,
    // except for attemptDeadServiceRecovery() when NFC crashes - we accept a
    // best effort recovery
    private static NfcAdapter sAdapter;
    // protected by NfcAdapterExtras.class, and final after first construction
    private static INfcAdapterExtras sService;
    private static NfcAdapterExtras sSingleton;
    private static NfcExecutionEnvironment sEmbeddedEe;
    private static CardEmulationRoute sRouteOff;
    private static CardEmulationRoute sRouteOnWhenScreenOn;

    /** get service handles */
    private static void initService() {
        sService = sAdapter.getNfcAdapterExtrasInterface();
    }

    /**
     * Get the {@link NfcAdapterExtras} for the given {@link NfcAdapter}.
     *
@@ -84,13 +76,12 @@ public final class NfcAdapterExtras {
        synchronized(NfcAdapterExtras.class) {
            if (sSingleton == null) {
                try {
                    sAdapter = adapter;
                    sService = adapter.getNfcAdapterExtrasInterface();
                    sEmbeddedEe = new NfcExecutionEnvironment(sService);
                    sRouteOff = new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null);
                    sSingleton = new NfcAdapterExtras();
                    sEmbeddedEe = new NfcExecutionEnvironment(sSingleton);
                    sRouteOnWhenScreenOn = new CardEmulationRoute(
                            CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, sEmbeddedEe);
                    initService();
                    sSingleton = new NfcAdapterExtras();
                } finally {
                    if (sSingleton == null) {
                        sService = null;
@@ -144,19 +135,6 @@ public final class NfcAdapterExtras {
        }
    }

    /**
     * NFC service dead - attempt best effort recovery
     */
    void attemptDeadServiceRecovery(Exception e) {
        Log.e(TAG, "NFC Adapter Extras dead - attempting to recover");
        sAdapter.attemptDeadServiceRecovery(e);
        initService();
    }

    INfcAdapterExtras getService() {
        return sService;
    }

    /**
     * Get the routing state of this NFC EE.
     *
@@ -172,7 +150,7 @@ public final class NfcAdapterExtras {
                    sRouteOff :
                    sRouteOnWhenScreenOn;
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            Log.e(TAG, "", e);
            return sRouteOff;
        }
    }
@@ -191,7 +169,7 @@ public final class NfcAdapterExtras {
        try {
            sService.setCardEmulationRoute(route.route);
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            Log.e(TAG, "", e);
        }
    }

@@ -212,7 +190,7 @@ public final class NfcAdapterExtras {
        try {
            sService.registerTearDownApdus(packageName, apdus);
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            Log.e(TAG, "", e);
        }
    }

@@ -220,7 +198,7 @@ public final class NfcAdapterExtras {
        try {
            sService.unregisterTearDownApdus(packageName);
        } catch (RemoteException e) {
            attemptDeadServiceRecovery(e);
            Log.e(TAG, "", e);
        }
    }
}
+9 −12
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import android.os.IBinder;
import android.os.RemoteException;

public class NfcExecutionEnvironment {
    private final NfcAdapterExtras mExtras;
    private final INfcAdapterExtras mService;

    /**
     * Broadcast Action: An ISO-DEP AID was selected.
@@ -55,8 +55,8 @@ public class NfcExecutionEnvironment {
     */
    public static final String EXTRA_AID = "com.android.nfc_extras.extra.AID";

    NfcExecutionEnvironment(NfcAdapterExtras extras) {
        mExtras = extras;
    NfcExecutionEnvironment(INfcAdapterExtras service) {
        mService = service;
    }

    /**
@@ -75,11 +75,10 @@ public class NfcExecutionEnvironment {
     */
    public void open() throws IOException {
        try {
            Bundle b = mExtras.getService().open(new Binder());
            Bundle b = mService.open(new Binder());
            throwBundle(b);
        } catch (RemoteException e) {
            mExtras.attemptDeadServiceRecovery(e);
            throw new IOException("NFC Service was dead, try again");
            return;
        }
    }

@@ -93,10 +92,9 @@ public class NfcExecutionEnvironment {
     */
    public void close() throws IOException {
        try {
            throwBundle(mExtras.getService().close());
            throwBundle(mService.close());
        } catch (RemoteException e) {
            mExtras.attemptDeadServiceRecovery(e);
            throw new IOException("NFC Service was dead");
            return;
        }
    }

@@ -111,10 +109,9 @@ public class NfcExecutionEnvironment {
    public byte[] transceive(byte[] in) throws IOException {
        Bundle b;
        try {
            b = mExtras.getService().transceive(in);
            b = mService.transceive(in);
        } catch (RemoteException e) {
            mExtras.attemptDeadServiceRecovery(e);
            throw new IOException("NFC Service was dead, need to re-open");
            throw new IOException(e.getMessage());
        }
        throwBundle(b);
        return b.getByteArray("out");