Merge "Remove modern_queue_enabled flag." into main
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index 39823a8..fae4348 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -6054,20 +6054,6 @@
     }
 
     /**
-     * Checks if the "modern" broadcast queue is enabled.
-     *
-     * @hide
-     */
-    @RequiresPermission(android.Manifest.permission.DUMP)
-    public boolean isModernBroadcastQueueEnabled() {
-        try {
-            return getService().isModernBroadcastQueueEnabled();
-        } catch (RemoteException e) {
-            throw e.rethrowFromSystemServer();
-        }
-    }
-
-    /**
      * Checks if the process represented by the given {@code pid} is frozen.
      *
      * @hide
diff --git a/core/java/android/app/ActivityManagerInternal.java b/core/java/android/app/ActivityManagerInternal.java
index 062b89e..e28a6ce 100644
--- a/core/java/android/app/ActivityManagerInternal.java
+++ b/core/java/android/app/ActivityManagerInternal.java
@@ -226,12 +226,6 @@
     public abstract boolean isSystemReady();
 
     /**
-     * @return {@code true} if system is using the "modern" broadcast queue,
-     *         {@code false} otherwise.
-     */
-    public abstract boolean isModernQueueEnabled();
-
-    /**
      * Enforce capability restrictions on use of the given BroadcastOptions
      */
     public abstract void enforceBroadcastOptionsPermissions(@Nullable Bundle options,
diff --git a/core/java/android/app/IActivityManager.aidl b/core/java/android/app/IActivityManager.aidl
index 7a95720..5e6b54b 100644
--- a/core/java/android/app/IActivityManager.aidl
+++ b/core/java/android/app/IActivityManager.aidl
@@ -898,10 +898,6 @@
     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
     void forceDelayBroadcastDelivery(in String targetPackage, long delayedDurationMs);
 
-    /** Checks if the modern broadcast queue is enabled. */
-    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
-    boolean isModernBroadcastQueueEnabled();
-
     /** Checks if the process represented by the given pid is frozen. */
     @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.DUMP)")
     boolean isProcessFrozen(int pid);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 7bd6745..60bfc63 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -725,12 +725,6 @@
     // Whether we should use SCHED_FIFO for UI and RenderThreads.
     final boolean mUseFifoUiScheduling;
 
-    /**
-     * Flag indicating if we should use {@link BroadcastQueueModernImpl} instead
-     * of the default {@link BroadcastQueueImpl}.
-     */
-    final boolean mEnableModernQueue;
-
     @GuardedBy("this")
     private final SparseArray<IUnsafeIntentStrictModeCallback>
             mStrictModeCallbacks = new SparseArray<>();
@@ -2508,7 +2502,6 @@
         mInternal = new LocalService();
         mPendingStartActivityUids = new PendingStartActivityUids();
         mUseFifoUiScheduling = false;
-        mEnableModernQueue = false;
         mBroadcastQueue = injector.getBroadcastQueue(this);
         mComponentAliasResolver = new ComponentAliasResolver(this);
     }
@@ -2550,9 +2543,6 @@
                 ? new OomAdjusterModernImpl(this, mProcessList, activeUids)
                 : new OomAdjuster(this, mProcessList, activeUids);
 
-        mEnableModernQueue = new BroadcastConstants(
-                Settings.Global.BROADCAST_FG_CONSTANTS).MODERN_QUEUE_ENABLED;
-
         mBroadcastQueue = mInjector.getBroadcastQueue(this);
 
         mServices = new ActiveServices(this);
