diff options
| author | 2024-11-13 22:45:13 +0000 | |
|---|---|---|
| committer | 2024-11-13 22:45:52 +0000 | |
| commit | 671c3e1e16feb5663cd12b64f5a7f0fed81c212f (patch) | |
| tree | 16a300ed7b01f832ed4e00c20f6cfcf0d4af5cf4 | |
| parent | fc463999b9e201c28624e1853afdef0753b9e640 (diff) | |
Disable concurrent mode when instrumentation is loaded
This fixes some platform tests that rely on reflection to access MessageQueue internals.
Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION
Change-Id: I8ba0a6e38e02341c234fb5a2a2e6fd26cc64f58f
| -rw-r--r-- | core/java/android/os/CombinedMessageQueue/MessageQueue.java | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/core/java/android/os/CombinedMessageQueue/MessageQueue.java b/core/java/android/os/CombinedMessageQueue/MessageQueue.java index 7529ab9ab894..172a994fd499 100644 --- a/core/java/android/os/CombinedMessageQueue/MessageQueue.java +++ b/core/java/android/os/CombinedMessageQueue/MessageQueue.java @@ -19,6 +19,7 @@ package android.os; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.TestApi; +import android.app.ActivityThread; import android.compat.annotation.UnsupportedAppUsage; import android.os.Process; import android.os.UserHandle; @@ -111,7 +112,20 @@ public final class MessageQueue { private native static void nativeSetFileDescriptorEvents(long ptr, int fd, int events); MessageQueue(boolean quitAllowed) { - mUseConcurrent = UserHandle.isCore(Process.myUid()) && !VMDebug.isDebuggingEnabled(); + // Concurrent mode modifies behavior that is observable via reflection and is commonly used + // by tests. + // For now, we limit it to system processes to avoid breaking apps and their tests. + mUseConcurrent = UserHandle.isCore(Process.myUid()); + // Even then, we don't use it if instrumentation is loaded as it breaks some + // platform tests. + final ActivityThread activityThread = ActivityThread.currentActivityThread(); + if (activityThread != null) { + final Instrumentation instrumentation = activityThread.getInstrumentation(); + mUseConcurrent &= instrumentation == null || !instrumentation.isInstrumenting(); + } + // We can lift this restriction in the future after we've made it possible for test authors + // to test Looper and MessageQueue without resorting to reflection. + mQuitAllowed = quitAllowed; mPtr = nativeInit(); } |