diff options
author | mike wakerly <mikey@google.com> | 2011-03-21 16:51:06 -0700 |
---|---|---|
committer | mike wakerly <mikey@google.com> | 2011-03-21 16:51:06 -0700 |
commit | 0bddf0dcfb066648f347afaf4e47401c855ff987 (patch) | |
tree | 5361350cdf0e1ede64de6d549ad3b1b4c6cfcfe7 /nfc-extras | |
parent | 661e9b371fcc1a2aec5dfd74f2cc65db1d8a77d5 (diff) | |
download | frameworks_base-0bddf0dcfb066648f347afaf4e47401c855ff987.zip frameworks_base-0bddf0dcfb066648f347afaf4e47401c855ff987.tar.gz frameworks_base-0bddf0dcfb066648f347afaf4e47401c855ff987.tar.bz2 |
NfcAdapterExtras: reset singleton state if initialization fails.
Change-Id: I9c319925008070cc5ea93d5dd3941c9396072a8c
Diffstat (limited to 'nfc-extras')
-rw-r--r-- | nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java | 25 |
1 files changed, 16 insertions, 9 deletions
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; } |