Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dd0726c1 authored by Shai Barack's avatar Shai Barack
Browse files

Revert^2 "Disable concurrent mode when instrumentation is loaded"

This reverts commit 7cdc4b8f.

Reason for revert: fixed b/378964381

Change-Id: Idc6a5a1280d5ecbf3a9c506a38a17e097e6ae89c
parent 7cdc4b8f
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.os;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.TestApi;
import android.app.ActivityThread;
import android.app.Instrumentation;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Process;
import android.os.UserHandle;
@@ -31,7 +33,6 @@ import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;

import dalvik.annotation.optimization.NeverCompile;
import dalvik.system.VMDebug;

import java.io.FileDescriptor;
import java.lang.annotation.Retention;
@@ -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();
    }