Release wakelock in LocationManagerService if client thread is dead
- also put a timeout on the wakelock so that it won't be held forever.
Bug: 111321558
Fixes: 111321558
Test: Tested on device.
Change-Id: I36e90f73143ff12d8622dbbb3aad643b283d17ce
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index 776cf47..232c151 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -795,6 +795,7 @@
* location updates.
*/
private final class Receiver implements IBinder.DeathRecipient, PendingIntent.OnFinished {
+ private static final long WAKELOCK_TIMEOUT_MILLIS = 60 * 1000;
final Identity mIdentity;
final int mAllowedResolutionLevel; // resolution level allowed to receiver
@@ -838,6 +839,10 @@
workSource = new WorkSource(mIdentity.mUid, mIdentity.mPackageName);
}
mWakeLock.setWorkSource(workSource);
+
+ // For a non-reference counted wakelock, each acquire will reset the timeout, and we
+ // only need to release it once.
+ mWakeLock.setReferenceCounted(false);
}
@Override
@@ -1099,9 +1104,8 @@
// this must be called while synchronized by caller in a synchronized block
// containing the sending of the broadcaset
private void incrementPendingBroadcastsLocked() {
- if (mPendingBroadcasts++ == 0) {
- mWakeLock.acquire();
- }
+ mPendingBroadcasts++;
+ mWakeLock.acquire(WAKELOCK_TIMEOUT_MILLIS);
}
private void decrementPendingBroadcastsLocked() {