@@ -15025,9 +15015,6 @@
                         + " ordered=" + ordered + " userid=" + userId
                         + " options=" + (brOptions == null ? "null" : brOptions.toBundle()));
         if ((resultTo != null) && !ordered) {
-            if (!mEnableModernQueue) {
-                Slog.w(TAG, "Broadcast " + intent + " not ordered but result callback requested!");
-            }
             if (!UserHandle.isCore(callingUid)) {
                 String msg = "Unauthorized unordered resultTo broadcast "
                              + intent + " sent from uid " + callingUid;
@@ -15628,29 +15615,6 @@
         filterNonExportedComponents(intent, callingUid, callingPid, registeredReceivers,
                 mPlatformCompat, callerPackage, resolvedType);
         int NR = registeredReceivers != null ? registeredReceivers.size() : 0;
-        if (!ordered && NR > 0 && !mEnableModernQueue) {
-            // If we are not serializing this broadcast, then send the
-            // registered receivers separately so they don't wait for the
-            // components to be launched. We don't do this split for the modern
-            // queue because delivery to registered receivers isn't blocked
-            // behind manifest receivers.
-            if (isCallerSystem) {
-                checkBroadcastFromSystem(intent, callerApp, callerPackage, callingUid,
-                        isProtectedBroadcast, registeredReceivers);
-            }
-            final BroadcastQueue queue = mBroadcastQueue;
-            BroadcastRecord r = new BroadcastRecord(queue, intent, callerApp, callerPackage,
-                    callerFeatureId, callingPid, callingUid, callerInstantApp, resolvedType,
-                    requiredPermissions, excludedPermissions, excludedPackages, appOp, brOptions,
-                    registeredReceivers, resultToApp, resultTo, resultCode, resultData,
-                    resultExtras, ordered, sticky, false, userId,
-                    backgroundStartPrivileges, timeoutExempt, filterExtrasForReceiver,
-                    callerAppProcessState);
-            if (DEBUG_BROADCAST) Slog.v(TAG_BROADCAST, "Enqueueing parallel broadcast " + r);
-            queue.enqueueBroadcastLocked(r);
-            registeredReceivers = null;
-            NR = 0;
-        }
 
         // Merge into one list.
         int ir = 0;
@@ -18302,11 +18266,6 @@
         }
 
         @Override
-        public boolean isModernQueueEnabled() {
-            return mEnableModernQueue;
-        }
-
-        @Override
         public void enforceBroadcastOptionsPermissions(Bundle options, int callingUid) {
             enforceBroadcastOptionPermissionsInternal(options, callingUid);
         }
@@ -18735,7 +18694,6 @@
                     Binder.restoreCallingIdentity(origId);
                 }
             }
-
         }
 
         @Override
@@ -18745,12 +18703,8 @@
                 int userId, int[] appIdAllowList,
                 @Nullable BiFunction<Integer, Bundle, Bundle> filterExtrasForReceiver,
                 @Nullable Bundle bOptions) {
-            // Sending broadcasts with a finish callback without the need for the broadcasts
-            // delivery to be serialized is only supported by modern queue. So, when modern
-            // queue is disabled, we continue to send broadcasts in a serialized fashion.
-            final boolean serialized = !isModernQueueEnabled();
-            return broadcastIntent(intent, resultTo, requiredPermissions, serialized, userId,
-                    appIdAllowList, filterExtrasForReceiver, bOptions);
+            return broadcastIntent(intent, resultTo, requiredPermissions, false /* serialized */,
+                    userId, appIdAllowList, filterExtrasForReceiver, bOptions);
         }
 
         @Override
@@ -19789,21 +19743,11 @@
         Objects.requireNonNull(targetPackage);
         Preconditions.checkArgumentNonnegative(delayedDurationMs);
         enforceCallingPermission(permission.DUMP, "forceDelayBroadcastDelivery()");
-        // Ignore request if modern queue is not enabled
-        if (!mEnableModernQueue) {
-            return;
-        }
 
         mBroadcastQueue.forceDelayBroadcastDelivery(targetPackage, delayedDurationMs);
     }
 
     @Override
