diff options
author | Nick Pelly <npelly@google.com> | 2011-06-12 21:36:46 -0700 |
---|---|---|
committer | Nick Pelly <npelly@google.com> | 2011-06-12 22:04:07 -0700 |
commit | 2edb3ee5e28ab719a3bb17b8d76b2b588405be9a (patch) | |
tree | c05e22c9913cac1211507daed4e555209f012a2c /src | |
parent | dfac80d25dd2816ad5af74cc4131b74134cc81b7 (diff) | |
download | packages_apps_nfc-2edb3ee5e28ab719a3bb17b8d76b2b588405be9a.zip packages_apps_nfc-2edb3ee5e28ab719a3bb17b8d76b2b588405be9a.tar.gz packages_apps_nfc-2edb3ee5e28ab719a3bb17b8d76b2b588405be9a.tar.bz2 |
Fix NFC service wake-lock, again.
1) Put a watchdog on the NFC Service disable path.
All the bug-reports show we were stuck in _disable(), watch-dog
this path (10 seconds).
2) Only attempt a SE reset once, even if it fails the first time.
All the bugs reports should the _disable() was due to SE reset
on first boot.
3) Grab the NFC service lock before the wake-lock.
So even if someone has NFC service lock, at least we don't
hold a wake-lock waiting for it.
Bug: 4581084
Change-Id: Ic9829dddde8d0c67cf0e8e4912357fa2902faa11
Diffstat (limited to 'src')
-rwxr-xr-x | src/com/android/nfc/NativeNfcManager.java | 1 | ||||
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 35 |
2 files changed, 33 insertions, 3 deletions
diff --git a/src/com/android/nfc/NativeNfcManager.java b/src/com/android/nfc/NativeNfcManager.java index 7e4db32..3f0f532 100755 --- a/src/com/android/nfc/NativeNfcManager.java +++ b/src/com/android/nfc/NativeNfcManager.java @@ -92,6 +92,7 @@ public class NativeNfcManager { public native boolean doActivateLlcp(); + public native void doAbort(); public native void doResetIsoDepTimeout(); public void resetIsoDepTimeout() { diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 244a3bf..667565b 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -1943,6 +1943,10 @@ public class NfcService extends Application { } private boolean _disable(boolean oldEnabledState) { + /* sometimes mManager.deinitialize() hangs, watch-dog it */ + WatchDogThread watchDog = new WatchDogThread(); + watchDog.start(); + boolean isSuccess; /* tear down the my tag server */ @@ -1970,9 +1974,34 @@ public class NfcService extends Application { updateNfcOnSetting(oldEnabledState); + watchDog.cancel(); return isSuccess; } + private class WatchDogThread extends Thread { + boolean mWatchDogCanceled = false; + @Override + public void run() { + boolean slept = false; + while (!slept) { + try { + Thread.sleep(10000); + slept = true; + } catch (InterruptedException e) { } + } + synchronized (this) { + if (!mWatchDogCanceled) { + // Trigger watch-dog + Log.e(TAG, "Watch dog triggered"); + mManager.doAbort(); + } + } + } + public synchronized void cancel() { + mWatchDogCanceled = true; + } + } + /** apply NFC discovery and EE routing */ private synchronized void applyRouting() { if (mIsNfcEnabled && mOpenEe == null) { @@ -2042,9 +2071,9 @@ public class NfcService extends Application { private void resetSeOnFirstBoot() { if (mPrefs.getBoolean(PREF_FIRST_BOOT, true)) { Log.i(TAG, "First Boot"); - executeSeReset(); mPrefsEditor.putBoolean(PREF_FIRST_BOOT, false); mPrefsEditor.apply(); + executeSeReset(); } } @@ -2891,13 +2920,13 @@ public class NfcService extends Application { applyRouting(); } } else { - mWakeLock.acquire(); synchronized (NfcService.this) { + mWakeLock.acquire(); mScreenOn = false; applyRouting(); maybeDisconnectTarget(); + mWakeLock.release(); } - mWakeLock.release(); } return null; } |