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

Commit f4fcd421 authored by Robert Tsai's avatar Robert Tsai Committed by The Android Automerger
Browse files

Preserve invariant that sService is not null (although NfcAdapter.get() can return null)

Change-Id: I85fcbc5e79549835dac255ce614bd5d65d39fc25
parent 32e8ebda
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -68,7 +68,11 @@ public final class NfcAdapterExtras {

    /** get service handles */
    private static void initService() {
        sService = sAdapter.getNfcAdapterExtrasInterface();
        final INfcAdapterExtras service = sAdapter.getNfcAdapterExtrasInterface();
        if (service != null) {
            // Leave stale rather than receive a null value.
            sService = service;
        }
    }

    /**
@@ -85,18 +89,19 @@ public final class NfcAdapterExtras {
            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 (sSingleton == null) {
                        sService = null;
                        sEmbeddedEe = null;
                        sRouteOff = null;
                    if (sService == null) {
                        sRouteOnWhenScreenOn = null;
                        sRouteOff = null;
                        sEmbeddedEe = null;
                        sSingleton = null;
                        sAdapter = null;
                    }
                }
            }