From 0bddf0dcfb066648f347afaf4e47401c855ff987 Mon Sep 17 00:00:00 2001 From: mike wakerly Date: Mon, 21 Mar 2011 16:51:06 -0700 Subject: NfcAdapterExtras: reset singleton state if initialization fails. Change-Id: I9c319925008070cc5ea93d5dd3941c9396072a8c --- .../com/android/nfc_extras/NfcAdapterExtras.java | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'nfc-extras') diff --git a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java index cf38bd1..ed1af49 100644 --- a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java +++ b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java @@ -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; - 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(); + 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; } -- cgit v1.1