Loading services/core/java/com/android/server/am/ActivityManagerService.java +0 −6 Original line number Diff line number Diff line Loading @@ -20315,12 +20315,6 @@ public class ActivityManagerService extends IActivityManager.Stub Settings.Global.BROADCAST_BG_CONSTANTS); backConstants.TIMEOUT = BROADCAST_BG_TIMEOUT; final BroadcastConstants offloadConstants = new BroadcastConstants( Settings.Global.BROADCAST_OFFLOAD_CONSTANTS); offloadConstants.TIMEOUT = BROADCAST_BG_TIMEOUT; // by default, no "slow" policy in this queue offloadConstants.SLOW_TIME = Integer.MAX_VALUE; return new BroadcastQueueModernImpl(service, service.mHandler, foreConstants, backConstants); } services/core/java/com/android/server/am/BroadcastConstants.java +3 −29 Original line number Diff line number Diff line Loading @@ -53,19 +53,11 @@ public class BroadcastConstants { // Value element names within the Settings record static final String KEY_TIMEOUT = "bcast_timeout"; static final String KEY_SLOW_TIME = "bcast_slow_time"; static final String KEY_DEFERRAL = "bcast_deferral"; static final String KEY_DEFERRAL_DECAY_FACTOR = "bcast_deferral_decay_factor"; static final String KEY_DEFERRAL_FLOOR = "bcast_deferral_floor"; static final String KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT = "bcast_allow_bg_activity_start_timeout"; // All time intervals are in milliseconds private static final long DEFAULT_TIMEOUT = 10_000 * Build.HW_TIMEOUT_MULTIPLIER; private static final long DEFAULT_SLOW_TIME = 5_000 * Build.HW_TIMEOUT_MULTIPLIER; private static final long DEFAULT_DEFERRAL = 5_000 * Build.HW_TIMEOUT_MULTIPLIER; private static final float DEFAULT_DEFERRAL_DECAY_FACTOR = 0.75f; private static final long DEFAULT_DEFERRAL_FLOOR = 0; private static final long DEFAULT_ALLOW_BG_ACTIVITY_START_TIMEOUT = 10_000 * Build.HW_TIMEOUT_MULTIPLIER; Loading Loading @@ -114,15 +106,6 @@ public class BroadcastConstants { // Timeout period for this broadcast queue public long TIMEOUT = DEFAULT_TIMEOUT; // Handling time above which we declare that a broadcast recipient was "slow". Any // value <= zero is interpreted as disabling broadcast deferral policy entirely. public long SLOW_TIME = DEFAULT_SLOW_TIME; // How long to initially defer broadcasts, if an app is slow to handle one public long DEFERRAL = DEFAULT_DEFERRAL; // Decay factor for successive broadcasts' deferral time public float DEFERRAL_DECAY_FACTOR = DEFAULT_DEFERRAL_DECAY_FACTOR; // Minimum that the deferral time can decay to until the backlog fully clears public long DEFERRAL_FLOOR = DEFAULT_DEFERRAL_FLOOR; // For a receiver that has been allowed to start background activities, how long after it // started its process can start a background activity. public long ALLOW_BG_ACTIVITY_START_TIMEOUT = DEFAULT_ALLOW_BG_ACTIVITY_START_TIMEOUT; Loading Loading @@ -278,7 +261,7 @@ public class BroadcastConstants { /** * For {@link BroadcastRecord}: Default to treating all broadcasts sent by * the system as be {@link BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE}. * the system as be {@link android.app.BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE}. */ public boolean CORE_DEFER_UNTIL_ACTIVE = DEFAULT_CORE_DEFER_UNTIL_ACTIVE; private static final String KEY_CORE_DEFER_UNTIL_ACTIVE = "bcast_core_defer_until_active"; Loading Loading @@ -361,18 +344,13 @@ public class BroadcastConstants { // Unspecified fields retain their current value rather than revert to default TIMEOUT = mParser.getLong(KEY_TIMEOUT, TIMEOUT); SLOW_TIME = mParser.getLong(KEY_SLOW_TIME, SLOW_TIME); DEFERRAL = mParser.getLong(KEY_DEFERRAL, DEFERRAL); DEFERRAL_DECAY_FACTOR = mParser.getFloat(KEY_DEFERRAL_DECAY_FACTOR, DEFERRAL_DECAY_FACTOR); DEFERRAL_FLOOR = mParser.getLong(KEY_DEFERRAL_FLOOR, DEFERRAL_FLOOR); ALLOW_BG_ACTIVITY_START_TIMEOUT = mParser.getLong(KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT, ALLOW_BG_ACTIVITY_START_TIMEOUT); } } /** * Return the {@link SystemProperty} name for the given key in our * Return the {@link SystemProperties} name for the given key in our * {@link DeviceConfig} namespace. */ private static @NonNull String propertyFor(@NonNull String key) { Loading @@ -380,7 +358,7 @@ public class BroadcastConstants { } /** * Return the {@link SystemProperty} name for the given key in our * Return the {@link SystemProperties} name for the given key in our * {@link DeviceConfig} namespace, but with a different prefix that can be * used to locally override the {@link DeviceConfig} value. */ Loading Loading @@ -475,10 +453,6 @@ public class BroadcastConstants { pw.println("):"); pw.increaseIndent(); pw.print(KEY_TIMEOUT, TimeUtils.formatDuration(TIMEOUT)).println(); pw.print(KEY_SLOW_TIME, TimeUtils.formatDuration(SLOW_TIME)).println(); pw.print(KEY_DEFERRAL, TimeUtils.formatDuration(DEFERRAL)).println(); pw.print(KEY_DEFERRAL_DECAY_FACTOR, DEFERRAL_DECAY_FACTOR).println(); pw.print(KEY_DEFERRAL_FLOOR, DEFERRAL_FLOOR).println(); pw.print(KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT, TimeUtils.formatDuration(ALLOW_BG_ACTIVITY_START_TIMEOUT)).println(); pw.decreaseIndent(); Loading services/core/java/com/android/server/am/BroadcastQueue.java +0 −8 Original line number Diff line number Diff line Loading @@ -75,12 +75,6 @@ public abstract class BroadcastQueue { } } static void checkStateWtf(boolean expression, @NonNull String msg) { if (!expression) { Slog.wtf(TAG, new IllegalStateException(msg)); } } static int traceBegin(@NonNull String methodName) { final int cookie = methodName.hashCode(); Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, Loading @@ -100,8 +94,6 @@ public abstract class BroadcastQueue { public abstract void start(@NonNull ContentResolver resolver); public abstract boolean isDelayBehindServices(); /** * Return the preferred scheduling group for the given process, typically * influenced by a broadcast being actively dispatched. Loading services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +0 −7 Original line number Diff line number Diff line Loading @@ -1893,13 +1893,6 @@ class BroadcastQueueModernImpl extends BroadcastQueue { return getRunningSize() + " running"; } @Override public boolean isDelayBehindServices() { // Modern queue does not alter the broadcasts delivery behavior based on background // services, so ignore. return false; } @GuardedBy("mService") @Override public void backgroundServicesFinishedLocked(int userId) { Loading services/core/java/com/android/server/am/BroadcastRecord.java +1 −148 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.am; import static android.app.ActivityManager.RESTRICTION_LEVEL_BACKGROUND_RESTRICTED; import static android.app.AppProtoEnums.BROADCAST_TYPE_ALARM; import static android.app.AppProtoEnums.BROADCAST_TYPE_BACKGROUND; import static android.app.AppProtoEnums.BROADCAST_TYPE_DEFERRABLE_UNTIL_ACTIVE; Loading @@ -31,12 +30,6 @@ import static android.app.AppProtoEnums.BROADCAST_TYPE_PUSH_MESSAGE_OVER_QUOTA; import static android.app.AppProtoEnums.BROADCAST_TYPE_RESULT_TO; import static android.app.AppProtoEnums.BROADCAST_TYPE_STICKY; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_ALL; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_CHANGE_ID; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_NONE; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY; import android.annotation.CheckResult; import android.annotation.CurrentTimeMillisLong; import android.annotation.ElapsedRealtimeLong; Loading @@ -45,12 +38,10 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UptimeMillisLong; import android.app.ActivityManager.ProcessState; import android.app.ActivityManagerInternal; import android.app.AppOpsManager; import android.app.BackgroundStartPrivileges; import android.app.BroadcastOptions; import android.app.BroadcastOptions.DeliveryGroupPolicy; import android.app.compat.CompatChanges; import android.content.ComponentName; import android.content.IIntentReceiver; import android.content.Intent; Loading @@ -63,7 +54,6 @@ import android.os.SystemClock; import android.os.UserHandle; import android.util.ArrayMap; import android.util.PrintWriterPrinter; import android.util.SparseArray; import android.util.TimeUtils; import android.util.proto.ProtoOutputStream; Loading @@ -75,13 +65,11 @@ import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; /** Loading Loading @@ -125,9 +113,6 @@ final class BroadcastRecord extends Binder { final int[] blockedUntilBeyondCount; // blocked until count of each receiver @Nullable ProcessRecord resultToApp; // who receives final result if non-null @Nullable IIntentReceiver resultTo; // who receives final result if non-null boolean deferred; int splitCount; // refcount for result callback, when split int splitToken; // identifier for cross-BroadcastRecord refcount @UptimeMillisLong long enqueueTime; // when broadcast enqueued @ElapsedRealtimeLong long enqueueRealTime; // when broadcast enqueued @CurrentTimeMillisLong long enqueueClockTime; // when broadcast enqueued Loading Loading @@ -276,15 +261,6 @@ final class BroadcastRecord extends Binder { BroadcastFilter curFilter; // the registered receiver currently running. Bundle curFilteredExtras; // the bundle that has been filtered by the package visibility rules int curAppLastProcessState; // The last process state of the current receiver before receiving boolean mIsReceiverAppRunning; // Was the receiver's app already running. boolean mWasReceiverAppStopped; // Was the receiver app stopped prior to starting // Private refcount-management bookkeeping; start > 0 static AtomicInteger sNextToken = new AtomicInteger(1); @NeverCompile void dump(PrintWriter pw, String prefix, SimpleDateFormat sdf) { final long now = SystemClock.uptimeMillis(); Loading Loading @@ -581,129 +557,6 @@ final class BroadcastRecord extends Binder { originalStickyCallingUid = from.originalStickyCallingUid; } /** * Split off a new BroadcastRecord that clones this one, but contains only the * recipient records for the current (just-finished) receiver's app, starting * after the just-finished receiver [i.e. at r.nextReceiver]. Returns null * if there are no matching subsequent receivers in this BroadcastRecord. */ BroadcastRecord splitRecipientsLocked(int slowAppUid, int startingAt) { // Do we actually have any matching receivers down the line...? ArrayList splitReceivers = null; for (int i = startingAt; i < receivers.size(); ) { Object o = receivers.get(i); if (getReceiverUid(o) == slowAppUid) { if (splitReceivers == null) { splitReceivers = new ArrayList<>(); } splitReceivers.add(o); receivers.remove(i); } else { i++; } } // No later receivers in the same app, so we have no more to do if (splitReceivers == null) { return null; } // build a new BroadcastRecord around that single-target list BroadcastRecord split = new BroadcastRecord(queue, intent, callerApp, callerPackage, callerFeatureId, callingPid, callingUid, callerInstantApp, resolvedType, requiredPermissions, excludedPermissions, excludedPackages, appOp, options, splitReceivers, resultToApp, resultTo, resultCode, resultData, resultExtras, ordered, sticky, initialSticky, userId, mBackgroundStartPrivileges, timeoutExempt, filterExtrasForReceiver, callerProcState); split.enqueueTime = this.enqueueTime; split.enqueueRealTime = this.enqueueRealTime; split.enqueueClockTime = this.enqueueClockTime; split.splitToken = this.splitToken; return split; } /** * Split a BroadcastRecord to a map of deferred receiver UID to deferred BroadcastRecord. * * The receivers that are deferred are removed from original BroadcastRecord's receivers list. * The receivers that are not deferred are kept in original BroadcastRecord's receivers list. * * Only used to split LOCKED_BOOT_COMPLETED or BOOT_COMPLETED BroadcastRecord. * LOCKED_BOOT_COMPLETED or BOOT_COMPLETED broadcast can be deferred until the first time * the receiver's UID has a process started. * * @param ams The ActivityManagerService object. * @param deferType Defer what UID? * @return the deferred UID to BroadcastRecord map, the BroadcastRecord has the list of * receivers in that UID. */ @NonNull SparseArray<BroadcastRecord> splitDeferredBootCompletedBroadcastLocked( ActivityManagerInternal activityManagerInternal, @BroadcastConstants.DeferBootCompletedBroadcastType int deferType) { final SparseArray<BroadcastRecord> ret = new SparseArray<>(); if (deferType == DEFER_BOOT_COMPLETED_BROADCAST_NONE) { return ret; } if (receivers == null) { return ret; } final String action = intent.getAction(); if (!Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(action) && !Intent.ACTION_BOOT_COMPLETED.equals(action)) { return ret; } final SparseArray<List<Object>> uid2receiverList = new SparseArray<>(); for (int i = receivers.size() - 1; i >= 0; i--) { final Object receiver = receivers.get(i); final int uid = getReceiverUid(receiver); if (deferType != DEFER_BOOT_COMPLETED_BROADCAST_ALL) { if ((deferType & DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY) != 0) { if (activityManagerInternal.getRestrictionLevel(uid) < RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) { // skip if the UID is not background restricted. continue; } } if ((deferType & DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY) != 0) { if (!CompatChanges.isChangeEnabled(DEFER_BOOT_COMPLETED_BROADCAST_CHANGE_ID, uid)) { // skip if the UID is not targetSdkVersion T+. continue; } } } // Remove receiver from original BroadcastRecord's receivers list. receivers.remove(i); final List<Object> receiverList = uid2receiverList.get(uid); if (receiverList != null) { receiverList.add(0, receiver); } else { ArrayList<Object> splitReceivers = new ArrayList<>(); splitReceivers.add(0, receiver); uid2receiverList.put(uid, splitReceivers); } } final int uidSize = uid2receiverList.size(); for (int i = 0; i < uidSize; i++) { final BroadcastRecord br = new BroadcastRecord(queue, intent, callerApp, callerPackage, callerFeatureId, callingPid, callingUid, callerInstantApp, resolvedType, requiredPermissions, excludedPermissions, excludedPackages, appOp, options, uid2receiverList.valueAt(i), null /* _resultToApp */, null /* _resultTo */, resultCode, resultData, resultExtras, ordered, sticky, initialSticky, userId, mBackgroundStartPrivileges, timeoutExempt, filterExtrasForReceiver, callerProcState); br.enqueueTime = this.enqueueTime; br.enqueueRealTime = this.enqueueRealTime; br.enqueueClockTime = this.enqueueClockTime; ret.put(uid2receiverList.keyAt(i), br); } return ret; } /** * Update the delivery state of the given {@link #receivers} index. * Automatically updates any time measurements related to state changes. Loading Loading @@ -876,7 +729,7 @@ final class BroadcastRecord extends Binder { } /** * Determine if the result of {@link #calculateBlockedUntilTerminalCount} * Determine if the result of {@link #calculateBlockedUntilBeyondCount(List, boolean)} * has prioritized tranches of receivers. */ @VisibleForTesting Loading Loading
services/core/java/com/android/server/am/ActivityManagerService.java +0 −6 Original line number Diff line number Diff line Loading @@ -20315,12 +20315,6 @@ public class ActivityManagerService extends IActivityManager.Stub Settings.Global.BROADCAST_BG_CONSTANTS); backConstants.TIMEOUT = BROADCAST_BG_TIMEOUT; final BroadcastConstants offloadConstants = new BroadcastConstants( Settings.Global.BROADCAST_OFFLOAD_CONSTANTS); offloadConstants.TIMEOUT = BROADCAST_BG_TIMEOUT; // by default, no "slow" policy in this queue offloadConstants.SLOW_TIME = Integer.MAX_VALUE; return new BroadcastQueueModernImpl(service, service.mHandler, foreConstants, backConstants); }
services/core/java/com/android/server/am/BroadcastConstants.java +3 −29 Original line number Diff line number Diff line Loading @@ -53,19 +53,11 @@ public class BroadcastConstants { // Value element names within the Settings record static final String KEY_TIMEOUT = "bcast_timeout"; static final String KEY_SLOW_TIME = "bcast_slow_time"; static final String KEY_DEFERRAL = "bcast_deferral"; static final String KEY_DEFERRAL_DECAY_FACTOR = "bcast_deferral_decay_factor"; static final String KEY_DEFERRAL_FLOOR = "bcast_deferral_floor"; static final String KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT = "bcast_allow_bg_activity_start_timeout"; // All time intervals are in milliseconds private static final long DEFAULT_TIMEOUT = 10_000 * Build.HW_TIMEOUT_MULTIPLIER; private static final long DEFAULT_SLOW_TIME = 5_000 * Build.HW_TIMEOUT_MULTIPLIER; private static final long DEFAULT_DEFERRAL = 5_000 * Build.HW_TIMEOUT_MULTIPLIER; private static final float DEFAULT_DEFERRAL_DECAY_FACTOR = 0.75f; private static final long DEFAULT_DEFERRAL_FLOOR = 0; private static final long DEFAULT_ALLOW_BG_ACTIVITY_START_TIMEOUT = 10_000 * Build.HW_TIMEOUT_MULTIPLIER; Loading Loading @@ -114,15 +106,6 @@ public class BroadcastConstants { // Timeout period for this broadcast queue public long TIMEOUT = DEFAULT_TIMEOUT; // Handling time above which we declare that a broadcast recipient was "slow". Any // value <= zero is interpreted as disabling broadcast deferral policy entirely. public long SLOW_TIME = DEFAULT_SLOW_TIME; // How long to initially defer broadcasts, if an app is slow to handle one public long DEFERRAL = DEFAULT_DEFERRAL; // Decay factor for successive broadcasts' deferral time public float DEFERRAL_DECAY_FACTOR = DEFAULT_DEFERRAL_DECAY_FACTOR; // Minimum that the deferral time can decay to until the backlog fully clears public long DEFERRAL_FLOOR = DEFAULT_DEFERRAL_FLOOR; // For a receiver that has been allowed to start background activities, how long after it // started its process can start a background activity. public long ALLOW_BG_ACTIVITY_START_TIMEOUT = DEFAULT_ALLOW_BG_ACTIVITY_START_TIMEOUT; Loading Loading @@ -278,7 +261,7 @@ public class BroadcastConstants { /** * For {@link BroadcastRecord}: Default to treating all broadcasts sent by * the system as be {@link BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE}. * the system as be {@link android.app.BroadcastOptions#DEFERRAL_POLICY_UNTIL_ACTIVE}. */ public boolean CORE_DEFER_UNTIL_ACTIVE = DEFAULT_CORE_DEFER_UNTIL_ACTIVE; private static final String KEY_CORE_DEFER_UNTIL_ACTIVE = "bcast_core_defer_until_active"; Loading Loading @@ -361,18 +344,13 @@ public class BroadcastConstants { // Unspecified fields retain their current value rather than revert to default TIMEOUT = mParser.getLong(KEY_TIMEOUT, TIMEOUT); SLOW_TIME = mParser.getLong(KEY_SLOW_TIME, SLOW_TIME); DEFERRAL = mParser.getLong(KEY_DEFERRAL, DEFERRAL); DEFERRAL_DECAY_FACTOR = mParser.getFloat(KEY_DEFERRAL_DECAY_FACTOR, DEFERRAL_DECAY_FACTOR); DEFERRAL_FLOOR = mParser.getLong(KEY_DEFERRAL_FLOOR, DEFERRAL_FLOOR); ALLOW_BG_ACTIVITY_START_TIMEOUT = mParser.getLong(KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT, ALLOW_BG_ACTIVITY_START_TIMEOUT); } } /** * Return the {@link SystemProperty} name for the given key in our * Return the {@link SystemProperties} name for the given key in our * {@link DeviceConfig} namespace. */ private static @NonNull String propertyFor(@NonNull String key) { Loading @@ -380,7 +358,7 @@ public class BroadcastConstants { } /** * Return the {@link SystemProperty} name for the given key in our * Return the {@link SystemProperties} name for the given key in our * {@link DeviceConfig} namespace, but with a different prefix that can be * used to locally override the {@link DeviceConfig} value. */ Loading Loading @@ -475,10 +453,6 @@ public class BroadcastConstants { pw.println("):"); pw.increaseIndent(); pw.print(KEY_TIMEOUT, TimeUtils.formatDuration(TIMEOUT)).println(); pw.print(KEY_SLOW_TIME, TimeUtils.formatDuration(SLOW_TIME)).println(); pw.print(KEY_DEFERRAL, TimeUtils.formatDuration(DEFERRAL)).println(); pw.print(KEY_DEFERRAL_DECAY_FACTOR, DEFERRAL_DECAY_FACTOR).println(); pw.print(KEY_DEFERRAL_FLOOR, DEFERRAL_FLOOR).println(); pw.print(KEY_ALLOW_BG_ACTIVITY_START_TIMEOUT, TimeUtils.formatDuration(ALLOW_BG_ACTIVITY_START_TIMEOUT)).println(); pw.decreaseIndent(); Loading
services/core/java/com/android/server/am/BroadcastQueue.java +0 −8 Original line number Diff line number Diff line Loading @@ -75,12 +75,6 @@ public abstract class BroadcastQueue { } } static void checkStateWtf(boolean expression, @NonNull String msg) { if (!expression) { Slog.wtf(TAG, new IllegalStateException(msg)); } } static int traceBegin(@NonNull String methodName) { final int cookie = methodName.hashCode(); Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, Loading @@ -100,8 +94,6 @@ public abstract class BroadcastQueue { public abstract void start(@NonNull ContentResolver resolver); public abstract boolean isDelayBehindServices(); /** * Return the preferred scheduling group for the given process, typically * influenced by a broadcast being actively dispatched. Loading
services/core/java/com/android/server/am/BroadcastQueueModernImpl.java +0 −7 Original line number Diff line number Diff line Loading @@ -1893,13 +1893,6 @@ class BroadcastQueueModernImpl extends BroadcastQueue { return getRunningSize() + " running"; } @Override public boolean isDelayBehindServices() { // Modern queue does not alter the broadcasts delivery behavior based on background // services, so ignore. return false; } @GuardedBy("mService") @Override public void backgroundServicesFinishedLocked(int userId) { Loading
services/core/java/com/android/server/am/BroadcastRecord.java +1 −148 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.server.am; import static android.app.ActivityManager.RESTRICTION_LEVEL_BACKGROUND_RESTRICTED; import static android.app.AppProtoEnums.BROADCAST_TYPE_ALARM; import static android.app.AppProtoEnums.BROADCAST_TYPE_BACKGROUND; import static android.app.AppProtoEnums.BROADCAST_TYPE_DEFERRABLE_UNTIL_ACTIVE; Loading @@ -31,12 +30,6 @@ import static android.app.AppProtoEnums.BROADCAST_TYPE_PUSH_MESSAGE_OVER_QUOTA; import static android.app.AppProtoEnums.BROADCAST_TYPE_RESULT_TO; import static android.app.AppProtoEnums.BROADCAST_TYPE_STICKY; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_ALL; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_CHANGE_ID; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_NONE; import static com.android.server.am.BroadcastConstants.DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY; import android.annotation.CheckResult; import android.annotation.CurrentTimeMillisLong; import android.annotation.ElapsedRealtimeLong; Loading @@ -45,12 +38,10 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UptimeMillisLong; import android.app.ActivityManager.ProcessState; import android.app.ActivityManagerInternal; import android.app.AppOpsManager; import android.app.BackgroundStartPrivileges; import android.app.BroadcastOptions; import android.app.BroadcastOptions.DeliveryGroupPolicy; import android.app.compat.CompatChanges; import android.content.ComponentName; import android.content.IIntentReceiver; import android.content.Intent; Loading @@ -63,7 +54,6 @@ import android.os.SystemClock; import android.os.UserHandle; import android.util.ArrayMap; import android.util.PrintWriterPrinter; import android.util.SparseArray; import android.util.TimeUtils; import android.util.proto.ProtoOutputStream; Loading @@ -75,13 +65,11 @@ import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; /** Loading Loading @@ -125,9 +113,6 @@ final class BroadcastRecord extends Binder { final int[] blockedUntilBeyondCount; // blocked until count of each receiver @Nullable ProcessRecord resultToApp; // who receives final result if non-null @Nullable IIntentReceiver resultTo; // who receives final result if non-null boolean deferred; int splitCount; // refcount for result callback, when split int splitToken; // identifier for cross-BroadcastRecord refcount @UptimeMillisLong long enqueueTime; // when broadcast enqueued @ElapsedRealtimeLong long enqueueRealTime; // when broadcast enqueued @CurrentTimeMillisLong long enqueueClockTime; // when broadcast enqueued Loading Loading @@ -276,15 +261,6 @@ final class BroadcastRecord extends Binder { BroadcastFilter curFilter; // the registered receiver currently running. Bundle curFilteredExtras; // the bundle that has been filtered by the package visibility rules int curAppLastProcessState; // The last process state of the current receiver before receiving boolean mIsReceiverAppRunning; // Was the receiver's app already running. boolean mWasReceiverAppStopped; // Was the receiver app stopped prior to starting // Private refcount-management bookkeeping; start > 0 static AtomicInteger sNextToken = new AtomicInteger(1); @NeverCompile void dump(PrintWriter pw, String prefix, SimpleDateFormat sdf) { final long now = SystemClock.uptimeMillis(); Loading Loading @@ -581,129 +557,6 @@ final class BroadcastRecord extends Binder { originalStickyCallingUid = from.originalStickyCallingUid; } /** * Split off a new BroadcastRecord that clones this one, but contains only the * recipient records for the current (just-finished) receiver's app, starting * after the just-finished receiver [i.e. at r.nextReceiver]. Returns null * if there are no matching subsequent receivers in this BroadcastRecord. */ BroadcastRecord splitRecipientsLocked(int slowAppUid, int startingAt) { // Do we actually have any matching receivers down the line...? ArrayList splitReceivers = null; for (int i = startingAt; i < receivers.size(); ) { Object o = receivers.get(i); if (getReceiverUid(o) == slowAppUid) { if (splitReceivers == null) { splitReceivers = new ArrayList<>(); } splitReceivers.add(o); receivers.remove(i); } else { i++; } } // No later receivers in the same app, so we have no more to do if (splitReceivers == null) { return null; } // build a new BroadcastRecord around that single-target list BroadcastRecord split = new BroadcastRecord(queue, intent, callerApp, callerPackage, callerFeatureId, callingPid, callingUid, callerInstantApp, resolvedType, requiredPermissions, excludedPermissions, excludedPackages, appOp, options, splitReceivers, resultToApp, resultTo, resultCode, resultData, resultExtras, ordered, sticky, initialSticky, userId, mBackgroundStartPrivileges, timeoutExempt, filterExtrasForReceiver, callerProcState); split.enqueueTime = this.enqueueTime; split.enqueueRealTime = this.enqueueRealTime; split.enqueueClockTime = this.enqueueClockTime; split.splitToken = this.splitToken; return split; } /** * Split a BroadcastRecord to a map of deferred receiver UID to deferred BroadcastRecord. * * The receivers that are deferred are removed from original BroadcastRecord's receivers list. * The receivers that are not deferred are kept in original BroadcastRecord's receivers list. * * Only used to split LOCKED_BOOT_COMPLETED or BOOT_COMPLETED BroadcastRecord. * LOCKED_BOOT_COMPLETED or BOOT_COMPLETED broadcast can be deferred until the first time * the receiver's UID has a process started. * * @param ams The ActivityManagerService object. * @param deferType Defer what UID? * @return the deferred UID to BroadcastRecord map, the BroadcastRecord has the list of * receivers in that UID. */ @NonNull SparseArray<BroadcastRecord> splitDeferredBootCompletedBroadcastLocked( ActivityManagerInternal activityManagerInternal, @BroadcastConstants.DeferBootCompletedBroadcastType int deferType) { final SparseArray<BroadcastRecord> ret = new SparseArray<>(); if (deferType == DEFER_BOOT_COMPLETED_BROADCAST_NONE) { return ret; } if (receivers == null) { return ret; } final String action = intent.getAction(); if (!Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(action) && !Intent.ACTION_BOOT_COMPLETED.equals(action)) { return ret; } final SparseArray<List<Object>> uid2receiverList = new SparseArray<>(); for (int i = receivers.size() - 1; i >= 0; i--) { final Object receiver = receivers.get(i); final int uid = getReceiverUid(receiver); if (deferType != DEFER_BOOT_COMPLETED_BROADCAST_ALL) { if ((deferType & DEFER_BOOT_COMPLETED_BROADCAST_BACKGROUND_RESTRICTED_ONLY) != 0) { if (activityManagerInternal.getRestrictionLevel(uid) < RESTRICTION_LEVEL_BACKGROUND_RESTRICTED) { // skip if the UID is not background restricted. continue; } } if ((deferType & DEFER_BOOT_COMPLETED_BROADCAST_TARGET_T_ONLY) != 0) { if (!CompatChanges.isChangeEnabled(DEFER_BOOT_COMPLETED_BROADCAST_CHANGE_ID, uid)) { // skip if the UID is not targetSdkVersion T+. continue; } } } // Remove receiver from original BroadcastRecord's receivers list. receivers.remove(i); final List<Object> receiverList = uid2receiverList.get(uid); if (receiverList != null) { receiverList.add(0, receiver); } else { ArrayList<Object> splitReceivers = new ArrayList<>(); splitReceivers.add(0, receiver); uid2receiverList.put(uid, splitReceivers); } } final int uidSize = uid2receiverList.size(); for (int i = 0; i < uidSize; i++) { final BroadcastRecord br = new BroadcastRecord(queue, intent, callerApp, callerPackage, callerFeatureId, callingPid, callingUid, callerInstantApp, resolvedType, requiredPermissions, excludedPermissions, excludedPackages, appOp, options, uid2receiverList.valueAt(i), null /* _resultToApp */, null /* _resultTo */, resultCode, resultData, resultExtras, ordered, sticky, initialSticky, userId, mBackgroundStartPrivileges, timeoutExempt, filterExtrasForReceiver, callerProcState); br.enqueueTime = this.enqueueTime; br.enqueueRealTime = this.enqueueRealTime; br.enqueueClockTime = this.enqueueClockTime; ret.put(uid2receiverList.keyAt(i), br); } return ret; } /** * Update the delivery state of the given {@link #receivers} index. * Automatically updates any time measurements related to state changes. Loading Loading @@ -876,7 +729,7 @@ final class BroadcastRecord extends Binder { } /** * Determine if the result of {@link #calculateBlockedUntilTerminalCount} * Determine if the result of {@link #calculateBlockedUntilBeyondCount(List, boolean)} * has prioritized tranches of receivers. */ @VisibleForTesting Loading