diff options
| author | Jeff Brown <jeffbrown@google.com> | 2013-09-09 16:14:20 -0700 |
|---|---|---|
| committer | Jeff Brown <jeffbrown@google.com> | 2013-09-09 16:14:20 -0700 |
| commit | 605839066af9a5825c074e54e3db90cf88a2220a (patch) | |
| tree | df88c8e50ec99cd94cd0e60173f6cee1ecb9abb9 /core/java/android/os/MessageQueue.java | |
| parent | 43afbe5842d88602b8da9868dfa778d669e6462f (diff) | |
Fix crash when Looper used after quit.
Calling Looper.loop() after quit() isn't supported but it shouldn't
crash either.
Bug: 8808624
Change-Id: I73ea54444ed908c2e8964645f4a8cd08b842baac
Diffstat (limited to 'core/java/android/os/MessageQueue.java')
| -rw-r--r-- | core/java/android/os/MessageQueue.java | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/core/java/android/os/MessageQueue.java b/core/java/android/os/MessageQueue.java index d1b8213d95fc..159b194e76b4 100644 --- a/core/java/android/os/MessageQueue.java +++ b/core/java/android/os/MessageQueue.java @@ -125,6 +125,14 @@ public final class MessageQueue { } Message next() { + // Return here if the message loop has already quit and been disposed. + // This can happen if the application tries to restart a looper after quit + // which is not supported. + final int ptr = mPtr; + if (ptr == 0) { + return null; + } + int pendingIdleHandlerCount = -1; // -1 only during first iteration int nextPollTimeoutMillis = 0; for (;;) { @@ -132,9 +140,7 @@ public final class MessageQueue { Binder.flushPendingCommands(); } - // We can assume mPtr != 0 because the loop is obviously still running. - // The looper will not call this method after the loop quits. - nativePollOnce(mPtr, nextPollTimeoutMillis); + nativePollOnce(ptr, nextPollTimeoutMillis); synchronized (this) { // Try to retrieve the next message. Return if found. |
