OSDN Git Service

am 3d79f1ce: am edc68a00: Merge "Attempt to reduce problems from issue #3183612"...
authorSimon Wilson <simonwilson@google.com>
Thu, 3 Mar 2011 02:13:49 +0000 (18:13 -0800)
committerAndroid Git Automerger <android-git-automerger@android.com>
Thu, 3 Mar 2011 02:13:49 +0000 (18:13 -0800)
* commit '3d79f1ce84ee60dbb26468b9e5f75f4ccb5ed8aa':
  Attempt to reduce problems from issue #3183612

1  2 
core/java/android/os/Looper.java

@@@ -108,12 -106,18 +108,18 @@@ public class Looper 
       */
      public static final void loop() {
          Looper me = myLooper();
 +        if (me == null) {
 +            throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");
 +        }
          MessageQueue queue = me.mQueue;
+         
+         // Make sure the identity of this thread is that of the local process,
+         // and keep track of what that identity token actually is.
+         Binder.clearCallingIdentity();
+         final long ident = Binder.clearCallingIdentity();
+         
          while (true) {
              Message msg = queue.next(); // might block
 -            //if (!me.mRun) {
 -            //    break;
 -            //}
              if (msg != null) {
                  if (msg.target == null) {
                      // No target is a magic identifier for the quit message.
                          + msg.callback + ": " + msg.what
                          );
                  msg.target.dispatchMessage(msg);
 -                if (me.mLogging!= null) me.mLogging.println(
 +                if (me.mLogging != null) me.mLogging.println(
                          "<<<<< Finished to    " + msg.target + " "
                          + msg.callback);
+                 
+                 // Make sure that during the course of dispatching the
+                 // identity of the thread wasn't corrupted.
+                 final long newIdent = Binder.clearCallingIdentity();
+                 if (ident != newIdent) {
+                     Log.wtf("Looper", "Thread identity changed from 0x"
+                             + Long.toHexString(ident) + " to 0x"
+                             + Long.toHexString(newIdent) + " while dispatching to "
+                             + msg.target + " " + msg.callback + " what=" + msg.what);
+                 }
+                 
                  msg.recycle();
              }
          }