Merge "Make all messages in KeyguardViewMediator asynchronous." into jb-mr1-dev
diff --git a/core/java/android/os/Handler.java b/core/java/android/os/Handler.java
index b892c81..7785368 100644
--- a/core/java/android/os/Handler.java
+++ b/core/java/android/os/Handler.java
@@ -123,6 +123,7 @@
}
mQueue = mLooper.mQueue;
mCallback = null;
+ mAsynchronous = false;
}
/**
@@ -147,6 +148,7 @@
}
mQueue = mLooper.mQueue;
mCallback = callback;
+ mAsynchronous = false;
}
/**
@@ -156,6 +158,7 @@
mLooper = looper;
mQueue = looper.mQueue;
mCallback = null;
+ mAsynchronous = false;
}
/**
@@ -166,6 +169,31 @@
mLooper = looper;
mQueue = looper.mQueue;
mCallback = callback;
+ mAsynchronous = false;
+ }
+
+ /**
+ * Use the provided queue instead of the default one and take a callback
+ * interface in which to handle messages. Also set whether the handler
+ * should be asynchronous.
+ *
+ * Handlers are synchronous by default unless this constructor is used to make
+ * one that is strictly asynchronous.
+ *
+ * Asynchronous messages represent interrupts or events that do not require global ordering
+ * with represent to synchronous messages. Asynchronous messages are not subject to
+ * the synchronization barriers introduced by {@link MessageQueue#enqueueSyncBarrier(long)}.
+ *
+ * @param async If true, the handler calls {@link Message#setAsynchronous(boolean)} for
+ * each {@link Message} that is sent to it or {@link Runnable} that is posted to it.
+ *
+ * @hide
+ */
+ public Handler(Looper looper, Callback callback, boolean async) {
+ mLooper = looper;
+ mQueue = looper.mQueue;
+ mCallback = callback;
+ mAsynchronous = async;
}
/**
@@ -464,20 +492,15 @@
* the looper is quit before the delivery time of the message
* occurs then the message will be dropped.
*/
- public boolean sendMessageAtTime(Message msg, long uptimeMillis)
- {
- boolean sent = false;
+ public boolean sendMessageAtTime(Message msg, long uptimeMillis) {
MessageQueue queue = mQueue;
- if (queue != null) {
- msg.target = this;
- sent = queue.enqueueMessage(msg, uptimeMillis);
- }
- else {
+ if (queue == null) {
RuntimeException e = new RuntimeException(
- this + " sendMessageAtTime() called with no mQueue");
+ this + " sendMessageAtTime() called with no mQueue");
Log.w("Looper", e.getMessage(), e);
+ return false;
}
- return sent;
+ return enqueueMessage(queue, msg, uptimeMillis);
}
/**
@@ -492,20 +515,23 @@
* message queue. Returns false on failure, usually because the
* looper processing the message queue is exiting.
*/
- public final boolean sendMessageAtFrontOfQueue(Message msg)
- {
- boolean sent = false;
+ public final boolean sendMessageAtFrontOfQueue(Message msg) {
MessageQueue queue = mQueue;
- if (queue != null) {
- msg.target = this;
- sent = queue.enqueueMessage(msg, 0);
- }
- else {
+ if (queue == null) {
RuntimeException e = new RuntimeException(
this + " sendMessageAtTime() called with no mQueue");
Log.w("Looper", e.getMessage(), e);
+ return false;
}
- return sent;
+ return enqueueMessage(queue, msg, 0);
+ }
+
+ private boolean enqueueMessage(MessageQueue queue, Message msg, long uptimeMillis) {
+ msg.target = this;
+ if (mAsynchronous) {
+ msg.setAsynchronous(true);
+ }
+ return queue.enqueueMessage(msg, uptimeMillis);
}
/**
@@ -618,5 +644,6 @@
final MessageQueue mQueue;
final Looper mLooper;
final Callback mCallback;
+ final boolean mAsynchronous;
IMessenger mMessenger;
}
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
index 0086f3c..472fd1a 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
@@ -34,6 +34,7 @@
import android.media.SoundPool;
import android.os.Handler;
import android.os.LocalPowerManager;
+import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
@@ -976,7 +977,7 @@
* interacts with the keyguard ui should be posted to this handler, rather
* than called directly.
*/
- private Handler mHandler = new Handler() {
+ private Handler mHandler = new Handler(Looper.myLooper(), null, true /*async*/) {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {