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

Commit e7eb1719 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge changes from topic "oct21"

* changes:
  Apply negative delay to "urgent" broadcasts.
  Deliver handful of system broadcasts as unordered.
  BroadcastQueue: more misc fixes before dogfooding.
parents 9a47209e 17814cc1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -220,6 +220,12 @@ public abstract class ActivityManagerInternal {
     */
    public abstract boolean isSystemReady();

    /**
     * @return {@code true} if system is using the "modern" broadcast queue,
     *         {@code false} otherwise.
     */
    public abstract boolean isModernQueueEnabled();

    /**
     * Returns package name given pid.
     *
+1 −0
Original line number Diff line number Diff line
@@ -597,6 +597,7 @@ public class SystemActions implements CoreStartable {
                case INTENT_ACTION_DPAD_CENTER: {
                    Intent intent = new Intent(intentAction);
                    intent.setPackage(context.getPackageName());
                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
                    return PendingIntent.getBroadcast(context, 0, intent,
                            PendingIntent.FLAG_IMMUTABLE);
                }
+10 −3
Original line number Diff line number Diff line
@@ -13897,7 +13897,7 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (DEBUG_BROADCAST_LIGHT) Slog.v(TAG_BROADCAST,
                (sticky ? "Broadcast sticky: ": "Broadcast: ") + intent
                + " ordered=" + ordered + " userid=" + userId);
        if ((resultTo != null) && !ordered) {
        if ((resultTo != null) && !ordered && !mEnableModernQueue) {
            Slog.w(TAG, "Broadcast " + intent + " not ordered but result callback requested!");
        }
@@ -14459,10 +14459,12 @@ public class ActivityManagerService extends IActivityManager.Stub
        filterNonExportedComponents(intent, callingUid, registeredReceivers,
                mPlatformCompat, callerPackage);
        int NR = registeredReceivers != null ? registeredReceivers.size() : 0;
        if (!ordered && NR > 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.
            // 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);
@@ -16895,6 +16897,11 @@ public class ActivityManagerService extends IActivityManager.Stub
            return mSystemReady;
        }
        @Override
        public boolean isModernQueueEnabled() {
            return mEnableModernQueue;
        }
        /**
         * Returns package name by pid.
         */
+15 −2
Original line number Diff line number Diff line
@@ -167,7 +167,7 @@ public class BroadcastConstants {
     */
    public long DELAY_NORMAL_MILLIS = DEFAULT_DELAY_NORMAL_MILLIS;
    private static final String KEY_DELAY_NORMAL_MILLIS = "bcast_delay_normal_millis";
    private static final long DEFAULT_DELAY_NORMAL_MILLIS = 1_000;
    private static final long DEFAULT_DELAY_NORMAL_MILLIS = 0;

    /**
     * For {@link BroadcastQueueModernImpl}: Delay to apply to broadcasts
@@ -175,7 +175,16 @@ public class BroadcastConstants {
     */
    public long DELAY_CACHED_MILLIS = DEFAULT_DELAY_CACHED_MILLIS;
    private static final String KEY_DELAY_CACHED_MILLIS = "bcast_delay_cached_millis";
    private static final long DEFAULT_DELAY_CACHED_MILLIS = 10_000;
    private static final long DEFAULT_DELAY_CACHED_MILLIS = 0;

    /**
     * For {@link BroadcastQueueModernImpl}: Delay to apply to urgent
     * broadcasts, typically a negative value to indicate they should be
     * executed before most other pending broadcasts.
     */
    public long DELAY_URGENT_MILLIS = DEFAULT_DELAY_URGENT_MILLIS;
    private static final String KEY_DELAY_URGENT_MILLIS = "bcast_delay_urgent_millis";
    private static final long DEFAULT_DELAY_URGENT_MILLIS = -120_000;

    /**
     * For {@link BroadcastQueueModernImpl}: Maximum number of complete
@@ -313,6 +322,8 @@ public class BroadcastConstants {
                    DEFAULT_DELAY_NORMAL_MILLIS);
            DELAY_CACHED_MILLIS = getDeviceConfigLong(KEY_DELAY_CACHED_MILLIS,
                    DEFAULT_DELAY_CACHED_MILLIS);
            DELAY_URGENT_MILLIS = getDeviceConfigLong(KEY_DELAY_URGENT_MILLIS,
                    DEFAULT_DELAY_URGENT_MILLIS);
            MAX_HISTORY_COMPLETE_SIZE = getDeviceConfigInt(KEY_MAX_HISTORY_COMPLETE_SIZE,
                    DEFAULT_MAX_HISTORY_COMPLETE_SIZE);
            MAX_HISTORY_SUMMARY_SIZE = getDeviceConfigInt(KEY_MAX_HISTORY_SUMMARY_SIZE,
@@ -354,6 +365,8 @@ public class BroadcastConstants {
                    TimeUtils.formatDuration(DELAY_NORMAL_MILLIS)).println();
            pw.print(KEY_DELAY_CACHED_MILLIS,
                    TimeUtils.formatDuration(DELAY_CACHED_MILLIS)).println();
            pw.print(KEY_DELAY_URGENT_MILLIS,
                    TimeUtils.formatDuration(DELAY_URGENT_MILLIS)).println();
            pw.print(KEY_MAX_HISTORY_COMPLETE_SIZE, MAX_HISTORY_COMPLETE_SIZE).println();
            pw.print(KEY_MAX_HISTORY_SUMMARY_SIZE, MAX_HISTORY_SUMMARY_SIZE).println();
            pw.decreaseIndent();
+17 −18
Original line number Diff line number Diff line
@@ -668,17 +668,18 @@ class BroadcastProcessQueue {
                return;
            }

            // If we have too many broadcasts pending, bypass any delays that
            // might have been applied above to aid draining
            if (mPending.size() + mPendingUrgent.size() >= constants.MAX_PENDING_BROADCASTS) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_MAX_PENDING;
                return;
            }

            if (mCountForeground > 0) {
                mRunnableAt = runnableAt;
                mRunnableAt = runnableAt + constants.DELAY_URGENT_MILLIS;
                mRunnableAtReason = REASON_CONTAINS_FOREGROUND;
            } else if (mCountInteractive > 0) {
                mRunnableAt = runnableAt + constants.DELAY_URGENT_MILLIS;
                mRunnableAtReason = REASON_CONTAINS_INTERACTIVE;
            } else if (mCountInstrumented > 0) {
                mRunnableAt = runnableAt + constants.DELAY_URGENT_MILLIS;
                mRunnableAtReason = REASON_CONTAINS_INSTRUMENTED;
            } else if (mProcessInstrumented) {
                mRunnableAt = runnableAt + constants.DELAY_URGENT_MILLIS;
                mRunnableAtReason = REASON_INSTRUMENTED;
            } else if (mCountOrdered > 0) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_CONTAINS_ORDERED;
@@ -688,18 +689,9 @@ class BroadcastProcessQueue {
            } else if (mCountPrioritized > 0) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_CONTAINS_PRIORITIZED;
            } else if (mCountInteractive > 0) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_CONTAINS_INTERACTIVE;
            } else if (mCountResultTo > 0) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_CONTAINS_RESULT_TO;
            } else if (mCountInstrumented > 0) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_CONTAINS_INSTRUMENTED;
            } else if (mProcessInstrumented) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_INSTRUMENTED;
            } else if (mProcessCached) {
                mRunnableAt = runnableAt + constants.DELAY_CACHED_MILLIS;
                mRunnableAtReason = REASON_CACHED;
@@ -707,6 +699,13 @@ class BroadcastProcessQueue {
                mRunnableAt = runnableAt + constants.DELAY_NORMAL_MILLIS;
                mRunnableAtReason = REASON_NORMAL;
            }

            // If we have too many broadcasts pending, bypass any delays that
            // might have been applied above to aid draining
            if (mPending.size() + mPendingUrgent.size() >= constants.MAX_PENDING_BROADCASTS) {
                mRunnableAt = runnableAt;
                mRunnableAtReason = REASON_MAX_PENDING;
            }
        } else {
            mRunnableAt = Long.MAX_VALUE;
            mRunnableAtReason = REASON_EMPTY;
Loading