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

Commit 5e0e68f1 authored by Shai Barack's avatar Shai Barack
Browse files

Allow SystemUI to use the concurrent message queue

SystemUI is not considered a core process, but it's still safe for it to use the concurrent message queue, and it would benefit from the performance boost.

Change-Id: I16ee8e000dbf79a755bb58c1d45a34b800a69c98
Flag: build.RELEASE_PACKAGE_MESSAGEQUEUE_IMPLEMENTATION
parent 2d0e124d
Loading
Loading
Loading
Loading
+47 −26
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import android.util.Printer;
import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;

import com.android.internal.ravenwood.RavenwoodEnvironment;

import dalvik.annotation.optimization.NeverCompile;

import java.io.FileDescriptor;
@@ -116,39 +118,58 @@ public final class MessageQueue {
    private native static void nativeSetFileDescriptorEvents(long ptr, int fd, int events);

    MessageQueue(boolean quitAllowed) {
        if (sIsProcessAllowedToUseConcurrent == null) {
        initIsProcessAllowedToUseConcurrent();
        mUseConcurrent = sIsProcessAllowedToUseConcurrent;
        mQuitAllowed = quitAllowed;
        mPtr = nativeInit();
    }

    private static void initIsProcessAllowedToUseConcurrent() {
        if (sIsProcessAllowedToUseConcurrent != null) {
            return;
        }

        if (RavenwoodEnvironment.getInstance().isRunningOnRavenwood()) {
            sIsProcessAllowedToUseConcurrent = false;
            return;
        }

        final String processName = Process.myProcessName();
        if (processName == null) {
            // Assume that this is a host-side test and avoid concurrent mode for now.
            sIsProcessAllowedToUseConcurrent = false;
            return;
        }

        // 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.
            boolean useConcurrent = UserHandle.isCore(Process.myUid());
        sIsProcessAllowedToUseConcurrent = UserHandle.isCore(Process.myUid());

            // Some platform tests run in system UIDs.
        if (sIsProcessAllowedToUseConcurrent) {
            // Some platform tests run in core UIDs.
            // Use this awful heuristic to detect them.
            if (useConcurrent) {
                final String processName = Process.myProcessName();
                if (processName == null
                        || processName.contains("test")
                        || processName.contains("Test")) {
                    useConcurrent = false;
            if (processName.contains("test") || processName.contains("Test")) {
                sIsProcessAllowedToUseConcurrent = false;
            }
        } else {
            // Also explicitly allow SystemUI processes.
            // SystemUI doesn't run in a core UID, but we want to give it the performance boost,
            // and we know that it's safe to use the concurrent implementation in SystemUI.
            sIsProcessAllowedToUseConcurrent =
                    processName.equals("com.android.systemui")
                            || processName.startsWith("com.android.systemui:");
            // On Android distributions where SystemUI has a different process name,
            // the above condition may need to be adjusted accordingly.
        }

            // We can lift this restriction in the future after we've made it possible for test
        // We can lift these restrictions in the future after we've made it possible for test
        // authors to test Looper and MessageQueue without resorting to reflection.

        // Holdback study.
            if (useConcurrent && Flags.messageQueueForceLegacy()) {
                useConcurrent = false;
            }

            sIsProcessAllowedToUseConcurrent = useConcurrent;
            mUseConcurrent = useConcurrent;
        } else {
            mUseConcurrent = sIsProcessAllowedToUseConcurrent;
        if (sIsProcessAllowedToUseConcurrent && Flags.messageQueueForceLegacy()) {
            sIsProcessAllowedToUseConcurrent = false;
        }

        mQuitAllowed = quitAllowed;
        mPtr = nativeInit();
    }

    @Override