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

Commit 0bddf0dc authored by mike wakerly's avatar mike wakerly
Browse files

NfcAdapterExtras: reset singleton state if initialization fails.

Change-Id: I9c319925008070cc5ea93d5dd3941c9396072a8c
parent 661e9b37
Loading
Loading
Loading
Loading
+16 −9
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ public final class NfcAdapterExtras {

    // protected by NfcAdapterExtras.class, and final after first construction
    private static INfcAdapterExtras sService;
    private static boolean sIsInitialized = false;
    private static NfcAdapterExtras sSingleton;
    private static NfcExecutionEnvironment sEmbeddedEe;
    private static CardEmulationRoute sRouteOff;
@@ -74,14 +73,22 @@ public final class NfcAdapterExtras {
     */
    public static NfcAdapterExtras get(NfcAdapter adapter) {
        synchronized(NfcAdapterExtras.class) {
            if (!sIsInitialized) {
               sIsInitialized = true;
            if (sSingleton == null) {
                try {
                    sService = adapter.getNfcAdapterExtrasInterface();
                    sEmbeddedEe = new NfcExecutionEnvironment(sService);
                    sRouteOff = new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null);
                    sRouteOnWhenScreenOn = new CardEmulationRoute(
                            CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, sEmbeddedEe);
                    sSingleton = new NfcAdapterExtras();
                } finally {
                    if (sSingleton == null) {
                        sService = null;
                        sEmbeddedEe = null;
                        sRouteOff = null;
                        sRouteOnWhenScreenOn = null;
                    }
                }
            }
            return sSingleton;
        }