diff options
| author | 2021-11-19 14:01:11 +0000 | |
|---|---|---|
| committer | 2021-11-19 14:01:11 +0000 | |
| commit | a1749585d37a50ddd49443d0a39d3b3bb08509d3 (patch) | |
| tree | 3eb418448abe7b40366680a1758cc196fc1bb328 | |
| parent | 451fd9a68c307e13b33263982370fb2fd8ecae22 (diff) | |
| parent | dafeebda80497cdd03cc51c16a91c08ef0aa0adc (diff) | |
Merge "Shift execution of Intent.ACTION_LOCALE_CHANGED broadcast to a new broadcast queue dedicated to offload foreground broadcast queue"
| -rw-r--r-- | core/java/android/content/Intent.java | 10 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 51 |
2 files changed, 46 insertions, 15 deletions
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index 3c9b1f81da8a..a3efbd771fad 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -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 {} @@ -6914,6 +6916,14 @@ public class Intent implements Parcelable, Cloneable { */ 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 * later receivers from seeing the broadcast. diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index ded115bbbcb4..1fe4d1405dca 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -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)); } |