diff options
author | mike wakerly <mikey@google.com> | 2012-08-02 15:45:47 -0700 |
---|---|---|
committer | Martijn Coenen <maco@google.com> | 2012-08-09 17:36:30 -0700 |
commit | c6cdbf21958178025010c6bed797ff193c89884f (patch) | |
tree | 09a1568c265c7ce5b77dd0083f9697d75387be1c /src/com | |
parent | 341fbf46e459073c929cb20fcb231ad981b0c67d (diff) | |
download | packages_apps_nfc-c6cdbf21958178025010c6bed797ff193c89884f.zip packages_apps_nfc-c6cdbf21958178025010c6bed797ff193c89884f.tar.gz packages_apps_nfc-c6cdbf21958178025010c6bed797ff193c89884f.tar.bz2 |
NfcService: hold a wake lock around transceive().
Bug: 6629750
Change-Id: Idee36983952b4ba593464f72188c6fb702c59f7f
Diffstat (limited to 'src/com')
-rwxr-xr-x | src/com/android/nfc/NfcService.java | 94 |
1 files changed, 72 insertions, 22 deletions
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java index 13f224b..5f9fc21 100755 --- a/src/com/android/nfc/NfcService.java +++ b/src/com/android/nfc/NfcService.java @@ -186,7 +186,10 @@ public class NfcService extends Application implements DeviceHostListener { private DeviceHost mDeviceHost; private SharedPreferences mPrefs; private SharedPreferences.Editor mPrefsEditor; - private PowerManager.WakeLock mWakeLock; + private PowerManager.WakeLock mRoutingWakeLock; + private PowerManager.WakeLock mOpenWakeLock; + private PowerManager.WakeLock mDisconnectWakeLock; + private PowerManager.WakeLock mTransceiveWakeLock; int mStartSound; int mEndSound; int mErrorSound; @@ -320,7 +323,17 @@ public class NfcService extends Application implements DeviceHostListener { mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); - mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NfcService"); + // TODO(mikey|maco): consolidate as a single wakelock when individual + // stats are no longer useful. + mRoutingWakeLock = mPowerManager.newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, "NfcService:mRoutingWakeLock"); + mOpenWakeLock = mPowerManager.newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, "NfcService:mOpenWakeLock"); + mDisconnectWakeLock = mPowerManager.newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, "NfcService:mDisconnectWakeLock"); + mTransceiveWakeLock = mPowerManager.newWakeLock( + PowerManager.PARTIAL_WAKE_LOCK, "NfcService:mTransceiveWakeLock"); + mKeyguard = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); mScreenState = checkScreenState(); @@ -403,6 +416,37 @@ public class NfcService extends Application implements DeviceHostListener { } } + int doOpenSecureElementConnection() { + mOpenWakeLock.acquire(); + try { + return mSecureElement.doOpenSecureElementConnection(); + } finally { + mOpenWakeLock.release(); + } + } + + byte[] doTransceive(int handle, byte[] cmd) { + mTransceiveWakeLock.acquire(); + try { + return doTransceiveNoLock(handle, cmd); + } finally { + mTransceiveWakeLock.release(); + } + } + + byte[] doTransceiveNoLock(int handle, byte[] cmd) { + return mSecureElement.doTransceive(handle, cmd); + } + + void doDisconnect(int handle) { + mDisconnectWakeLock.acquire(); + try { + mSecureElement.doDisconnect(handle); + } finally { + mDisconnectWakeLock.release(); + } + } + /** * Manages tasks that involve turning on/off the NFC controller. * @@ -587,7 +631,7 @@ public class NfcService extends Application implements DeviceHostListener { } } Log.i(TAG, "Executing SE wipe"); - int handle = mSecureElement.doOpenSecureElementConnection(); + int handle = doOpenSecureElementConnection(); if (handle == 0) { Log.w(TAG, "Could not open the secure element"); if (tempEnable) { @@ -596,19 +640,27 @@ public class NfcService extends Application implements DeviceHostListener { return; } - mDeviceHost.setTimeout(TagTechnology.ISO_DEP, 10000); + try { + mTransceiveWakeLock.acquire(); + try { + mDeviceHost.setTimeout(TagTechnology.ISO_DEP, 10000); - for (byte[] cmd : apdus) { - byte[] resp = mSecureElement.doTransceive(handle, cmd); - if (resp == null) { - Log.w(TAG, "Transceive failed, could not wipe NFC-EE"); - break; + for (byte[] cmd : apdus) { + byte[] resp = doTransceiveNoLock(handle, cmd); + if (resp == null) { + Log.w(TAG, "Transceive failed, could not wipe NFC-EE"); + break; + } + } + + mDeviceHost.resetTimeouts(); + } finally { + mTransceiveWakeLock.release(); } + } finally { + doDisconnect(handle); } - mDeviceHost.resetTimeouts(); - mSecureElement.doDisconnect(handle); - if (tempEnable) { disableInternal(); } @@ -1189,7 +1241,7 @@ public class NfcService extends Application implements DeviceHostListener { binder.unlinkToDeath(mOpenEe, 0); mDeviceHost.resetTimeouts(); - mSecureElement.doDisconnect(mOpenEe.handle); + doDisconnect(mOpenEe.handle); mOpenEe = null; applyRouting(true); @@ -1232,7 +1284,7 @@ public class NfcService extends Application implements DeviceHostListener { throw new IOException("NFC EE already open"); } - int handle = mSecureElement.doOpenSecureElementConnection(); + int handle = doOpenSecureElementConnection(); if (handle == 0) { throw new IOException("NFC EE failed to open"); } @@ -1296,7 +1348,7 @@ public class NfcService extends Application implements DeviceHostListener { } } - return mSecureElement.doTransceive(mOpenEe.handle, data); + return doTransceive(mOpenEe.handle, data); } @Override @@ -1796,13 +1848,11 @@ public class NfcService extends Application implements DeviceHostListener { } mScreenState = params[0].intValue(); - boolean needWakelock = mScreenState == SCREEN_STATE_OFF; - if (needWakelock) { - mWakeLock.acquire(); - } - applyRouting(false); - if (needWakelock) { - mWakeLock.release(); + mRoutingWakeLock.acquire(); + try { + applyRouting(false); + } finally { + mRoutingWakeLock.release(); } return null; } |