-    public boolean isModernBroadcastQueueEnabled() {
-        enforceCallingPermission(permission.DUMP, "isModernBroadcastQueueEnabled()");
-        return mEnableModernQueue;
-    }
-
-    @Override
     public boolean isProcessFrozen(int pid) {
         enforceCallingPermission(permission.DUMP, "isProcessFrozen()");
         return mOomAdjuster.mCachedAppOptimizer.isProcessFrozen(pid);
diff --git a/services/core/java/com/android/server/am/BroadcastConstants.java b/services/core/java/com/android/server/am/BroadcastConstants.java
index 887915d..57080f8 100644
--- a/services/core/java/com/android/server/am/BroadcastConstants.java
+++ b/services/core/java/com/android/server/am/BroadcastConstants.java
@@ -128,14 +128,6 @@
     public long ALLOW_BG_ACTIVITY_START_TIMEOUT = DEFAULT_ALLOW_BG_ACTIVITY_START_TIMEOUT;
 
     /**
-     * Flag indicating if we should use {@link BroadcastQueueModernImpl} instead
-     * of the default {@link BroadcastQueueImpl}.
-     */
-    public boolean MODERN_QUEUE_ENABLED = DEFAULT_MODERN_QUEUE_ENABLED;
-    private static final String KEY_MODERN_QUEUE_ENABLED = "modern_queue_enabled";
-    private static final boolean DEFAULT_MODERN_QUEUE_ENABLED = true;
-
-    /**
      * For {@link BroadcastQueueModernImpl}: Maximum dispatch parallelism
      * that we'll tolerate for ordinary broadcast dispatch.
      */
@@ -421,8 +413,6 @@
      */
     private void updateDeviceConfigConstants() {
         synchronized (this) {
-            MODERN_QUEUE_ENABLED = getDeviceConfigBoolean(KEY_MODERN_QUEUE_ENABLED,
-                    DEFAULT_MODERN_QUEUE_ENABLED);
             MAX_RUNNING_PROCESS_QUEUES = getDeviceConfigInt(KEY_MAX_RUNNING_PROCESS_QUEUES,
                     DEFAULT_MAX_RUNNING_PROCESS_QUEUES);
             EXTRA_RUNNING_URGENT_PROCESS_QUEUES = getDeviceConfigInt(
@@ -498,7 +488,6 @@
             pw.print(NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT);
             pw.println("):");
             pw.increaseIndent();
-            pw.print(KEY_MODERN_QUEUE_ENABLED, MODERN_QUEUE_ENABLED).println();
             pw.print(KEY_MAX_RUNNING_PROCESS_QUEUES, MAX_RUNNING_PROCESS_QUEUES).println();
             pw.print(KEY_MAX_RUNNING_ACTIVE_BROADCASTS, MAX_RUNNING_ACTIVE_BROADCASTS).println();
             pw.print(KEY_CORE_MAX_RUNNING_BLOCKING_BROADCASTS,
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index 13a1807..70d447f 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -646,7 +646,7 @@
                 new String[]{android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
                 AppOpsManager.OP_NONE,
                 getTemporaryAppAllowlistBroadcastOptions(REASON_LOCKED_BOOT_COMPLETED)
-                        .toBundle(), true,
+                        .toBundle(),
                 false, MY_PID, SYSTEM_UID,
                 Binder.getCallingUid(), Binder.getCallingPid(), userId);
     }
@@ -740,7 +740,7 @@
             unlockedIntent.addFlags(
                     Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND);
             mInjector.broadcastIntent(unlockedIntent, null, null, 0, null,
-                    null, null, AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID,
+                    null, null, AppOpsManager.OP_NONE, null, false, MY_PID, SYSTEM_UID,
                     Binder.getCallingUid(), Binder.getCallingPid(), userId);
         }
 
@@ -765,7 +765,7 @@
                                     | Intent.FLAG_RECEIVER_FOREGROUND);
                     mInjector.broadcastIntent(profileUnlockedIntent,
                             null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                            null, false, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
+                            null, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
                             Binder.getCallingPid(), parent.id);
                 }
             }
@@ -824,7 +824,7 @@
                                 initializeUser.run();
                             }
                         }, 0, null, null, null, AppOpsManager.OP_NONE,
-                        null, true, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
+                        null, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
                         Binder.getCallingPid(), userId);
             }
         }
@@ -876,7 +876,7 @@
                     new String[]{android.Manifest.permission.RECEIVE_BOOT_COMPLETED},
                     AppOpsManager.OP_NONE,
                     getTemporaryAppAllowlistBroadcastOptions(REASON_BOOT_COMPLETED).toBundle(),
-                    true, false, MY_PID, SYSTEM_UID, callingUid, callingPid, userId);
+                    false, MY_PID, SYSTEM_UID, callingUid, callingPid, userId);
         });
     }
 
@@ -1124,7 +1124,7 @@
                 mInjector.broadcastIntent(stoppingIntent,
                         null, stoppingReceiver, 0, null, null,
                         new String[]{INTERACT_ACROSS_USERS}, AppOpsManager.OP_NONE,
-                        null, true, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
+                        null, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
                         Binder.getCallingPid(), UserHandle.USER_ALL);
             });
         }
@@ -1187,7 +1187,7 @@
         mInjector.broadcastIntent(shutdownIntent,
                 null, shutdownReceiver, 0, null, null, null,
                 AppOpsManager.OP_NONE,
-                null, true, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
+                null, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
                 Binder.getCallingPid(), userId);
     }
 
