Skip to content
Snippets Groups Projects
Commit 0bddf0dc authored by mike wakerly's avatar mike wakerly
Browse files

NfcAdapterExtras: reset singleton state if initialization fails.

Change-Id: I9c319925008070cc5ea93d5dd3941c9396072a8c
parent 661e9b37
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment