Skip to content

Commit e5dea75

Browse files
author
Dianne Hackborn
committed
Attempt to reduce problems from issue #3183612
java.lang.SecurityException: Neither user 1209 nor current... ...process has android.permission.WAKE_LOCK. It looks like, somehow, the calling uid/pid of the SyncHandler thread is getting corrupted. This change has Looper check for these values changing from their original defaults and, if there is a problem, resetting them and logging a WTF. Hopefully this will avoid crashing the process, while also giving us more helpful error reports about what is going on. Change-Id: Iff06d575951fb8c06e2a3c31141f2907a715eb81
1 parent be4b39d commit e5dea75

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

core/java/android/os/Looper.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package android.os;
1818

1919
import android.util.Config;
20+
import android.util.Log;
2021
import android.util.Printer;
2122

2223
/**
@@ -106,6 +107,12 @@ public synchronized static final Looper getMainLooper() {
106107
public static final void loop() {
107108
Looper me = myLooper();
108109
MessageQueue queue = me.mQueue;
110+
111+
// Make sure the identity of this thread is that of the local process,
112+
// and keep track of what that identity token actually is.
113+
Binder.clearCallingIdentity();
114+
final long ident = Binder.clearCallingIdentity();
115+
109116
while (true) {
110117
Message msg = queue.next(); // might block
111118
//if (!me.mRun) {
@@ -124,6 +131,17 @@ public static final void loop() {
124131
if (me.mLogging!= null) me.mLogging.println(
125132
"<<<<< Finished to " + msg.target + " "
126133
+ msg.callback);
134+
135+
// Make sure that during the course of dispatching the
136+
// identity of the thread wasn't corrupted.
137+
final long newIdent = Binder.clearCallingIdentity();
138+
if (ident != newIdent) {
139+
Log.wtf("Looper", "Thread identity changed from 0x"
140+
+ Long.toHexString(ident) + " to 0x"
141+
+ Long.toHexString(newIdent) + " while dispatching to "
142+
+ msg.target + " " + msg.callback + " what=" + msg.what);
143+
}
144+
127145
msg.recycle();
128146
}
129147
}

0 commit comments

Comments
 (0)