@@ -1464,7 +1464,7 @@
         intent.putExtra(Intent.EXTRA_USER_HANDLE, userId);
         mInjector.broadcastIntent(intent,
                 null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                null, false, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
+                null, false, MY_PID, SYSTEM_UID, Binder.getCallingUid(),
                 Binder.getCallingPid(), UserHandle.USER_ALL);
 
         // Send PROFILE_INACCESSIBLE broadcast if a profile was stopped
@@ -2404,7 +2404,7 @@
         mInjector.broadcastIntent(intent, /* resolvedType= */ null, /* resultTo= */ null,
                 /* resultCode= */ 0, /* resultData= */ null, /* resultExtras= */ null,
                 /* requiredPermissions= */ null, AppOpsManager.OP_NONE, /* bOptions= */ null,
-                /* ordered= */ false, /* sticky= */ false, MY_PID, SYSTEM_UID,
+                /* sticky= */ false, MY_PID, SYSTEM_UID,
                 callingUid, callingPid, userId);
     }
 
@@ -2432,7 +2432,7 @@
                     }
                 }, /* resultCode= */ 0, /* resultData= */ null, /* resultExtras= */ null,
                 new String[]{INTERACT_ACROSS_USERS}, AppOpsManager.OP_NONE, /* bOptions= */ null,
-                /* ordered= */ true, /* sticky= */ false, MY_PID, SYSTEM_UID,
+                /* sticky= */ false, MY_PID, SYSTEM_UID,
                 callingUid, callingPid, UserHandle.USER_ALL);
     }
 
@@ -2457,7 +2457,7 @@
                     intent.putExtra(Intent.EXTRA_USER, UserHandle.of(profileUserId));
                     mInjector.broadcastIntent(intent,
                             null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                            null, false, false, MY_PID, SYSTEM_UID, callingUid, callingPid,
+                            null, false, MY_PID, SYSTEM_UID, callingUid, callingPid,
                             profileUserId);
                 }
             }
@@ -2476,7 +2476,7 @@
                     intent.putExtra(Intent.EXTRA_USER, UserHandle.of(profileUserId));
                     mInjector.broadcastIntent(intent,
                             null, null, 0, null, null, null, AppOpsManager.OP_NONE,
-                            null, false, false, MY_PID, SYSTEM_UID, callingUid, callingPid,
+                            null, false, MY_PID, SYSTEM_UID, callingUid, callingPid,
                             profileUserId);
                 }
                 intent = new Intent(Intent.ACTION_USER_SWITCHED);
@@ -2489,7 +2489,7 @@
                 mInjector.broadcastIntent(intent,
                         null, null, 0, null, null,
                         new String[] {android.Manifest.permission.MANAGE_USERS},
-                        AppOpsManager.OP_NONE, null, false, false, MY_PID, SYSTEM_UID, callingUid,
+                        AppOpsManager.OP_NONE, null, false, MY_PID, SYSTEM_UID, callingUid,
                         callingPid, UserHandle.USER_ALL);
             }
         } finally {
@@ -2513,7 +2513,7 @@
         mInjector.broadcastIntent(intent, /* resolvedType= */ null, /* resultTo= */
                 null, /* resultCode= */ 0, /* resultData= */ null, /* resultExtras= */
                 null, /* requiredPermissions= */ null, AppOpsManager.OP_NONE, /* bOptions= */
-                null, /* ordered= */ false, /* sticky= */ false, MY_PID, SYSTEM_UID,
+                null, /* sticky= */ false, MY_PID, SYSTEM_UID,
                 Binder.getCallingUid(), Binder.getCallingPid(), parentId);
     }
 
@@ -3576,7 +3576,7 @@
         protected int broadcastIntent(Intent intent, String resolvedType,
                 IIntentReceiver resultTo, int resultCode, String resultData,
                 Bundle resultExtras, String[] requiredPermissions, int appOp, Bundle bOptions,
-                boolean ordered, boolean sticky, int callingPid, int callingUid, int realCallingUid,
+                boolean sticky, int callingPid, int callingUid, int realCallingUid,
                 int realCallingPid, @UserIdInt int userId) {
 
             int logUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
@@ -3585,21 +3585,13 @@
             }
             EventLog.writeEvent(EventLogTags.UC_SEND_USER_BROADCAST, logUserId, intent.getAction());
 
