summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorMatthew Williams <mjwilliams@google.com>2013-09-30 21:46:58 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-30 21:46:59 +0000
commit508a57f58f873efcabc4d771b5f11285193685f6 (patch)
tree18e7d857b1daae1a8bd391a32f01129067a8a646 /services
parent6f07cc8424caccda695918f83e1b57f7a67d9f0c (diff)
parent8704fc3dae2361d41d026e6e6cade7a63b12c973 (diff)
downloadframeworks_base-508a57f58f873efcabc4d771b5f11285193685f6.zip
frameworks_base-508a57f58f873efcabc4d771b5f11285193685f6.tar.gz
frameworks_base-508a57f58f873efcabc4d771b5f11285193685f6.tar.bz2
Merge "Remove blocking from SM before boot completed." into klp-dev
Diffstat (limited to 'services')
-rw-r--r--services/java/com/android/server/content/SyncManager.java50
1 files changed, 30 insertions, 20 deletions
diff --git a/services/java/com/android/server/content/SyncManager.java b/services/java/com/android/server/content/SyncManager.java
index 635ba5c..2ae7bc7 100644
--- a/services/java/com/android/server/content/SyncManager.java
+++ b/services/java/com/android/server/content/SyncManager.java
@@ -1785,16 +1785,20 @@ public class SyncManager {
public final SyncTimeTracker mSyncTimeTracker = new SyncTimeTracker();
private final HashMap<Pair<Account, String>, PowerManager.WakeLock> mWakeLocks =
Maps.newHashMap();
-
- private volatile CountDownLatch mReadyToRunLatch = new CountDownLatch(1);
+ private List<Message> mBootQueue = new ArrayList<Message>();
public void onBootCompleted() {
- mBootCompleted = true;
-
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.v(TAG, "Boot completed, clearing boot queue.");
+ }
doDatabaseCleanup();
-
- if (mReadyToRunLatch != null) {
- mReadyToRunLatch.countDown();
+ synchronized(this) {
+ // Dispatch any stashed messages.
+ for (Message message : mBootQueue) {
+ sendMessage(message);
+ }
+ mBootQueue = null;
+ mBootCompleted = true;
}
}
@@ -1811,20 +1815,24 @@ public class SyncManager {
return wakeLock;
}
- private void waitUntilReadyToRun() {
- CountDownLatch latch = mReadyToRunLatch;
- if (latch != null) {
- while (true) {
- try {
- latch.await();
- mReadyToRunLatch = null;
- return;
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
+ /**
+ * Stash any messages that come to the handler before boot is complete.
+ * {@link #onBootCompleted()} will disable this and dispatch all the messages collected.
+ * @param msg Message to dispatch at a later point.
+ * @return true if a message was enqueued, false otherwise. This is to avoid losing the
+ * message if we manage to acquire the lock but by the time we do boot has completed.
+ */
+ private boolean tryEnqueueMessageUntilReadyToRun(Message msg) {
+ synchronized (this) {
+ if (!mBootCompleted) {
+ // Need to copy the message bc looper will recycle it.
+ mBootQueue.add(Message.obtain(msg));
+ return true;
}
+ return false;
}
}
+
/**
* Used to keep track of whether a sync notification is active and who it is for.
*/
@@ -1854,13 +1862,15 @@ public class SyncManager {
@Override
public void handleMessage(Message msg) {
+ if (tryEnqueueMessageUntilReadyToRun(msg)) {
+ return;
+ }
+
long earliestFuturePollTime = Long.MAX_VALUE;
long nextPendingSyncTime = Long.MAX_VALUE;
-
// Setting the value here instead of a method because we want the dumpsys logs
// to have the most recent value used.
try {
- waitUntilReadyToRun();
mDataConnectionIsConnected = readDataConnectionState();
mSyncManagerWakeLock.acquire();
// Always do this first so that we be sure that any periodic syncs that