Skip to content

Commit 15bc894

Browse files
author
Robert Tsai
committedJul 10, 2011
Preserve invariant that sService is not null (although NfcAdapter.get() can return null)
Change-Id: I85fcbc5e79549835dac255ce614bd5d65d39fc25
1 parent 4d825e1 commit 15bc894

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed
 

‎nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ public final class NfcAdapterExtras {
6767

6868
/** get service handles */
6969
private static void initService() {
70-
sService = sAdapter.getNfcAdapterExtrasInterface();
70+
final INfcAdapterExtras service = sAdapter.getNfcAdapterExtrasInterface();
71+
if (service != null) {
72+
// Leave stale rather than receive a null value.
73+
sService = service;
74+
}
7175
}
7276

7377
/**
@@ -84,18 +88,19 @@ public static NfcAdapterExtras get(NfcAdapter adapter) {
8488
if (sSingleton == null) {
8589
try {
8690
sAdapter = adapter;
87-
sRouteOff = new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null);
8891
sSingleton = new NfcAdapterExtras();
8992
sEmbeddedEe = new NfcExecutionEnvironment(sSingleton);
93+
sRouteOff = new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null);
9094
sRouteOnWhenScreenOn = new CardEmulationRoute(
9195
CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, sEmbeddedEe);
9296
initService();
9397
} finally {
94-
if (sSingleton == null) {
95-
sService = null;
96-
sEmbeddedEe = null;
97-
sRouteOff = null;
98+
if (sService == null) {
9899
sRouteOnWhenScreenOn = null;
100+
sRouteOff = null;
101+
sEmbeddedEe = null;
102+
sSingleton = null;
103+
sAdapter = null;
99104
}
100105
}
101106
}

0 commit comments

Comments
 (0)
Please sign in to comment.