-            // When the modern broadcast stack is enabled, deliver all our
-            // broadcasts as unordered, since the modern stack has better
-            // support for sequencing cold-starts, and it supports delivering
-            // resultTo for non-ordered broadcasts
-            if (mService.mEnableModernQueue) {
-                ordered = false;
-            }
-
             TimingsTraceAndSlog t = new TimingsTraceAndSlog();
             // TODO b/64165549 Verify that mLock is not held before calling AMS methods
             synchronized (mService) {
                 t.traceBegin("broadcastIntent-" + userId + "-" + intent.getAction());
                 final int result = mService.broadcastIntentLocked(null, null, null, intent,
                         resolvedType, resultTo, resultCode, resultData, resultExtras,
-                        requiredPermissions, null, null, appOp, bOptions, ordered, sticky,
+                        requiredPermissions, null, null, appOp, bOptions, false, sticky,
                         callingPid, callingUid, realCallingUid, realCallingPid, userId);
                 t.traceEnd();
                 return result;
diff --git a/services/core/java/com/android/server/pm/BroadcastHelper.java b/services/core/java/com/android/server/pm/BroadcastHelper.java
index 9af2b3f..278deb8 100644
--- a/services/core/java/com/android/server/pm/BroadcastHelper.java
+++ b/services/core/java/com/android/server/pm/BroadcastHelper.java
@@ -207,18 +207,8 @@
                     + intent.toShortString(false, true, false, false)
                     + " " + intent.getExtras(), here);
         }
-        final boolean ordered;
-        if (mAmInternal.isModernQueueEnabled()) {
-            // When the modern broadcast stack is enabled, deliver all our
-            // broadcasts as unordered, since the modern stack has better
-            // support for sequencing cold-starts, and it supports
-            // delivering resultTo for non-ordered broadcasts
-            ordered = false;
-        } else {
-            ordered = (finishedReceiver != null);
-        }
-        mAmInternal.broadcastIntent(
-                intent, finishedReceiver, requiredPermissions, ordered, userId,
+        mAmInternal.broadcastIntentWithCallback(
+                intent, finishedReceiver, requiredPermissions, userId,
                 broadcastAllowList == null ? null : broadcastAllowList.get(userId),
                 filterExtrasForReceiver, bOptions);
     }
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index 652cf18..fde49d2 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -902,9 +902,9 @@
         }
 
         if (mActivityManagerInternal.isSystemReady()) {
-            final boolean ordered = !mActivityManagerInternal.isModernQueueEnabled();
-            mActivityManagerInternal.broadcastIntent(mScreenOnIntent, mWakeUpBroadcastDone,
-                    null, ordered, UserHandle.USER_ALL, null, null, mScreenOnOffOptions);
+            mActivityManagerInternal.broadcastIntentWithCallback(mScreenOnIntent,
+                    mWakeUpBroadcastDone, null, UserHandle.USER_ALL,
+                    null, null, mScreenOnOffOptions);
         } else {
             EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_STOP, 2, 1);
             sendNextBroadcast();
@@ -927,9 +927,9 @@
         }
 
         if (mActivityManagerInternal.isSystemReady()) {
-            final boolean ordered = !mActivityManagerInternal.isModernQueueEnabled();
-            mActivityManagerInternal.broadcastIntent(mScreenOffIntent, mGoToSleepBroadcastDone,
-                    null, ordered, UserHandle.USER_ALL, null, null, mScreenOnOffOptions);
+            mActivityManagerInternal.broadcastIntentWithCallback(mScreenOffIntent,
+                    mGoToSleepBroadcastDone, null, UserHandle.USER_ALL,
+                    null, null, mScreenOnOffOptions);
         } else {
             EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_STOP, 3, 1);
             sendNextBroadcast();
diff --git a/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java b/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
index ea1a68a..7891661 100644
--- a/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/UserControllerTest.java
@@ -1342,7 +1342,7 @@
         @Override
         protected int broadcastIntent(Intent intent, String resolvedType,
                 IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
-                String[] requiredPermissions, int appOp, Bundle bOptions, boolean ordered,
+                String[] requiredPermissions, int appOp, Bundle bOptions,
                 boolean sticky, int callingPid, int callingUid, int realCallingUid,
                 int realCallingPid, int userId) {
             Log.i(TAG, "broadcastIntentLocked " + intent);