summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Shai Barack <shayba@google.com> 2024-11-27 17:28:46 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-11-27 17:28:46 +0000
commit2ec35d9638cc351e7e2397cb7c57eddca60f43c6 (patch)
treee85f21574e16dd0e285915e720e082854587e1ee
parent29536598de23db1dcbaa2867dc75b8fac1a5824b (diff)
parent5e0e68f1bdca2ccb35d65af982c4347fab147388 (diff)
Merge "Allow SystemUI to use the concurrent message queue" into main
-rw-r--r--core/java/android/os/CombinedMessageQueue/MessageQueue.java73
1 files changed, 47 insertions, 26 deletions
diff --git a/core/java/android/os/CombinedMessageQueue/MessageQueue.java b/core/java/android/os/CombinedMessageQueue/MessageQueue.java
index 476968151e18..23114c4318c7 100644
--- a/core/java/android/os/CombinedMessageQueue/MessageQueue.java
+++ b/core/java/android/os/CombinedMessageQueue/MessageQueue.java
@@ -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) {
- // 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());
+ initIsProcessAllowedToUseConcurrent();
+ mUseConcurrent = sIsProcessAllowedToUseConcurrent;
+ mQuitAllowed = quitAllowed;
+ mPtr = nativeInit();
+ }
- // Some platform tests run in system 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;
- }
- }
+ private static void initIsProcessAllowedToUseConcurrent() {
+ if (sIsProcessAllowedToUseConcurrent != null) {
+ return;
+ }
- // 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.
+ if (RavenwoodEnvironment.getInstance().isRunningOnRavenwood()) {
+ sIsProcessAllowedToUseConcurrent = false;
+ return;
+ }
- // Holdback study.
- if (useConcurrent && Flags.messageQueueForceLegacy()) {
- useConcurrent = false;
- }
+ 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;
+ }
- sIsProcessAllowedToUseConcurrent = useConcurrent;
- mUseConcurrent = useConcurrent;
+ // 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.
+ sIsProcessAllowedToUseConcurrent = UserHandle.isCore(Process.myUid());
+
+ if (sIsProcessAllowedToUseConcurrent) {
+ // Some platform tests run in core UIDs.
+ // Use this awful heuristic to detect them.
+ if (processName.contains("test") || processName.contains("Test")) {
+ sIsProcessAllowedToUseConcurrent = false;
+ }
} else {
- mUseConcurrent = sIsProcessAllowedToUseConcurrent;
+ // 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.
}
- mQuitAllowed = quitAllowed;
- mPtr = nativeInit();
+ // 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 (sIsProcessAllowedToUseConcurrent && Flags.messageQueueForceLegacy()) {
+ sIsProcessAllowedToUseConcurrent = false;
+ }
}
@Override