Loading services/core/java/com/android/server/am/ConnectionRecord.java +9 −2 Original line number Diff line number Diff line Loading @@ -161,8 +161,15 @@ final class ConnectionRecord implements OomAdjusterImpl.Connection{ } @Override public boolean transmitsCpuTime() { return !hasFlag(Context.BIND_ALLOW_FREEZE) || mOngoingCalls; public int cpuTimeTransmissionType() { if (mOngoingCalls) { return CPU_TIME_TRANSMISSION_NORMAL; } if (hasFlag(Context.BIND_ALLOW_FREEZE)) { return CPU_TIME_TRANSMISSION_NONE; } return hasFlag(Context.BIND_SIMULATE_ALLOW_FREEZE) ? CPU_TIME_TRANSMISSION_LEGACY : CPU_TIME_TRANSMISSION_NORMAL; } public long getFlags() { Loading services/core/java/com/android/server/am/OomAdjuster.java +141 −22 Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ import static com.android.server.am.ActivityManagerService.TAG_LRU; import static com.android.server.am.ActivityManagerService.TAG_OOM_ADJ; import static com.android.server.am.ActivityManagerService.TAG_UID_OBSERVERS; import static com.android.server.am.AppProfiler.TAG_PSS; import static com.android.server.am.OomAdjusterImpl.Connection.CPU_TIME_TRANSMISSION_LEGACY; import static com.android.server.am.OomAdjusterImpl.Connection.CPU_TIME_TRANSMISSION_NONE; import static com.android.server.am.ProcessList.CACHED_APP_IMPORTANCE_LEVELS; import static com.android.server.am.ProcessList.CACHED_APP_MAX_ADJ; import static com.android.server.am.ProcessList.CACHED_APP_MIN_ADJ; Loading Loading @@ -113,6 +115,7 @@ import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_ import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_IS_VISIBLE; import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; Loading Loading @@ -154,6 +157,8 @@ import com.android.server.am.psc.UidRecordInternal; import com.android.server.wm.WindowProcessController; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; Loading @@ -165,6 +170,66 @@ import java.util.List; public abstract class OomAdjuster { static final String TAG = "OomAdjuster"; /** To be used when the process does not have PROCESS_CAPABILITY_CPU_TIME. */ public static final int CPU_TIME_REASON_NONE = 0; /** The process has PROCESS_CAPABILITY_CPU_TIME, but the reason is not interesting for logs. */ public static final int CPU_TIME_REASON_OTHER = 0x1; /** * The process has PROCESS_CAPABILITY_CPU_TIME because it was transmitted over a connection * from a client. This is interesting because this reason will cease to exist if all the * responsible bindings started using {@link Context#BIND_ALLOW_FREEZE}. */ public static final int CPU_TIME_REASON_TRANSMITTED = 0x2; /** * The process has PROCESS_CAPABILITY_CPU_TIME because it was transmitted over a connection * from a client transitively only because of {@link Context#BIND_SIMULATE_ALLOW_FREEZE}. * This indicates that this reason will soon go away and in absence of other reasons, the app * will not have PROCESS_CAPABILITY_CPU_TIME. */ public static final int CPU_TIME_REASON_TRANSMITTED_LEGACY = 0x4; @IntDef(flag = true, prefix = "CPU_TIME_REASON_", value = { CPU_TIME_REASON_NONE, CPU_TIME_REASON_OTHER, CPU_TIME_REASON_TRANSMITTED, CPU_TIME_REASON_TRANSMITTED_LEGACY, }) @Retention(RetentionPolicy.SOURCE) public @interface CpuTimeReasons { } /** To be used when the process does not have PROCESS_CAPABILITY_IMPLICIT_CPU_TIME. */ public static final int IMPLICIT_CPU_TIME_REASON_NONE = 0; /** * The process has PROCESS_CAPABILITY_IMPLICIT_CPU_TIME, but the reason is not interesting for * logs. */ public static final int IMPLICIT_CPU_TIME_REASON_OTHER = 0x1; /** * The process has PROCESS_CAPABILITY_IMPLICIT_CPU_TIME because it was transmitted over a * connection from a client. This is interesting because this reason will cease to exist if all * the responsible bindings started using {@link Context#BIND_ALLOW_FREEZE}. */ public static final int IMPLICIT_CPU_TIME_REASON_TRANSMITTED = 0x2; /** * The process has PROCESS_CAPABILITY_IMPLICIT_CPU_TIME because it was transmitted over a * connection from a client transitively only because of * {@link Context#BIND_SIMULATE_ALLOW_FREEZE}. * This indicates that this reason will soon go away and in absence of other reasons, the app * will not have PROCESS_CAPABILITY_IMPLICIT_CPU_TIME. */ public static final int IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY = 0x4; @IntDef(flag = true, prefix = "IMPLICIT_CPU_TIME_REASON_", value = { IMPLICIT_CPU_TIME_REASON_NONE, IMPLICIT_CPU_TIME_REASON_OTHER, IMPLICIT_CPU_TIME_REASON_TRANSMITTED, IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY, }) @Retention(RetentionPolicy.SOURCE) public @interface ImplicitCpuTimeReasons { } public static final int oomAdjReasonToProto(@OomAdjReason int oomReason) { switch (oomReason) { case OOM_ADJ_REASON_NONE: Loading Loading @@ -1975,44 +2040,51 @@ public abstract class OomAdjuster { return baseCapabilities | networkCapabilities; } protected static int getCpuCapability(ProcessRecord app, long nowUptime, boolean hasForegroundActivities) { // Note: persistent processes get all capabilities, including CPU_TIME. @CpuTimeReasons private static int getCpuTimeReasons(ProcessRecord app, boolean hasForegroundActivities) { // Note: persistent processes always get CPU_TIME with reason CPU_TIME_REASON_OTHER. // Currently, we only cite CPU_TIME_REASON_OTHER for all reasons. More specific reasons // can be used when they become interesting to observe. final UidRecordInternal uidRec = app.getUidRecord(); if (uidRec != null && uidRec.isCurAllowListed()) { // Process is in the power allowlist. return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (hasForegroundActivities) { // TODO: b/402987519 - This grants the Top Sleeping process CPU_TIME but eventually // should not. // Process has user perceptible activities. return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.mServices.numberOfExecutingServices() > 0) { // Ensure that services get cpu time during start-up and tear-down. return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.mServices.hasForegroundServices()) { return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.mReceivers.isReceivingBroadcast()) { return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.hasActiveInstrumentation()) { return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } // TODO(b/370817323): Populate this method with all of the reasons to keep a process // unfrozen. return 0; return CPU_TIME_REASON_NONE; } protected static int getCpuCapability(ProcessRecord app, boolean hasForegroundActivities) { final int reasons = getCpuTimeReasons(app, hasForegroundActivities); app.addCurCpuTimeReasons(reasons); return (reasons != CPU_TIME_REASON_NONE) ? PROCESS_CAPABILITY_CPU_TIME : 0; } // Grant PROCESS_CAPABILITY_IMPLICIT_CPU_TIME to processes based on oom adj score. protected int getImplicitCpuCapability(ProcessRecordInternal app, int adj) { if (adj < mConstants.FREEZER_CUTOFF_ADJ) { return PROCESS_CAPABILITY_IMPLICIT_CPU_TIME; } if (app.getMaxAdj() < mConstants.FREEZER_CUTOFF_ADJ) { if (adj < mConstants.FREEZER_CUTOFF_ADJ || app.getMaxAdj() < mConstants.FREEZER_CUTOFF_ADJ) { app.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER); return PROCESS_CAPABILITY_IMPLICIT_CPU_TIME; } return 0; Loading Loading @@ -2068,13 +2140,49 @@ public abstract class OomAdjuster { /** * @return the CPU capability from a client (of a service binding or provider). */ protected static int getCpuCapabilityFromClient(OomAdjusterImpl.Connection conn, ProcessRecordInternal client) { if (conn == null || conn.transmitsCpuTime()) { return client.getCurCapability() & ALL_CPU_TIME_CAPABILITIES; } else { protected static int getCpuCapabilitiesFromClient(ProcessRecordInternal app, ProcessRecord client, OomAdjusterImpl.Connection conn) { final int clientCpuCaps = client.getCurCapability() & ALL_CPU_TIME_CAPABILITIES; final @CpuTimeReasons int clientCpuReasons = client.getCurCpuTimeReasons(); final @ImplicitCpuTimeReasons int clientImplicitCpuReasons = client.getCurImplicitCpuTimeReasons(); final @OomAdjusterImpl.Connection.CpuTimeTransmissionType int transmissionType = (conn != null) ? conn.cpuTimeTransmissionType() : CPU_TIME_TRANSMISSION_NONE; if (transmissionType == CPU_TIME_TRANSMISSION_NONE) { // The binding does not transmit CPU_TIME capabilities in any way. return 0; } @CpuTimeReasons int cpuReasons = CPU_TIME_REASON_NONE; @ImplicitCpuTimeReasons int implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_NONE; if ((clientCpuCaps & PROCESS_CAPABILITY_CPU_TIME) != 0) { if (clientCpuReasons == CPU_TIME_REASON_TRANSMITTED_LEGACY) { // Client has CPU_TIME only for a legacy reason. cpuReasons = CPU_TIME_REASON_TRANSMITTED_LEGACY; } else if (transmissionType == CPU_TIME_TRANSMISSION_LEGACY) { // Binding only transmits CPU_TIME for a legacy reason. cpuReasons = CPU_TIME_REASON_TRANSMITTED_LEGACY; } else { cpuReasons = CPU_TIME_REASON_TRANSMITTED; } } if ((clientCpuCaps & PROCESS_CAPABILITY_IMPLICIT_CPU_TIME) != 0) { if (clientImplicitCpuReasons == IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY) { // Client has IMPLICIT_CPU_TIME only for a legacy reason. implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY; } else if (transmissionType == CPU_TIME_TRANSMISSION_LEGACY) { // Binding only transmits IMPLICIT_CPU_TIME for a legacy reason. implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY; } else { implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_TRANSMITTED; } } app.addCurCpuTimeReasons(cpuReasons); app.addCurImplicitCpuTimeReasons(implicitCpuReasons); return clientCpuCaps; } /** Inform the oomadj observer of changes to oomadj. Used by tests. */ Loading Loading @@ -2312,6 +2420,8 @@ public abstract class OomAdjuster { if (state.getCurCapability() != state.getSetCapability()) { state.setSetCapability(state.getCurCapability()); state.setSetCpuTimeReasons(state.getCurCpuTimeReasons()); state.setSetImplicitCpuTimeReasons(state.getCurImplicitCpuTimeReasons()); } final boolean curBoundByNonBgRestrictedApp = state.isCurBoundByNonBgRestrictedApp(); Loading Loading @@ -2404,6 +2514,8 @@ public abstract class OomAdjuster { state.setCurProcState(initialProcState); state.setCurRawProcState(initialProcState); state.setCurCapability(initialCapability); state.addCurCpuTimeReasons(CPU_TIME_REASON_OTHER); state.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER); state.setCurAdj(ProcessList.FOREGROUND_APP_ADJ); state.setCurRawAdj(ProcessList.FOREGROUND_APP_ADJ); Loading Loading @@ -2609,7 +2721,7 @@ public abstract class OomAdjuster { if ((proc.getCurCapability() & ALL_CPU_TIME_CAPABILITIES) != 0) { /// App is important enough (see {@link #getCpuCapability} and /// {@link #getImplicitCpuCapability}) or bound by something important enough to /// not be frozen (see {@link #getCpuCapabilityFromClient}). /// not be frozen (see {@link #getCpuCapabilitiesFromClient}). return false; } Loading Loading @@ -2670,6 +2782,8 @@ public abstract class OomAdjuster { == PROCESS_CAPABILITY_IMPLICIT_CPU_TIME; final boolean implicitCpuCapabilityChanged = hasImplicitCpuCapability != usedToHaveImplicitCpuCapability; final int cpuTimeReasons = app.getCurCpuTimeReasons(); final int implicitCpuTimeReasons = app.getCurImplicitCpuTimeReasons(); if ((oomAdjChanged || shouldNotFreezeChanged || cpuCapabilityChanged || implicitCpuCapabilityChanged) && Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { Loading @@ -2688,7 +2802,9 @@ public abstract class OomAdjuster { + "/" + app.getPid() + "/" + state.getCurAdj() + "/" + oldOomAdj + "/" + opt.shouldNotFreezeReason()); + "/" + opt.shouldNotFreezeReason() + "/" + cpuTimeReasons + "/" + implicitCpuTimeReasons); Trace.instantForTrack(Trace.TRACE_TAG_ACTIVITY_MANAGER, CachedAppOptimizer.ATRACE_FREEZER_TRACK, "updateAppFreezeStateLSP " + app.processName Loading @@ -2701,7 +2817,10 @@ public abstract class OomAdjuster { + " oldOomAdj: " + oldOomAdj + " immediate: " + immediate + " cpuCapability: " + hasCpuCapability + " implicitCpuCapability: " + hasImplicitCpuCapability); + " implicitCpuCapability: " + hasImplicitCpuCapability + " cpuTimeReasons: 0x" + Integer.toHexString(cpuTimeReasons) + " implicitCpuTimeReasons: 0x" + Integer.toHexString(implicitCpuTimeReasons)); } } Loading services/core/java/com/android/server/am/OomAdjusterImpl.java +26 −9 Original line number Diff line number Diff line Loading @@ -498,6 +498,18 @@ public class OomAdjusterImpl extends OomAdjuster { * change in importance in the host process based on the client process and connection state. */ public interface Connection { int CPU_TIME_TRANSMISSION_NONE = 0; int CPU_TIME_TRANSMISSION_NORMAL = 1; int CPU_TIME_TRANSMISSION_LEGACY = 2; @IntDef(prefix = "CPU_TIME_TRANSMISSION_", value = { CPU_TIME_TRANSMISSION_NONE, CPU_TIME_TRANSMISSION_NORMAL, CPU_TIME_TRANSMISSION_LEGACY, }) @interface CpuTimeTransmissionType { } /** * Compute the impact this connection has on the host's importance values. */ Loading @@ -510,12 +522,12 @@ public class OomAdjusterImpl extends OomAdjuster { boolean canAffectCapabilities(); /** * Returns whether this connection transmits PROCESS_CAPABILITY_CPU_TIME to the host, if the * client possesses it. * Returns the type of transmission of ALL_CPU_TIME_CAPABILITIES to the host, if the client * possesses it. */ default boolean transmitsCpuTime() { // Always lend this capability by default. return true; @CpuTimeTransmissionType default int cpuTimeTransmissionType() { return CPU_TIME_TRANSMISSION_NORMAL; } } Loading Loading @@ -1171,6 +1183,10 @@ public class OomAdjusterImpl extends OomAdjuster { long now) { final ProcessRecordInternal state = app; // We'll evaluate the reasons within getCpuCapability and getImplicitCpuCapability later. state.clearCurCpuTimeReasons(); state.clearCurImplicitCpuTimeReasons(); // Remove any follow up update this process might have. It will be rescheduled if still // needed. state.setFollowupUpdateUptimeMs(NO_FOLLOW_UP_TIME); Loading Loading @@ -1213,6 +1229,8 @@ public class OomAdjusterImpl extends OomAdjuster { state.setHasForegroundActivities(false); state.setCurrentSchedulingGroup(SCHED_GROUP_DEFAULT); state.setCurCapability(PROCESS_CAPABILITY_ALL); // BFSL allowed state.addCurCpuTimeReasons(CPU_TIME_REASON_OTHER); state.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER); state.setCurProcState(ActivityManager.PROCESS_STATE_PERSISTENT); // System processes can do UI, and when they do we want to have // them trim their memory after the user leaves the UI. To Loading Loading @@ -1793,7 +1811,7 @@ public class OomAdjusterImpl extends OomAdjuster { } capability |= getDefaultCapability(app, procState); capability |= getCpuCapability(app, now, foregroundActivities); capability |= getCpuCapability(app, foregroundActivities); capability |= getImplicitCpuCapability(app, adj); // Procstates below BFGS should never have this capability. Loading Loading @@ -1887,7 +1905,7 @@ public class OomAdjusterImpl extends OomAdjuster { // we check the final procstate, and remove it if the procsate is below BFGS. capability |= getBfslCapabilityFromClient(client); capability |= getCpuCapabilityFromClient(cr, client); capability |= getCpuCapabilitiesFromClient(app, client, cr); if (cr.notHasFlag(Context.BIND_WAIVE_PRIORITY)) { if (cr.hasFlag(Context.BIND_INCLUDE_CAPABILITIES)) { Loading Loading @@ -2321,8 +2339,7 @@ public class OomAdjusterImpl extends OomAdjuster { // but, right before actually setting it to the process, // we check the final procstate, and remove it if the procsate is below BFGS. capability |= getBfslCapabilityFromClient(client); capability |= getCpuCapabilityFromClient(conn, client); capability |= getCpuCapabilitiesFromClient(app, client, conn); if (clientProcState >= PROCESS_STATE_CACHED_ACTIVITY) { // If the other app is cached for any reason, for purposes here Loading services/core/java/com/android/server/am/psc/ProcessRecordInternal.java +95 −2 Original line number Diff line number Diff line Loading @@ -20,11 +20,13 @@ import static android.app.ActivityManager.PROCESS_CAPABILITY_NONE; import static android.app.ActivityManager.PROCESS_STATE_CACHED_EMPTY; import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; import static com.android.server.am.ProcessList.SERVICE_B_ADJ; import static com.android.server.am.OomAdjuster.CPU_TIME_REASON_NONE; import static com.android.server.am.OomAdjuster.IMPLICIT_CPU_TIME_REASON_NONE; import static com.android.server.am.ProcessList.CACHED_APP_MIN_ADJ; import static com.android.server.am.ProcessList.UNKNOWN_ADJ; import static com.android.server.am.ProcessList.INVALID_ADJ; import static com.android.server.am.ProcessList.SCHED_GROUP_BACKGROUND; import static com.android.server.am.ProcessList.SERVICE_B_ADJ; import static com.android.server.am.ProcessList.UNKNOWN_ADJ; import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_IS_VISIBLE; import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; Loading @@ -38,6 +40,7 @@ import android.util.TimeUtils; import com.android.internal.annotations.CompositeRWLock; import com.android.internal.annotations.GuardedBy; import com.android.server.am.Flags; import com.android.server.am.OomAdjuster; import com.android.server.am.psc.PlatformCompatCache.CachedCompatChangeId; import java.io.PrintWriter; Loading Loading @@ -238,6 +241,38 @@ public abstract class ProcessRecordInternal { @GuardedBy("mServiceLock") private int mVerifiedAdj = INVALID_ADJ; /** * The current reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_CPU_TIME} to this * process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.CpuTimeReasons private int mCurCpuTimeReasons = CPU_TIME_REASON_NONE; /** * The last reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_CPU_TIME} to this * process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.CpuTimeReasons private int mSetCpuTimeReasons = CPU_TIME_REASON_NONE; /** * The current reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_IMPLICIT_CPU_TIME} * to this process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.ImplicitCpuTimeReasons private int mCurImplicitCpuTimeReasons = IMPLICIT_CPU_TIME_REASON_NONE; /** * The last reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_IMPLICIT_CPU_TIME} * to this process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.ImplicitCpuTimeReasons private int mSetImplicitCpuTimeReasons = IMPLICIT_CPU_TIME_REASON_NONE; /** * Current capability flags of this process. * For example, PROCESS_CAPABILITY_FOREGROUND_LOCATION is one capability. Loading Loading @@ -727,6 +762,54 @@ public abstract class ProcessRecordInternal { return mSetCapability; } @GuardedBy({"mServiceLock", "mProcLock"}) public void setSetCpuTimeReasons(@OomAdjuster.CpuTimeReasons int setCpuTimeReasons) { mSetCpuTimeReasons = setCpuTimeReasons; } @GuardedBy(anyOf = {"mServiceLock", "mProcLock"}) @OomAdjuster.CpuTimeReasons public int getCurCpuTimeReasons() { return mCurCpuTimeReasons; } /** Add given reasons to mCurCpuTimeReasons. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void addCurCpuTimeReasons(@OomAdjuster.CpuTimeReasons int cpuTimeReasons) { mCurCpuTimeReasons |= cpuTimeReasons; } /** Sets mCurCpuTimeReasons to CPU_TIME_REASON_NONE. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void clearCurCpuTimeReasons() { mCurCpuTimeReasons = CPU_TIME_REASON_NONE; } @GuardedBy({"mServiceLock", "mProcLock"}) public void setSetImplicitCpuTimeReasons( @OomAdjuster.ImplicitCpuTimeReasons int setImplicitCpuTimeReasons) { mSetImplicitCpuTimeReasons = setImplicitCpuTimeReasons; } @GuardedBy(anyOf = {"mServiceLock", "mProcLock"}) @OomAdjuster.ImplicitCpuTimeReasons public int getCurImplicitCpuTimeReasons() { return mCurImplicitCpuTimeReasons; } /** Add given reasons to mCurImplicitCpuTimeReasons. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void addCurImplicitCpuTimeReasons( @OomAdjuster.ImplicitCpuTimeReasons int implicitCpuTimeReasons) { mCurImplicitCpuTimeReasons |= implicitCpuTimeReasons; } /** Sets mCurImplicitCpuTimeReasons to IMPLICIT_CPU_TIME_REASON_NONE. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void clearCurImplicitCpuTimeReasons() { mCurImplicitCpuTimeReasons = IMPLICIT_CPU_TIME_REASON_NONE; } /** Sets the current scheduling group for this process, and notifies the observer. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void setCurrentSchedulingGroup(int curSchedGroup) { Loading Loading @@ -1577,6 +1660,16 @@ public abstract class ProcessRecordInternal { pw.print(" setCapability="); ActivityManager.printCapabilitiesFull(pw, mSetCapability); pw.println(); pw.print(prefix); pw.print("curCpuTimeReasons=0x"); pw.print(Integer.toHexString(mCurCpuTimeReasons)); pw.print(" setCpuTimeReasons=0x"); pw.print(Integer.toHexString(mSetCpuTimeReasons)); pw.print(" curImplicitCpuTimeReasons=0x"); pw.print(Integer.toHexString(mCurImplicitCpuTimeReasons)); pw.print(" setImplicitCpuTimeReasons=0x"); pw.print(Integer.toHexString(mSetImplicitCpuTimeReasons)); pw.println(); if (mBackgroundRestricted) { pw.print(" backgroundRestricted="); pw.print(mBackgroundRestricted); Loading services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +312 −16 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/core/java/com/android/server/am/ConnectionRecord.java +9 −2 Original line number Diff line number Diff line Loading @@ -161,8 +161,15 @@ final class ConnectionRecord implements OomAdjusterImpl.Connection{ } @Override public boolean transmitsCpuTime() { return !hasFlag(Context.BIND_ALLOW_FREEZE) || mOngoingCalls; public int cpuTimeTransmissionType() { if (mOngoingCalls) { return CPU_TIME_TRANSMISSION_NORMAL; } if (hasFlag(Context.BIND_ALLOW_FREEZE)) { return CPU_TIME_TRANSMISSION_NONE; } return hasFlag(Context.BIND_SIMULATE_ALLOW_FREEZE) ? CPU_TIME_TRANSMISSION_LEGACY : CPU_TIME_TRANSMISSION_NORMAL; } public long getFlags() { Loading
services/core/java/com/android/server/am/OomAdjuster.java +141 −22 Original line number Diff line number Diff line Loading @@ -84,6 +84,8 @@ import static com.android.server.am.ActivityManagerService.TAG_LRU; import static com.android.server.am.ActivityManagerService.TAG_OOM_ADJ; import static com.android.server.am.ActivityManagerService.TAG_UID_OBSERVERS; import static com.android.server.am.AppProfiler.TAG_PSS; import static com.android.server.am.OomAdjusterImpl.Connection.CPU_TIME_TRANSMISSION_LEGACY; import static com.android.server.am.OomAdjusterImpl.Connection.CPU_TIME_TRANSMISSION_NONE; import static com.android.server.am.ProcessList.CACHED_APP_IMPORTANCE_LEVELS; import static com.android.server.am.ProcessList.CACHED_APP_MAX_ADJ; import static com.android.server.am.ProcessList.CACHED_APP_MIN_ADJ; Loading Loading @@ -113,6 +115,7 @@ import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_ import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_IS_VISIBLE; import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; Loading Loading @@ -154,6 +157,8 @@ import com.android.server.am.psc.UidRecordInternal; import com.android.server.wm.WindowProcessController; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; Loading @@ -165,6 +170,66 @@ import java.util.List; public abstract class OomAdjuster { static final String TAG = "OomAdjuster"; /** To be used when the process does not have PROCESS_CAPABILITY_CPU_TIME. */ public static final int CPU_TIME_REASON_NONE = 0; /** The process has PROCESS_CAPABILITY_CPU_TIME, but the reason is not interesting for logs. */ public static final int CPU_TIME_REASON_OTHER = 0x1; /** * The process has PROCESS_CAPABILITY_CPU_TIME because it was transmitted over a connection * from a client. This is interesting because this reason will cease to exist if all the * responsible bindings started using {@link Context#BIND_ALLOW_FREEZE}. */ public static final int CPU_TIME_REASON_TRANSMITTED = 0x2; /** * The process has PROCESS_CAPABILITY_CPU_TIME because it was transmitted over a connection * from a client transitively only because of {@link Context#BIND_SIMULATE_ALLOW_FREEZE}. * This indicates that this reason will soon go away and in absence of other reasons, the app * will not have PROCESS_CAPABILITY_CPU_TIME. */ public static final int CPU_TIME_REASON_TRANSMITTED_LEGACY = 0x4; @IntDef(flag = true, prefix = "CPU_TIME_REASON_", value = { CPU_TIME_REASON_NONE, CPU_TIME_REASON_OTHER, CPU_TIME_REASON_TRANSMITTED, CPU_TIME_REASON_TRANSMITTED_LEGACY, }) @Retention(RetentionPolicy.SOURCE) public @interface CpuTimeReasons { } /** To be used when the process does not have PROCESS_CAPABILITY_IMPLICIT_CPU_TIME. */ public static final int IMPLICIT_CPU_TIME_REASON_NONE = 0; /** * The process has PROCESS_CAPABILITY_IMPLICIT_CPU_TIME, but the reason is not interesting for * logs. */ public static final int IMPLICIT_CPU_TIME_REASON_OTHER = 0x1; /** * The process has PROCESS_CAPABILITY_IMPLICIT_CPU_TIME because it was transmitted over a * connection from a client. This is interesting because this reason will cease to exist if all * the responsible bindings started using {@link Context#BIND_ALLOW_FREEZE}. */ public static final int IMPLICIT_CPU_TIME_REASON_TRANSMITTED = 0x2; /** * The process has PROCESS_CAPABILITY_IMPLICIT_CPU_TIME because it was transmitted over a * connection from a client transitively only because of * {@link Context#BIND_SIMULATE_ALLOW_FREEZE}. * This indicates that this reason will soon go away and in absence of other reasons, the app * will not have PROCESS_CAPABILITY_IMPLICIT_CPU_TIME. */ public static final int IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY = 0x4; @IntDef(flag = true, prefix = "IMPLICIT_CPU_TIME_REASON_", value = { IMPLICIT_CPU_TIME_REASON_NONE, IMPLICIT_CPU_TIME_REASON_OTHER, IMPLICIT_CPU_TIME_REASON_TRANSMITTED, IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY, }) @Retention(RetentionPolicy.SOURCE) public @interface ImplicitCpuTimeReasons { } public static final int oomAdjReasonToProto(@OomAdjReason int oomReason) { switch (oomReason) { case OOM_ADJ_REASON_NONE: Loading Loading @@ -1975,44 +2040,51 @@ public abstract class OomAdjuster { return baseCapabilities | networkCapabilities; } protected static int getCpuCapability(ProcessRecord app, long nowUptime, boolean hasForegroundActivities) { // Note: persistent processes get all capabilities, including CPU_TIME. @CpuTimeReasons private static int getCpuTimeReasons(ProcessRecord app, boolean hasForegroundActivities) { // Note: persistent processes always get CPU_TIME with reason CPU_TIME_REASON_OTHER. // Currently, we only cite CPU_TIME_REASON_OTHER for all reasons. More specific reasons // can be used when they become interesting to observe. final UidRecordInternal uidRec = app.getUidRecord(); if (uidRec != null && uidRec.isCurAllowListed()) { // Process is in the power allowlist. return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (hasForegroundActivities) { // TODO: b/402987519 - This grants the Top Sleeping process CPU_TIME but eventually // should not. // Process has user perceptible activities. return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.mServices.numberOfExecutingServices() > 0) { // Ensure that services get cpu time during start-up and tear-down. return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.mServices.hasForegroundServices()) { return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.mReceivers.isReceivingBroadcast()) { return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } if (app.hasActiveInstrumentation()) { return PROCESS_CAPABILITY_CPU_TIME; return CPU_TIME_REASON_OTHER; } // TODO(b/370817323): Populate this method with all of the reasons to keep a process // unfrozen. return 0; return CPU_TIME_REASON_NONE; } protected static int getCpuCapability(ProcessRecord app, boolean hasForegroundActivities) { final int reasons = getCpuTimeReasons(app, hasForegroundActivities); app.addCurCpuTimeReasons(reasons); return (reasons != CPU_TIME_REASON_NONE) ? PROCESS_CAPABILITY_CPU_TIME : 0; } // Grant PROCESS_CAPABILITY_IMPLICIT_CPU_TIME to processes based on oom adj score. protected int getImplicitCpuCapability(ProcessRecordInternal app, int adj) { if (adj < mConstants.FREEZER_CUTOFF_ADJ) { return PROCESS_CAPABILITY_IMPLICIT_CPU_TIME; } if (app.getMaxAdj() < mConstants.FREEZER_CUTOFF_ADJ) { if (adj < mConstants.FREEZER_CUTOFF_ADJ || app.getMaxAdj() < mConstants.FREEZER_CUTOFF_ADJ) { app.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER); return PROCESS_CAPABILITY_IMPLICIT_CPU_TIME; } return 0; Loading Loading @@ -2068,13 +2140,49 @@ public abstract class OomAdjuster { /** * @return the CPU capability from a client (of a service binding or provider). */ protected static int getCpuCapabilityFromClient(OomAdjusterImpl.Connection conn, ProcessRecordInternal client) { if (conn == null || conn.transmitsCpuTime()) { return client.getCurCapability() & ALL_CPU_TIME_CAPABILITIES; } else { protected static int getCpuCapabilitiesFromClient(ProcessRecordInternal app, ProcessRecord client, OomAdjusterImpl.Connection conn) { final int clientCpuCaps = client.getCurCapability() & ALL_CPU_TIME_CAPABILITIES; final @CpuTimeReasons int clientCpuReasons = client.getCurCpuTimeReasons(); final @ImplicitCpuTimeReasons int clientImplicitCpuReasons = client.getCurImplicitCpuTimeReasons(); final @OomAdjusterImpl.Connection.CpuTimeTransmissionType int transmissionType = (conn != null) ? conn.cpuTimeTransmissionType() : CPU_TIME_TRANSMISSION_NONE; if (transmissionType == CPU_TIME_TRANSMISSION_NONE) { // The binding does not transmit CPU_TIME capabilities in any way. return 0; } @CpuTimeReasons int cpuReasons = CPU_TIME_REASON_NONE; @ImplicitCpuTimeReasons int implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_NONE; if ((clientCpuCaps & PROCESS_CAPABILITY_CPU_TIME) != 0) { if (clientCpuReasons == CPU_TIME_REASON_TRANSMITTED_LEGACY) { // Client has CPU_TIME only for a legacy reason. cpuReasons = CPU_TIME_REASON_TRANSMITTED_LEGACY; } else if (transmissionType == CPU_TIME_TRANSMISSION_LEGACY) { // Binding only transmits CPU_TIME for a legacy reason. cpuReasons = CPU_TIME_REASON_TRANSMITTED_LEGACY; } else { cpuReasons = CPU_TIME_REASON_TRANSMITTED; } } if ((clientCpuCaps & PROCESS_CAPABILITY_IMPLICIT_CPU_TIME) != 0) { if (clientImplicitCpuReasons == IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY) { // Client has IMPLICIT_CPU_TIME only for a legacy reason. implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY; } else if (transmissionType == CPU_TIME_TRANSMISSION_LEGACY) { // Binding only transmits IMPLICIT_CPU_TIME for a legacy reason. implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_TRANSMITTED_LEGACY; } else { implicitCpuReasons = IMPLICIT_CPU_TIME_REASON_TRANSMITTED; } } app.addCurCpuTimeReasons(cpuReasons); app.addCurImplicitCpuTimeReasons(implicitCpuReasons); return clientCpuCaps; } /** Inform the oomadj observer of changes to oomadj. Used by tests. */ Loading Loading @@ -2312,6 +2420,8 @@ public abstract class OomAdjuster { if (state.getCurCapability() != state.getSetCapability()) { state.setSetCapability(state.getCurCapability()); state.setSetCpuTimeReasons(state.getCurCpuTimeReasons()); state.setSetImplicitCpuTimeReasons(state.getCurImplicitCpuTimeReasons()); } final boolean curBoundByNonBgRestrictedApp = state.isCurBoundByNonBgRestrictedApp(); Loading Loading @@ -2404,6 +2514,8 @@ public abstract class OomAdjuster { state.setCurProcState(initialProcState); state.setCurRawProcState(initialProcState); state.setCurCapability(initialCapability); state.addCurCpuTimeReasons(CPU_TIME_REASON_OTHER); state.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER); state.setCurAdj(ProcessList.FOREGROUND_APP_ADJ); state.setCurRawAdj(ProcessList.FOREGROUND_APP_ADJ); Loading Loading @@ -2609,7 +2721,7 @@ public abstract class OomAdjuster { if ((proc.getCurCapability() & ALL_CPU_TIME_CAPABILITIES) != 0) { /// App is important enough (see {@link #getCpuCapability} and /// {@link #getImplicitCpuCapability}) or bound by something important enough to /// not be frozen (see {@link #getCpuCapabilityFromClient}). /// not be frozen (see {@link #getCpuCapabilitiesFromClient}). return false; } Loading Loading @@ -2670,6 +2782,8 @@ public abstract class OomAdjuster { == PROCESS_CAPABILITY_IMPLICIT_CPU_TIME; final boolean implicitCpuCapabilityChanged = hasImplicitCpuCapability != usedToHaveImplicitCpuCapability; final int cpuTimeReasons = app.getCurCpuTimeReasons(); final int implicitCpuTimeReasons = app.getCurImplicitCpuTimeReasons(); if ((oomAdjChanged || shouldNotFreezeChanged || cpuCapabilityChanged || implicitCpuCapabilityChanged) && Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) { Loading @@ -2688,7 +2802,9 @@ public abstract class OomAdjuster { + "/" + app.getPid() + "/" + state.getCurAdj() + "/" + oldOomAdj + "/" + opt.shouldNotFreezeReason()); + "/" + opt.shouldNotFreezeReason() + "/" + cpuTimeReasons + "/" + implicitCpuTimeReasons); Trace.instantForTrack(Trace.TRACE_TAG_ACTIVITY_MANAGER, CachedAppOptimizer.ATRACE_FREEZER_TRACK, "updateAppFreezeStateLSP " + app.processName Loading @@ -2701,7 +2817,10 @@ public abstract class OomAdjuster { + " oldOomAdj: " + oldOomAdj + " immediate: " + immediate + " cpuCapability: " + hasCpuCapability + " implicitCpuCapability: " + hasImplicitCpuCapability); + " implicitCpuCapability: " + hasImplicitCpuCapability + " cpuTimeReasons: 0x" + Integer.toHexString(cpuTimeReasons) + " implicitCpuTimeReasons: 0x" + Integer.toHexString(implicitCpuTimeReasons)); } } Loading
services/core/java/com/android/server/am/OomAdjusterImpl.java +26 −9 Original line number Diff line number Diff line Loading @@ -498,6 +498,18 @@ public class OomAdjusterImpl extends OomAdjuster { * change in importance in the host process based on the client process and connection state. */ public interface Connection { int CPU_TIME_TRANSMISSION_NONE = 0; int CPU_TIME_TRANSMISSION_NORMAL = 1; int CPU_TIME_TRANSMISSION_LEGACY = 2; @IntDef(prefix = "CPU_TIME_TRANSMISSION_", value = { CPU_TIME_TRANSMISSION_NONE, CPU_TIME_TRANSMISSION_NORMAL, CPU_TIME_TRANSMISSION_LEGACY, }) @interface CpuTimeTransmissionType { } /** * Compute the impact this connection has on the host's importance values. */ Loading @@ -510,12 +522,12 @@ public class OomAdjusterImpl extends OomAdjuster { boolean canAffectCapabilities(); /** * Returns whether this connection transmits PROCESS_CAPABILITY_CPU_TIME to the host, if the * client possesses it. * Returns the type of transmission of ALL_CPU_TIME_CAPABILITIES to the host, if the client * possesses it. */ default boolean transmitsCpuTime() { // Always lend this capability by default. return true; @CpuTimeTransmissionType default int cpuTimeTransmissionType() { return CPU_TIME_TRANSMISSION_NORMAL; } } Loading Loading @@ -1171,6 +1183,10 @@ public class OomAdjusterImpl extends OomAdjuster { long now) { final ProcessRecordInternal state = app; // We'll evaluate the reasons within getCpuCapability and getImplicitCpuCapability later. state.clearCurCpuTimeReasons(); state.clearCurImplicitCpuTimeReasons(); // Remove any follow up update this process might have. It will be rescheduled if still // needed. state.setFollowupUpdateUptimeMs(NO_FOLLOW_UP_TIME); Loading Loading @@ -1213,6 +1229,8 @@ public class OomAdjusterImpl extends OomAdjuster { state.setHasForegroundActivities(false); state.setCurrentSchedulingGroup(SCHED_GROUP_DEFAULT); state.setCurCapability(PROCESS_CAPABILITY_ALL); // BFSL allowed state.addCurCpuTimeReasons(CPU_TIME_REASON_OTHER); state.addCurImplicitCpuTimeReasons(IMPLICIT_CPU_TIME_REASON_OTHER); state.setCurProcState(ActivityManager.PROCESS_STATE_PERSISTENT); // System processes can do UI, and when they do we want to have // them trim their memory after the user leaves the UI. To Loading Loading @@ -1793,7 +1811,7 @@ public class OomAdjusterImpl extends OomAdjuster { } capability |= getDefaultCapability(app, procState); capability |= getCpuCapability(app, now, foregroundActivities); capability |= getCpuCapability(app, foregroundActivities); capability |= getImplicitCpuCapability(app, adj); // Procstates below BFGS should never have this capability. Loading Loading @@ -1887,7 +1905,7 @@ public class OomAdjusterImpl extends OomAdjuster { // we check the final procstate, and remove it if the procsate is below BFGS. capability |= getBfslCapabilityFromClient(client); capability |= getCpuCapabilityFromClient(cr, client); capability |= getCpuCapabilitiesFromClient(app, client, cr); if (cr.notHasFlag(Context.BIND_WAIVE_PRIORITY)) { if (cr.hasFlag(Context.BIND_INCLUDE_CAPABILITIES)) { Loading Loading @@ -2321,8 +2339,7 @@ public class OomAdjusterImpl extends OomAdjuster { // but, right before actually setting it to the process, // we check the final procstate, and remove it if the procsate is below BFGS. capability |= getBfslCapabilityFromClient(client); capability |= getCpuCapabilityFromClient(conn, client); capability |= getCpuCapabilitiesFromClient(app, client, conn); if (clientProcState >= PROCESS_STATE_CACHED_ACTIVITY) { // If the other app is cached for any reason, for purposes here Loading
services/core/java/com/android/server/am/psc/ProcessRecordInternal.java +95 −2 Original line number Diff line number Diff line Loading @@ -20,11 +20,13 @@ import static android.app.ActivityManager.PROCESS_CAPABILITY_NONE; import static android.app.ActivityManager.PROCESS_STATE_CACHED_EMPTY; import static android.app.ActivityManager.PROCESS_STATE_NONEXISTENT; import static com.android.server.am.ProcessList.SERVICE_B_ADJ; import static com.android.server.am.OomAdjuster.CPU_TIME_REASON_NONE; import static com.android.server.am.OomAdjuster.IMPLICIT_CPU_TIME_REASON_NONE; import static com.android.server.am.ProcessList.CACHED_APP_MIN_ADJ; import static com.android.server.am.ProcessList.UNKNOWN_ADJ; import static com.android.server.am.ProcessList.INVALID_ADJ; import static com.android.server.am.ProcessList.SCHED_GROUP_BACKGROUND; import static com.android.server.am.ProcessList.SERVICE_B_ADJ; import static com.android.server.am.ProcessList.UNKNOWN_ADJ; import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_IS_VISIBLE; import static com.android.server.wm.WindowProcessController.ACTIVITY_STATE_FLAG_MASK_MIN_TASK_LAYER; Loading @@ -38,6 +40,7 @@ import android.util.TimeUtils; import com.android.internal.annotations.CompositeRWLock; import com.android.internal.annotations.GuardedBy; import com.android.server.am.Flags; import com.android.server.am.OomAdjuster; import com.android.server.am.psc.PlatformCompatCache.CachedCompatChangeId; import java.io.PrintWriter; Loading Loading @@ -238,6 +241,38 @@ public abstract class ProcessRecordInternal { @GuardedBy("mServiceLock") private int mVerifiedAdj = INVALID_ADJ; /** * The current reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_CPU_TIME} to this * process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.CpuTimeReasons private int mCurCpuTimeReasons = CPU_TIME_REASON_NONE; /** * The last reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_CPU_TIME} to this * process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.CpuTimeReasons private int mSetCpuTimeReasons = CPU_TIME_REASON_NONE; /** * The current reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_IMPLICIT_CPU_TIME} * to this process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.ImplicitCpuTimeReasons private int mCurImplicitCpuTimeReasons = IMPLICIT_CPU_TIME_REASON_NONE; /** * The last reasons for granting {@link ActivityManager#PROCESS_CAPABILITY_IMPLICIT_CPU_TIME} * to this process. */ @CompositeRWLock({"mServiceLock", "mProcLock"}) @OomAdjuster.ImplicitCpuTimeReasons private int mSetImplicitCpuTimeReasons = IMPLICIT_CPU_TIME_REASON_NONE; /** * Current capability flags of this process. * For example, PROCESS_CAPABILITY_FOREGROUND_LOCATION is one capability. Loading Loading @@ -727,6 +762,54 @@ public abstract class ProcessRecordInternal { return mSetCapability; } @GuardedBy({"mServiceLock", "mProcLock"}) public void setSetCpuTimeReasons(@OomAdjuster.CpuTimeReasons int setCpuTimeReasons) { mSetCpuTimeReasons = setCpuTimeReasons; } @GuardedBy(anyOf = {"mServiceLock", "mProcLock"}) @OomAdjuster.CpuTimeReasons public int getCurCpuTimeReasons() { return mCurCpuTimeReasons; } /** Add given reasons to mCurCpuTimeReasons. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void addCurCpuTimeReasons(@OomAdjuster.CpuTimeReasons int cpuTimeReasons) { mCurCpuTimeReasons |= cpuTimeReasons; } /** Sets mCurCpuTimeReasons to CPU_TIME_REASON_NONE. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void clearCurCpuTimeReasons() { mCurCpuTimeReasons = CPU_TIME_REASON_NONE; } @GuardedBy({"mServiceLock", "mProcLock"}) public void setSetImplicitCpuTimeReasons( @OomAdjuster.ImplicitCpuTimeReasons int setImplicitCpuTimeReasons) { mSetImplicitCpuTimeReasons = setImplicitCpuTimeReasons; } @GuardedBy(anyOf = {"mServiceLock", "mProcLock"}) @OomAdjuster.ImplicitCpuTimeReasons public int getCurImplicitCpuTimeReasons() { return mCurImplicitCpuTimeReasons; } /** Add given reasons to mCurImplicitCpuTimeReasons. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void addCurImplicitCpuTimeReasons( @OomAdjuster.ImplicitCpuTimeReasons int implicitCpuTimeReasons) { mCurImplicitCpuTimeReasons |= implicitCpuTimeReasons; } /** Sets mCurImplicitCpuTimeReasons to IMPLICIT_CPU_TIME_REASON_NONE. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void clearCurImplicitCpuTimeReasons() { mCurImplicitCpuTimeReasons = IMPLICIT_CPU_TIME_REASON_NONE; } /** Sets the current scheduling group for this process, and notifies the observer. */ @GuardedBy({"mServiceLock", "mProcLock"}) public void setCurrentSchedulingGroup(int curSchedGroup) { Loading Loading @@ -1577,6 +1660,16 @@ public abstract class ProcessRecordInternal { pw.print(" setCapability="); ActivityManager.printCapabilitiesFull(pw, mSetCapability); pw.println(); pw.print(prefix); pw.print("curCpuTimeReasons=0x"); pw.print(Integer.toHexString(mCurCpuTimeReasons)); pw.print(" setCpuTimeReasons=0x"); pw.print(Integer.toHexString(mSetCpuTimeReasons)); pw.print(" curImplicitCpuTimeReasons=0x"); pw.print(Integer.toHexString(mCurImplicitCpuTimeReasons)); pw.print(" setImplicitCpuTimeReasons=0x"); pw.print(Integer.toHexString(mSetImplicitCpuTimeReasons)); pw.println(); if (mBackgroundRestricted) { pw.print(" backgroundRestricted="); pw.print(mBackgroundRestricted); Loading
services/tests/mockingservicestests/src/com/android/server/am/MockingOomAdjusterTests.java +312 −16 File changed.Preview size limit exceeded, changes collapsed. Show changes