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

Commit a1749585 authored by Anubhav Kakkar's avatar Anubhav Kakkar Committed by Android (Google) Code Review
Browse files

Merge "Shift execution of Intent.ACTION_LOCALE_CHANGED broadcast to a new...

Merge "Shift execution of Intent.ACTION_LOCALE_CHANGED broadcast to a new broadcast queue dedicated to offload foreground broadcast queue"
parents 451fd9a6 dafeebda
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -6415,6 +6415,7 @@ public class Intent implements Parcelable, Cloneable {
            FLAG_RECEIVER_FROM_SHELL,
            FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS,
            FLAG_RECEIVER_OFFLOAD,
            FLAG_RECEIVER_OFFLOAD_FOREGROUND,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Flags {}
@@ -6460,6 +6461,7 @@ public class Intent implements Parcelable, Cloneable {
            FLAG_RECEIVER_FROM_SHELL,
            FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS,
            FLAG_RECEIVER_OFFLOAD,
            FLAG_RECEIVER_OFFLOAD_FOREGROUND,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface MutableFlags {}
@@ -6913,6 +6915,14 @@ public class Intent implements Parcelable, Cloneable {
     * @hide
     */
    public static final int FLAG_RECEIVER_OFFLOAD = 0x80000000;
    /**
    /**
     * If set, when sending a broadcast the recipient will run on the system dedicated queue.
     *
     * @hide
     */
    public static final int FLAG_RECEIVER_OFFLOAD_FOREGROUND = 0x00000800;

    /**
     * If this is an ordered broadcast, don't allow receivers to abort the broadcast.
     * They can still propagate results through to later receivers, but they can not prevent
+36 −15
Original line number Diff line number Diff line
@@ -642,10 +642,11 @@ public class ActivityManagerService extends IActivityManager.Stub
    final BroadcastQueue mFgBroadcastQueue;
    final BroadcastQueue mBgBroadcastQueue;
    final BroadcastQueue mOffloadBroadcastQueue;
    final BroadcastQueue mBgOffloadBroadcastQueue;
    final BroadcastQueue mFgOffloadBroadcastQueue;
    // Convenient for easy iteration over the queues. Foreground is first
    // so that dispatch of foreground broadcasts gets precedence.
    final BroadcastQueue[] mBroadcastQueues = new BroadcastQueue[3];
    final BroadcastQueue[] mBroadcastQueues = new BroadcastQueue[4];
    @GuardedBy("this")
    BroadcastStats mLastBroadcastStats;
@@ -656,12 +657,20 @@ public class ActivityManagerService extends IActivityManager.Stub
    TraceErrorLogger mTraceErrorLogger;
    BroadcastQueue broadcastQueueForIntent(Intent intent) {
        if (isOnOffloadQueue(intent.getFlags())) {
        if (isOnFgOffloadQueue(intent.getFlags())) {
            if (DEBUG_BROADCAST_BACKGROUND) {
                Slog.i(TAG_BROADCAST,
                        "Broadcast intent " + intent + " on offload queue");
                        "Broadcast intent " + intent + " on foreground offload queue");
            }
            return mOffloadBroadcastQueue;
            return mFgOffloadBroadcastQueue;
        }
        if (isOnBgOffloadQueue(intent.getFlags())) {
            if (DEBUG_BROADCAST_BACKGROUND) {
                Slog.i(TAG_BROADCAST,
                        "Broadcast intent " + intent + " on background offload queue");
            }
            return mBgOffloadBroadcastQueue;
        }
        final boolean isFg = (intent.getFlags() & Intent.FLAG_RECEIVER_FOREGROUND) != 0;
@@ -2263,7 +2272,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        mPendingStartActivityUids = new PendingStartActivityUids(mContext);
        mUseFifoUiScheduling = false;
        mEnableOffloadQueue = false;
        mFgBroadcastQueue = mBgBroadcastQueue = mOffloadBroadcastQueue = null;
        mFgBroadcastQueue = mBgBroadcastQueue = mBgOffloadBroadcastQueue =
                mFgOffloadBroadcastQueue = null;
        mComponentAliasResolver = new ComponentAliasResolver(this);
    }
@@ -2324,11 +2334,14 @@ public class ActivityManagerService extends IActivityManager.Stub
                "foreground", foreConstants, false);
        mBgBroadcastQueue = new BroadcastQueue(this, mHandler,
                "background", backConstants, true);
        mOffloadBroadcastQueue = new BroadcastQueue(this, mHandler,
                "offload", offloadConstants, true);
        mBgOffloadBroadcastQueue = new BroadcastQueue(this, mHandler,
                "offload_bg", offloadConstants, true);
        mFgOffloadBroadcastQueue = new BroadcastQueue(this, mHandler,
                "offload_fg", foreConstants, true);
        mBroadcastQueues[0] = mFgBroadcastQueue;
        mBroadcastQueues[1] = mBgBroadcastQueue;
        mBroadcastQueues[2] = mOffloadBroadcastQueue;
        mBroadcastQueues[2] = mBgOffloadBroadcastQueue;
        mBroadcastQueues[3] = mFgOffloadBroadcastQueue;
        mServices = new ActiveServices(this);
        mCpHelper = new ContentProviderHelper(this, true);
@@ -12552,13 +12565,15 @@ public class ActivityManagerService extends IActivityManager.Stub
    boolean isPendingBroadcastProcessLocked(int pid) {
        return mFgBroadcastQueue.isPendingBroadcastProcessLocked(pid)
                || mBgBroadcastQueue.isPendingBroadcastProcessLocked(pid)
                || mOffloadBroadcastQueue.isPendingBroadcastProcessLocked(pid);
                || mBgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(pid)
                || mFgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(pid);
    }
    boolean isPendingBroadcastProcessLocked(ProcessRecord app) {
        return mFgBroadcastQueue.isPendingBroadcastProcessLocked(app)
                || mBgBroadcastQueue.isPendingBroadcastProcessLocked(app)
                || mOffloadBroadcastQueue.isPendingBroadcastProcessLocked(app);
                || mBgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(app)
                || mFgOffloadBroadcastQueue.isPendingBroadcastProcessLocked(app);
    }
    void skipPendingBroadcastLocked(int pid) {
@@ -14007,8 +14022,10 @@ public class ActivityManagerService extends IActivityManager.Stub
            BroadcastQueue queue;
            synchronized(this) {
                if (isOnOffloadQueue(flags)) {
                    queue = mOffloadBroadcastQueue;
                if (isOnFgOffloadQueue(flags)) {
                    queue = mFgOffloadBroadcastQueue;
                } else if (isOnBgOffloadQueue(flags)) {
                    queue = mBgOffloadBroadcastQueue;
                } else {
                    queue = (flags & Intent.FLAG_RECEIVER_FOREGROUND) != 0
                            ? mFgBroadcastQueue : mBgBroadcastQueue;
@@ -16302,7 +16319,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                        Binder.getCallingUid(), Binder.getCallingPid(), UserHandle.USER_ALL);
                if ((changes & ActivityInfo.CONFIG_LOCALE) != 0) {
                    intent = new Intent(Intent.ACTION_LOCALE_CHANGED);
                    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND
                    intent.addFlags(Intent.FLAG_RECEIVER_OFFLOAD_FOREGROUND
                            | Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND
                            | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
                    if (initLocale || !mProcessesReady) {
@@ -17479,7 +17496,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    private boolean isOnOffloadQueue(int flags) {
    private boolean isOnFgOffloadQueue(int flags) {
        return ((flags & Intent.FLAG_RECEIVER_OFFLOAD_FOREGROUND) != 0);
    }
    private boolean isOnBgOffloadQueue(int flags) {
        return (mEnableOffloadQueue && ((flags & Intent.FLAG_RECEIVER_OFFLOAD) != 0));
    }