diff options
author | Robert Tsai <robtsai@google.com> | 2011-07-09 23:57:22 -0700 |
---|---|---|
committer | Robert Tsai <robtsai@google.com> | 2011-07-09 23:57:22 -0700 |
commit | 15bc894aae9192e26c35e0af22b5dbd2a5c30028 (patch) | |
tree | 85b0d5aada686b8ad569db6b14a65cd2964cb8dc /nfc-extras | |
parent | 4d825e1f3bb6b52ecbea6f0c4aa2081b7f1edc89 (diff) | |
download | frameworks_base-15bc894aae9192e26c35e0af22b5dbd2a5c30028.zip frameworks_base-15bc894aae9192e26c35e0af22b5dbd2a5c30028.tar.gz frameworks_base-15bc894aae9192e26c35e0af22b5dbd2a5c30028.tar.bz2 |
Preserve invariant that sService is not null (although NfcAdapter.get() can return null)
Change-Id: I85fcbc5e79549835dac255ce614bd5d65d39fc25
Diffstat (limited to 'nfc-extras')
-rw-r--r-- | nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java index e0c38b1..99cbb86 100644 --- a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java +++ b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java @@ -67,7 +67,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; + } } /** @@ -84,18 +88,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; } } } |