From f439271150e4548f116919e0254d57655421581c Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Thu, 31 May 2012 18:00:59 -0700 Subject: Add watchdog to applyRouting(). We've seen some devices hang in doSelectSecureElement, probably waiting for a response from the HW. Root cause is unknown, may be due to a different access pattern of Wallet or OTAProxy. Until we can reproduce better and find the root cause, watchdog this method. Added advantage is that we can have the relevant context in the logs when the crash occurs. Bug: 6585958 Change-Id: Ic797ea479869a68173fcd42049cc4ba8d009d2e0 --- src/com/android/nfc/NfcService.java | 99 ++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 7b3c456..602b25d 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -1407,62 +1407,69 @@ public class NfcService extends Application implements DeviceHostListener { // PN544 cannot be reconfigured while EE is open return; } + WatchDogThread watchDog = new WatchDogThread(); - if (PN544_QUIRK_DISCONNECT_BEFORE_RECONFIGURE && mScreenState == SCREEN_STATE_OFF) { - /* TODO undo this after the LLCP stack is fixed. - * Use a different sequence when turning the screen off to - * workaround race conditions in pn544 libnfc. The race occurs - * when we change routing while there is a P2P target connect. - * The async LLCP callback will crash since the routing code - * is overwriting globals it relies on. - */ - if (POLLING_MODE > SCREEN_STATE_OFF) { - if (force || mNfcPollingEnabled) { - Log.d(TAG, "NFC-C OFF, disconnect"); - mNfcPollingEnabled = false; - mDeviceHost.disableDiscovery(); - maybeDisconnectTarget(); + try { + watchDog.start(); + + if (PN544_QUIRK_DISCONNECT_BEFORE_RECONFIGURE && mScreenState == SCREEN_STATE_OFF) { + /* TODO undo this after the LLCP stack is fixed. + * Use a different sequence when turning the screen off to + * workaround race conditions in pn544 libnfc. The race occurs + * when we change routing while there is a P2P target connect. + * The async LLCP callback will crash since the routing code + * is overwriting globals it relies on. + */ + if (POLLING_MODE > SCREEN_STATE_OFF) { + if (force || mNfcPollingEnabled) { + Log.d(TAG, "NFC-C OFF, disconnect"); + mNfcPollingEnabled = false; + mDeviceHost.disableDiscovery(); + maybeDisconnectTarget(); + } } + if (mEeRoutingState == ROUTE_ON_WHEN_SCREEN_ON) { + if (force || mNfceeRouteEnabled) { + Log.d(TAG, "NFC-EE OFF"); + mNfceeRouteEnabled = false; + mDeviceHost.doDeselectSecureElement(); + } + } + return; } - if (mEeRoutingState == ROUTE_ON_WHEN_SCREEN_ON) { - if (force || mNfceeRouteEnabled) { + + // configure NFC-EE routing + if (mScreenState >= SCREEN_STATE_ON_LOCKED && + mEeRoutingState == ROUTE_ON_WHEN_SCREEN_ON) { + if (force || !mNfceeRouteEnabled) { + Log.d(TAG, "NFC-EE ON"); + mNfceeRouteEnabled = true; + mDeviceHost.doSelectSecureElement(); + } + } else { + if (force || mNfceeRouteEnabled) { Log.d(TAG, "NFC-EE OFF"); mNfceeRouteEnabled = false; mDeviceHost.doDeselectSecureElement(); } } - return; - } - - // configure NFC-EE routing - if (mScreenState >= SCREEN_STATE_ON_LOCKED && - mEeRoutingState == ROUTE_ON_WHEN_SCREEN_ON) { - if (force || !mNfceeRouteEnabled) { - Log.d(TAG, "NFC-EE ON"); - mNfceeRouteEnabled = true; - mDeviceHost.doSelectSecureElement(); - } - } else { - if (force || mNfceeRouteEnabled) { - Log.d(TAG, "NFC-EE OFF"); - mNfceeRouteEnabled = false; - mDeviceHost.doDeselectSecureElement(); - } - } - // configure NFC-C polling - if (mScreenState >= POLLING_MODE) { - if (force || !mNfcPollingEnabled) { - Log.d(TAG, "NFC-C ON"); - mNfcPollingEnabled = true; - mDeviceHost.enableDiscovery(); - } - } else { - if (force || mNfcPollingEnabled) { - Log.d(TAG, "NFC-C OFF"); - mNfcPollingEnabled = false; - mDeviceHost.disableDiscovery(); + // configure NFC-C polling + if (mScreenState >= POLLING_MODE) { + if (force || !mNfcPollingEnabled) { + Log.d(TAG, "NFC-C ON"); + mNfcPollingEnabled = true; + mDeviceHost.enableDiscovery(); + } + } else { + if (force || mNfcPollingEnabled) { + Log.d(TAG, "NFC-C OFF"); + mNfcPollingEnabled = false; + mDeviceHost.disableDiscovery(); + } } + } finally { + watchDog.cancel(); } } } -- cgit v1.1