summaryrefslogtreecommitdiff
path: root/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2011-04-26 16:38:00 -0700
committerNick Pelly <npelly@google.com>2011-04-26 16:38:00 -0700
commitcc9ee72bd42bb40b1852f907f58305adde12ecc2 (patch)
tree4870cc32b9330093d21ba4a7167ee6dbc127e400 /nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
parentd2127c438fc858a4f6c8ad75b7a1e4491da69a78 (diff)
Implement dead service recovery in NFC extras library.
Change-Id: I4f1d714c625470df4cda2c4c9aacb8d27bfabb10
Diffstat (limited to 'nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java')
-rw-r--r--nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java38
1 files changed, 30 insertions, 8 deletions
diff --git a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
index 9bd8f36ad2ba..6001be92a322 100644
--- a/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
+++ b/nfc-extras/java/com/android/nfc_extras/NfcAdapterExtras.java
@@ -56,13 +56,21 @@ public final class NfcAdapterExtras {
public static final String ACTION_RF_FIELD_OFF_DETECTED =
"com.android.nfc_extras.action.RF_FIELD_OFF_DETECTED";
- // protected by NfcAdapterExtras.class, and final after first construction
+ // protected by NfcAdapterExtras.class, and final after first construction,
+ // except for attemptDeadServiceRecovery() when NFC crashes - we accept a
+ // best effort recovery
+ private static NfcAdapter sAdapter;
private static INfcAdapterExtras sService;
private static NfcAdapterExtras sSingleton;
private static NfcExecutionEnvironment sEmbeddedEe;
private static CardEmulationRoute sRouteOff;
private static CardEmulationRoute sRouteOnWhenScreenOn;
+ /** get service handles */
+ private static void initService() {
+ sService = sAdapter.getNfcAdapterExtrasInterface();
+ }
+
/**
* Get the {@link NfcAdapterExtras} for the given {@link NfcAdapter}.
*
@@ -76,12 +84,13 @@ public final class NfcAdapterExtras {
synchronized(NfcAdapterExtras.class) {
if (sSingleton == null) {
try {
- sService = adapter.getNfcAdapterExtrasInterface();
- sEmbeddedEe = new NfcExecutionEnvironment(sService);
+ sAdapter = adapter;
sRouteOff = new CardEmulationRoute(CardEmulationRoute.ROUTE_OFF, null);
+ sSingleton = new NfcAdapterExtras();
+ sEmbeddedEe = new NfcExecutionEnvironment(sSingleton);
sRouteOnWhenScreenOn = new CardEmulationRoute(
CardEmulationRoute.ROUTE_ON_WHEN_SCREEN_ON, sEmbeddedEe);
- sSingleton = new NfcAdapterExtras();
+ initService();
} finally {
if (sSingleton == null) {
sService = null;
@@ -136,6 +145,19 @@ public final class NfcAdapterExtras {
}
/**
+ * NFC service dead - attempt best effort recovery
+ */
+ void attemptDeadServiceRecovery(Exception e) {
+ Log.e(TAG, "NFC Adapter Extras dead - attempting to recover");
+ sAdapter.attemptDeadServiceRecovery(e);
+ initService();
+ }
+
+ INfcAdapterExtras getService() {
+ return sService;
+ }
+
+ /**
* Get the routing state of this NFC EE.
*
* <p class="note">
@@ -150,7 +172,7 @@ public final class NfcAdapterExtras {
sRouteOff :
sRouteOnWhenScreenOn;
} catch (RemoteException e) {
- Log.e(TAG, "", e);
+ attemptDeadServiceRecovery(e);
return sRouteOff;
}
}
@@ -169,7 +191,7 @@ public final class NfcAdapterExtras {
try {
sService.setCardEmulationRoute(route.route);
} catch (RemoteException e) {
- Log.e(TAG, "", e);
+ attemptDeadServiceRecovery(e);
}
}
@@ -190,7 +212,7 @@ public final class NfcAdapterExtras {
try {
sService.registerTearDownApdus(packageName, apdus);
} catch (RemoteException e) {
- Log.e(TAG, "", e);
+ attemptDeadServiceRecovery(e);
}
}
@@ -198,7 +220,7 @@ public final class NfcAdapterExtras {
try {
sService.unregisterTearDownApdus(packageName);
} catch (RemoteException e) {
- Log.e(TAG, "", e);
+ attemptDeadServiceRecovery(e);
}
}
}