summaryrefslogtreecommitdiff
path: root/services/java
diff options
context:
space:
mode:
author Jeff Brown <jeffbrown@google.com> 2012-08-25 13:07:01 -0700
committer Jeff Brown <jeffbrown@google.com> 2012-08-25 13:40:28 -0700
commit028872fe07f9b3468aa1506c658d6aae25f53015 (patch)
tree40069ed51bf79a0daabd60b3b78c93e7d2632cbd /services/java
parenta2910d0abbbe18ba1710dfd4a31af45769632255 (diff)
Fix GpsLocationProvider wake lock book keeping.
The GpsLocationProvider typically acquires a wake lock before sending a message to its handler then releases it after the message has been handled. There were two cases where messages might be removed from the handler, resulting in the wake lock being released. There were also two cases where background tasks were being started while not holding a wake lock for the duration. Fixed these issues and marked the GpsLocationProvider handler as asynchronous too so that it doesn't accidentally get blocked by traversals if it happens to share a thread with some UI. Bug: 7057752 Change-Id: I8e12fc91ae943e84db068c08ec809879537503c6
Diffstat (limited to 'services/java')
-rwxr-xr-xservices/java/com/android/server/location/GpsLocationProvider.java28
1 files changed, 20 insertions, 8 deletions
diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/java/com/android/server/location/GpsLocationProvider.java
index 32b3597fa4aa..c2c0a71f218d 100755
--- a/services/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/java/com/android/server/location/GpsLocationProvider.java
@@ -598,6 +598,8 @@ public class GpsLocationProvider implements LocationProviderInterface {
}
mInjectNtpTimePending = STATE_DOWNLOADING;
+ // hold wake lock while task runs
+ mWakeLock.acquire();
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
@@ -628,14 +630,16 @@ public class GpsLocationProvider implements LocationProviderInterface {
delay = RETRY_INTERVAL;
}
- mHandler.sendMessage(Message.obtain(mHandler, INJECT_NTP_TIME_FINISHED));
+ sendMessage(INJECT_NTP_TIME_FINISHED, 0, null);
if (mPeriodicTimeInjection) {
// send delayed message for next NTP injection
// since this is delayed and not urgent we do not hold a wake lock here
- mHandler.removeMessages(INJECT_NTP_TIME);
- mHandler.sendMessageDelayed(Message.obtain(mHandler, INJECT_NTP_TIME), delay);
+ mHandler.sendEmptyMessageDelayed(INJECT_NTP_TIME, delay);
}
+
+ // release wake lock held by task
+ mWakeLock.release();
}
});
}
@@ -652,6 +656,8 @@ public class GpsLocationProvider implements LocationProviderInterface {
}
mDownloadXtraDataPending = STATE_DOWNLOADING;
+ // hold wake lock while task runs
+ mWakeLock.acquire();
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
@@ -664,17 +670,17 @@ public class GpsLocationProvider implements LocationProviderInterface {
native_inject_xtra_data(data, data.length);
}
- mHandler.sendMessage(Message.obtain(mHandler, DOWNLOAD_XTRA_DATA_FINISHED));
+ sendMessage(DOWNLOAD_XTRA_DATA_FINISHED, 0, null);
if (data == null) {
// try again later
// since this is delayed and not urgent we do not hold a wake lock here
- mHandler.removeMessages(DOWNLOAD_XTRA_DATA);
- mHandler.sendMessageDelayed(Message.obtain(mHandler, DOWNLOAD_XTRA_DATA),
- RETRY_INTERVAL);
+ mHandler.sendEmptyMessageDelayed(DOWNLOAD_XTRA_DATA, RETRY_INTERVAL);
}
- }
+ // release wake lock held by task
+ mWakeLock.release();
+ }
});
}
@@ -1475,11 +1481,17 @@ public class GpsLocationProvider implements LocationProviderInterface {
private void sendMessage(int message, int arg, Object obj) {
// hold a wake lock until this message is delivered
+ // note that this assumes the message will not be removed from the queue before
+ // it is handled (otherwise the wake lock would be leaked).
mWakeLock.acquire();
mHandler.obtainMessage(message, arg, 1, obj).sendToTarget();
}
private final class ProviderHandler extends Handler {
+ public ProviderHandler() {
+ super(true /*async*/);
+ }
+
@Override
public void handleMessage(Message msg) {
int message = msg.what;