android: Handle pending exceptions in MessagePump.
It's possible for there to be a pending Java exception for the current
thread when the Android version of MessagePumpForUI is called, because
the ALooper we use to schedule our message pump iterations can also have
other callbacks running on it and ALooper doesn't check for exceptions
between callbacks.
One example of this is render thread exceptions on P and earlier, which
are thrown by sending a message to the UI thread in native - if we get
unlucky and our MessagePumpForUI runs afterward in the same ALooper
polling cycle, we will crash the first time we make a JNI call,
resulting in a confusing stack trace.
Avoid this by just skipping our callback execution if there is a pending
exception set at the start of the callback. If the exception ends up not
being fatal (caught by something higher up the stack) then our callback
will be run again in the next iteration, as the fd has not been reset.
Bug: 1052830
Change-Id: Ie13ceab6c2c1b988189791546fa12a5529ef17b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062434
Reviewed-by: Sami Kyöstilä <[email protected]>
Commit-Queue: Richard Coles <[email protected]>
Cr-Commit-Position: refs/heads/master@{#742600}
diff --git a/base/message_loop/message_pump_android.h b/base/message_loop/message_pump_android.h
index a6014b4..0e7da3f 100644
--- a/base/message_loop/message_pump_android.h
+++ b/base/message_loop/message_pump_android.h
@@ -97,6 +97,9 @@
// The Android Looper for this thread.
ALooper* looper_ = nullptr;
+ // The JNIEnv* for this thread, used to check for pending exceptions.
+ JNIEnv* env_;
+
DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
};