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

Commit ad19fc30 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Bump Standby Bucket for FGS sooner." into sc-dev am: fbd8deba

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14340965

Change-Id: Iab8a714c3de518e555b29743b3a65c66b5b1e066
parents 759a6a32 fbd8deba
Loading
Loading
Loading
Loading
+48 −16
Original line number Original line Diff line number Diff line
@@ -73,10 +73,16 @@ final class ActivityManagerConstants extends ContentObserver {
    private static final String KEY_POWER_CHECK_MAX_CPU_2 = "power_check_max_cpu_2";
    private static final String KEY_POWER_CHECK_MAX_CPU_2 = "power_check_max_cpu_2";
    private static final String KEY_POWER_CHECK_MAX_CPU_3 = "power_check_max_cpu_3";
    private static final String KEY_POWER_CHECK_MAX_CPU_3 = "power_check_max_cpu_3";
    private static final String KEY_POWER_CHECK_MAX_CPU_4 = "power_check_max_cpu_4";
    private static final String KEY_POWER_CHECK_MAX_CPU_4 = "power_check_max_cpu_4";
    private static final String KEY_SERVICE_USAGE_INTERACTION_TIME
    /** Used for all apps on R and earlier versions. */
            = "service_usage_interaction_time";
    private static final String KEY_SERVICE_USAGE_INTERACTION_TIME_PRE_S =
    private static final String KEY_USAGE_STATS_INTERACTION_INTERVAL
            "service_usage_interaction_time";
            = "usage_stats_interaction_interval";
    private static final String KEY_SERVICE_USAGE_INTERACTION_TIME_POST_S =
            "service_usage_interaction_time_post_s";
    /** Used for all apps on R and earlier versions. */
    private static final String KEY_USAGE_STATS_INTERACTION_INTERVAL_PRE_S =
            "usage_stats_interaction_interval";
    private static final String KEY_USAGE_STATS_INTERACTION_INTERVAL_POST_S =
            "usage_stats_interaction_interval_post_s";
    private static final String KEY_IMPERCEPTIBLE_KILL_EXEMPT_PACKAGES =
    private static final String KEY_IMPERCEPTIBLE_KILL_EXEMPT_PACKAGES =
            "imperceptible_kill_exempt_packages";
            "imperceptible_kill_exempt_packages";
    private static final String KEY_IMPERCEPTIBLE_KILL_EXEMPT_PROC_STATES =
    private static final String KEY_IMPERCEPTIBLE_KILL_EXEMPT_PROC_STATES =
@@ -120,8 +126,10 @@ final class ActivityManagerConstants extends ContentObserver {
    private static final int DEFAULT_POWER_CHECK_MAX_CPU_2 = 25;
    private static final int DEFAULT_POWER_CHECK_MAX_CPU_2 = 25;
    private static final int DEFAULT_POWER_CHECK_MAX_CPU_3 = 10;
    private static final int DEFAULT_POWER_CHECK_MAX_CPU_3 = 10;
    private static final int DEFAULT_POWER_CHECK_MAX_CPU_4 = 2;
    private static final int DEFAULT_POWER_CHECK_MAX_CPU_4 = 2;
    private static final long DEFAULT_SERVICE_USAGE_INTERACTION_TIME = 30*60*1000;
    private static final long DEFAULT_SERVICE_USAGE_INTERACTION_TIME_PRE_S = 30 * 60 * 1000;
    private static final long DEFAULT_USAGE_STATS_INTERACTION_INTERVAL = 2*60*60*1000L;
    private static final long DEFAULT_SERVICE_USAGE_INTERACTION_TIME_POST_S = 60 * 1000;
    private static final long DEFAULT_USAGE_STATS_INTERACTION_INTERVAL_PRE_S = 2 * 60 * 60 * 1000;
    private static final long DEFAULT_USAGE_STATS_INTERACTION_INTERVAL_POST_S = 10 * 60 * 1000;
    private static final long DEFAULT_SERVICE_RESTART_DURATION = 1*1000;
    private static final long DEFAULT_SERVICE_RESTART_DURATION = 1*1000;
    private static final long DEFAULT_SERVICE_RESET_RUN_DURATION = 60*1000;
    private static final long DEFAULT_SERVICE_RESET_RUN_DURATION = 60*1000;
    private static final int DEFAULT_SERVICE_RESTART_DURATION_FACTOR = 4;
    private static final int DEFAULT_SERVICE_RESTART_DURATION_FACTOR = 4;
@@ -303,11 +311,23 @@ final class ActivityManagerConstants extends ContentObserver {


    // This is the amount of time an app needs to be running a foreground service before
    // This is the amount of time an app needs to be running a foreground service before
    // we will consider it to be doing interaction for usage stats.
    // we will consider it to be doing interaction for usage stats.
    long SERVICE_USAGE_INTERACTION_TIME = DEFAULT_SERVICE_USAGE_INTERACTION_TIME;
    // Only used for apps targeting pre-S versions.
    long SERVICE_USAGE_INTERACTION_TIME_PRE_S = DEFAULT_SERVICE_USAGE_INTERACTION_TIME_PRE_S;

    // This is the amount of time an app needs to be running a foreground service before
    // we will consider it to be doing interaction for usage stats.
    // Only used for apps targeting versions S and above.
    long SERVICE_USAGE_INTERACTION_TIME_POST_S = DEFAULT_SERVICE_USAGE_INTERACTION_TIME_POST_S;

    // Maximum amount of time we will allow to elapse before re-reporting usage stats
    // interaction with foreground processes.
    // Only used for apps targeting pre-S versions.
    long USAGE_STATS_INTERACTION_INTERVAL_PRE_S = DEFAULT_USAGE_STATS_INTERACTION_INTERVAL_PRE_S;


    // Maximum amount of time we will allow to elapse before re-reporting usage stats
    // Maximum amount of time we will allow to elapse before re-reporting usage stats
    // interaction with foreground processes.
    // interaction with foreground processes.
    long USAGE_STATS_INTERACTION_INTERVAL = DEFAULT_USAGE_STATS_INTERACTION_INTERVAL;
    // Only used for apps targeting versions S and above.
    long USAGE_STATS_INTERACTION_INTERVAL_POST_S = DEFAULT_USAGE_STATS_INTERACTION_INTERVAL_POST_S;


    // How long a service needs to be running until restarting its process
    // How long a service needs to be running until restarting its process
    // is no longer considered to be a relaunch of the service.
    // is no longer considered to be a relaunch of the service.
@@ -817,10 +837,18 @@ final class ActivityManagerConstants extends ContentObserver {
                    DEFAULT_POWER_CHECK_MAX_CPU_3);
                    DEFAULT_POWER_CHECK_MAX_CPU_3);
            POWER_CHECK_MAX_CPU_4 = mParser.getInt(KEY_POWER_CHECK_MAX_CPU_4,
            POWER_CHECK_MAX_CPU_4 = mParser.getInt(KEY_POWER_CHECK_MAX_CPU_4,
                    DEFAULT_POWER_CHECK_MAX_CPU_4);
                    DEFAULT_POWER_CHECK_MAX_CPU_4);
            SERVICE_USAGE_INTERACTION_TIME = mParser.getLong(KEY_SERVICE_USAGE_INTERACTION_TIME,
            SERVICE_USAGE_INTERACTION_TIME_PRE_S = mParser.getLong(
                    DEFAULT_SERVICE_USAGE_INTERACTION_TIME);
                    KEY_SERVICE_USAGE_INTERACTION_TIME_PRE_S,
            USAGE_STATS_INTERACTION_INTERVAL = mParser.getLong(KEY_USAGE_STATS_INTERACTION_INTERVAL,
                    DEFAULT_SERVICE_USAGE_INTERACTION_TIME_PRE_S);
                    DEFAULT_USAGE_STATS_INTERACTION_INTERVAL);
            SERVICE_USAGE_INTERACTION_TIME_POST_S = mParser.getLong(
                    KEY_SERVICE_USAGE_INTERACTION_TIME_POST_S,
                    DEFAULT_SERVICE_USAGE_INTERACTION_TIME_POST_S);
            USAGE_STATS_INTERACTION_INTERVAL_PRE_S = mParser.getLong(
                    KEY_USAGE_STATS_INTERACTION_INTERVAL_PRE_S,
                    DEFAULT_USAGE_STATS_INTERACTION_INTERVAL_PRE_S);
            USAGE_STATS_INTERACTION_INTERVAL_POST_S = mParser.getLong(
                    KEY_USAGE_STATS_INTERACTION_INTERVAL_POST_S,
                    DEFAULT_USAGE_STATS_INTERACTION_INTERVAL_POST_S);
            SERVICE_RESTART_DURATION = mParser.getLong(KEY_SERVICE_RESTART_DURATION,
            SERVICE_RESTART_DURATION = mParser.getLong(KEY_SERVICE_RESTART_DURATION,
                    DEFAULT_SERVICE_RESTART_DURATION);
                    DEFAULT_SERVICE_RESTART_DURATION);
            SERVICE_RESET_RUN_DURATION = mParser.getLong(KEY_SERVICE_RESET_RUN_DURATION,
            SERVICE_RESET_RUN_DURATION = mParser.getLong(KEY_SERVICE_RESET_RUN_DURATION,
@@ -1135,10 +1163,14 @@ final class ActivityManagerConstants extends ContentObserver {
        pw.println(POWER_CHECK_MAX_CPU_3);
        pw.println(POWER_CHECK_MAX_CPU_3);
        pw.print("  "); pw.print(KEY_POWER_CHECK_MAX_CPU_4); pw.print("=");
        pw.print("  "); pw.print(KEY_POWER_CHECK_MAX_CPU_4); pw.print("=");
        pw.println(POWER_CHECK_MAX_CPU_4);
        pw.println(POWER_CHECK_MAX_CPU_4);
        pw.print("  "); pw.print(KEY_SERVICE_USAGE_INTERACTION_TIME); pw.print("=");
        pw.print("  "); pw.print(KEY_SERVICE_USAGE_INTERACTION_TIME_PRE_S); pw.print("=");
        pw.println(SERVICE_USAGE_INTERACTION_TIME);
        pw.println(SERVICE_USAGE_INTERACTION_TIME_PRE_S);
        pw.print("  "); pw.print(KEY_USAGE_STATS_INTERACTION_INTERVAL); pw.print("=");
        pw.print("  "); pw.print(KEY_SERVICE_USAGE_INTERACTION_TIME_POST_S); pw.print("=");
        pw.println(USAGE_STATS_INTERACTION_INTERVAL);
        pw.println(SERVICE_USAGE_INTERACTION_TIME_POST_S);
        pw.print("  "); pw.print(KEY_USAGE_STATS_INTERACTION_INTERVAL_PRE_S); pw.print("=");
        pw.println(USAGE_STATS_INTERACTION_INTERVAL_PRE_S);
        pw.print("  "); pw.print(KEY_USAGE_STATS_INTERACTION_INTERVAL_POST_S); pw.print("=");
        pw.println(USAGE_STATS_INTERACTION_INTERVAL_POST_S);
        pw.print("  "); pw.print(KEY_SERVICE_RESTART_DURATION); pw.print("=");
        pw.print("  "); pw.print(KEY_SERVICE_RESTART_DURATION); pw.print("=");
        pw.println(SERVICE_RESTART_DURATION);
        pw.println(SERVICE_RESTART_DURATION);
        pw.print("  "); pw.print(KEY_SERVICE_RESET_RUN_DURATION); pw.print("=");
        pw.print("  "); pw.print(KEY_SERVICE_RESET_RUN_DURATION); pw.print("=");
+66 −16
Original line number Original line Diff line number Diff line
@@ -80,6 +80,7 @@ import android.app.ApplicationExitInfo;
import android.app.usage.UsageEvents;
import android.app.usage.UsageEvents;
import android.compat.annotation.ChangeId;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.EnabledSince;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
@@ -122,7 +123,7 @@ import java.util.Arrays;
/**
/**
 * All of the code required to compute proc states and oom_adj values.
 * All of the code required to compute proc states and oom_adj values.
 */
 */
public final class OomAdjuster {
public class OomAdjuster {
    static final String TAG = "OomAdjuster";
    static final String TAG = "OomAdjuster";
    static final String OOM_ADJ_REASON_METHOD = "updateOomAdj";
    static final String OOM_ADJ_REASON_METHOD = "updateOomAdj";
    static final String OOM_ADJ_REASON_NONE = OOM_ADJ_REASON_METHOD + "_meh";
    static final String OOM_ADJ_REASON_NONE = OOM_ADJ_REASON_METHOD + "_meh";
@@ -163,6 +164,14 @@ public final class OomAdjuster {
    @EnabledAfter(targetSdkVersion=android.os.Build.VERSION_CODES.Q)
    @EnabledAfter(targetSdkVersion=android.os.Build.VERSION_CODES.Q)
    static final long CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID = 136219221L;
    static final long CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID = 136219221L;


    /**
     * For apps targeting S+, this determines whether to use a shorter timeout before elevating the
     * standby bucket to ACTIVE when apps start a foreground service.
     */
    @ChangeId
    @EnabledSince(targetSdkVersion = android.os.Build.VERSION_CODES.S)
    static final long USE_SHORT_FGS_USAGE_INTERACTION_TIME = 183972877L;

    /**
    /**
     * For some direct access we need to power manager.
     * For some direct access we need to power manager.
     */
     */
@@ -249,7 +258,9 @@ public final class OomAdjuster {


    private final PlatformCompatCache mPlatformCompatCache;
    private final PlatformCompatCache mPlatformCompatCache;


    private static class PlatformCompatCache {
    /** Overrideable by a test */
    @VisibleForTesting
    static class PlatformCompatCache {
        private final PlatformCompat mPlatformCompat;
        private final PlatformCompat mPlatformCompat;
        private final IPlatformCompat mIPlatformCompatProxy;
        private final IPlatformCompat mIPlatformCompatProxy;
        private final LongSparseArray<CacheItem> mCaches = new LongSparseArray<>();
        private final LongSparseArray<CacheItem> mCaches = new LongSparseArray<>();
@@ -278,6 +289,20 @@ public final class OomAdjuster {
                    : mIPlatformCompatProxy.isChangeEnabled(changeId, app);
                    : mIPlatformCompatProxy.isChangeEnabled(changeId, app);
        }
        }


        /**
         * Same as {@link #isChangeEnabled(long, ApplicationInfo)} but instead of throwing a
         * RemoteException from platform compat, it returns the default value provided.
         */
        boolean isChangeEnabled(long changeId, ApplicationInfo app, boolean defaultValue) {
            try {
                return mCacheEnabled ? mCaches.get(changeId).isChangeEnabled(app)
                        : mIPlatformCompatProxy.isChangeEnabled(changeId, app);
            } catch (RemoteException e) {
                Slog.w(TAG, "Error reading platform compat change " + changeId, e);
                return defaultValue;
            }
        }

        void invalidate(ApplicationInfo app) {
        void invalidate(ApplicationInfo app) {
            for (int i = mCaches.size() - 1; i >= 0; i--) {
            for (int i = mCaches.size() - 1; i >= 0; i--) {
                mCaches.valueAt(i).invalidate(app);
                mCaches.valueAt(i).invalidate(app);
@@ -335,6 +360,12 @@ public final class OomAdjuster {
        }
        }
    }
    }


    /** Overrideable by a test */
    @VisibleForTesting
    protected PlatformCompatCache getPlatformCompatCache() {
        return mPlatformCompatCache;
    }

    OomAdjuster(ActivityManagerService service, ProcessList processList, ActiveUids activeUids) {
    OomAdjuster(ActivityManagerService service, ProcessList processList, ActiveUids activeUids) {
        this(service, processList, activeUids, createAdjusterThread());
        this(service, processList, activeUids, createAdjusterThread());
    }
    }
@@ -383,7 +414,8 @@ public final class OomAdjuster {
        mNumSlots = ((ProcessList.CACHED_APP_MAX_ADJ - ProcessList.CACHED_APP_MIN_ADJ + 1) >> 1)
        mNumSlots = ((ProcessList.CACHED_APP_MAX_ADJ - ProcessList.CACHED_APP_MIN_ADJ + 1) >> 1)
                / ProcessList.CACHED_APP_IMPORTANCE_LEVELS;
                / ProcessList.CACHED_APP_IMPORTANCE_LEVELS;
        mPlatformCompatCache = new PlatformCompatCache(new long[] {
        mPlatformCompatCache = new PlatformCompatCache(new long[] {
                PROCESS_CAPABILITY_CHANGE_ID, CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID
                PROCESS_CAPABILITY_CHANGE_ID, CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID,
                USE_SHORT_FGS_USAGE_INTERACTION_TIME
        });
        });
    }
    }


@@ -755,7 +787,7 @@ public final class OomAdjuster {
        if (app != null) {
        if (app != null) {
            mPendingProcessSet.remove(app);
            mPendingProcessSet.remove(app);
            if (procDied) {
            if (procDied) {
                mPlatformCompatCache.invalidate(app.info);
                getPlatformCompatCache().invalidate(app.info);
            }
            }
        }
        }
    }
    }
@@ -1924,7 +1956,7 @@ public final class OomAdjuster {


                    boolean enabled = false;
                    boolean enabled = false;
                    try {
                    try {
                        enabled = mPlatformCompatCache.isChangeEnabled(
                        enabled = getPlatformCompatCache().isChangeEnabled(
                                CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID, s.appInfo);
                                CAMERA_MICROPHONE_CAPABILITY_CHANGE_ID, s.appInfo);
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {
                    }
                    }
@@ -2147,7 +2179,7 @@ public final class OomAdjuster {
                                state.bumpAllowStartFgsState(PROCESS_STATE_BOUND_TOP);
                                state.bumpAllowStartFgsState(PROCESS_STATE_BOUND_TOP);
                                boolean enabled = false;
                                boolean enabled = false;
                                try {
                                try {
                                    enabled = mPlatformCompatCache.isChangeEnabled(
                                    enabled = getPlatformCompatCache().isChangeEnabled(
                                            PROCESS_CAPABILITY_CHANGE_ID, client.info);
                                            PROCESS_CAPABILITY_CHANGE_ID, client.info);
                                } catch (RemoteException e) {
                                } catch (RemoteException e) {
                                }
                                }
@@ -2787,16 +2819,28 @@ public final class OomAdjuster {
            } else {
            } else {
                state.setProcStateChanged(true);
                state.setProcStateChanged(true);
            }
            }
        } else if (state.hasReportedInteraction() && (nowElapsed - state.getInteractionEventTime())
        } else if (state.hasReportedInteraction()) {
                > mConstants.USAGE_STATS_INTERACTION_INTERVAL) {
            final boolean fgsInteractionChangeEnabled = getPlatformCompatCache().isChangeEnabled(
                    USE_SHORT_FGS_USAGE_INTERACTION_TIME, app.info, false);
            final long interactionThreshold = fgsInteractionChangeEnabled
                    ? mConstants.USAGE_STATS_INTERACTION_INTERVAL_POST_S
                    : mConstants.USAGE_STATS_INTERACTION_INTERVAL_PRE_S;
            // For apps that sit around for a long time in the interactive state, we need
            // For apps that sit around for a long time in the interactive state, we need
            // to report this at least once a day so they don't go idle.
            // to report this at least once a day so they don't go idle.
            if ((nowElapsed - state.getInteractionEventTime()) > interactionThreshold) {
                maybeUpdateUsageStatsLSP(app, nowElapsed);
                maybeUpdateUsageStatsLSP(app, nowElapsed);
        } else if (!state.hasReportedInteraction() && (nowElapsed - state.getFgInteractionTime())
            }
                > mConstants.SERVICE_USAGE_INTERACTION_TIME) {
        } else {
            final boolean fgsInteractionChangeEnabled = getPlatformCompatCache().isChangeEnabled(
                    USE_SHORT_FGS_USAGE_INTERACTION_TIME, app.info, false);
            final long interactionThreshold = fgsInteractionChangeEnabled
                    ? mConstants.SERVICE_USAGE_INTERACTION_TIME_POST_S
                    : mConstants.SERVICE_USAGE_INTERACTION_TIME_PRE_S;
            // For foreground services that sit around for a long time but are not interacted with.
            // For foreground services that sit around for a long time but are not interacted with.
            if ((nowElapsed - state.getFgInteractionTime()) > interactionThreshold) {
                maybeUpdateUsageStatsLSP(app, nowElapsed);
                maybeUpdateUsageStatsLSP(app, nowElapsed);
            }
            }
        }


        if (state.getCurCapability() != state.getSetCapability()) {
        if (state.getCurCapability() != state.getSetCapability()) {
            changes |= ActivityManagerService.ProcessChangeItem.CHANGE_CAPABILITY;
            changes |= ActivityManagerService.ProcessChangeItem.CHANGE_CAPABILITY;
@@ -2877,6 +2921,8 @@ public final class OomAdjuster {
        if (mService.mUsageStatsService == null) {
        if (mService.mUsageStatsService == null) {
            return;
            return;
        }
        }
        final boolean fgsInteractionChangeEnabled = getPlatformCompatCache().isChangeEnabled(
                USE_SHORT_FGS_USAGE_INTERACTION_TIME, app.info, false);
        boolean isInteraction;
        boolean isInteraction;
        // To avoid some abuse patterns, we are going to be careful about what we consider
        // To avoid some abuse patterns, we are going to be careful about what we consider
        // to be an app interaction.  Being the top activity doesn't count while the display
        // to be an app interaction.  Being the top activity doesn't count while the display
@@ -2890,18 +2936,22 @@ public final class OomAdjuster {
                state.setFgInteractionTime(nowElapsed);
                state.setFgInteractionTime(nowElapsed);
                isInteraction = false;
                isInteraction = false;
            } else {
            } else {
                isInteraction = nowElapsed > state.getFgInteractionTime()
                final long interactionTime = fgsInteractionChangeEnabled
                        + mConstants.SERVICE_USAGE_INTERACTION_TIME;
                        ? mConstants.SERVICE_USAGE_INTERACTION_TIME_POST_S
                        : mConstants.SERVICE_USAGE_INTERACTION_TIME_PRE_S;
                isInteraction = nowElapsed > state.getFgInteractionTime() + interactionTime;
            }
            }
        } else {
        } else {
            isInteraction =
            isInteraction =
                    state.getCurProcState() <= PROCESS_STATE_IMPORTANT_FOREGROUND;
                    state.getCurProcState() <= PROCESS_STATE_IMPORTANT_FOREGROUND;
            state.setFgInteractionTime(0);
            state.setFgInteractionTime(0);
        }
        }
        final long interactionThreshold = fgsInteractionChangeEnabled
                ? mConstants.USAGE_STATS_INTERACTION_INTERVAL_POST_S
                : mConstants.USAGE_STATS_INTERACTION_INTERVAL_PRE_S;
        if (isInteraction
        if (isInteraction
                && (!state.hasReportedInteraction()
                && (!state.hasReportedInteraction()
                    || (nowElapsed - state.getInteractionEventTime())
                    || (nowElapsed - state.getInteractionEventTime()) > interactionThreshold)) {
                    > mConstants.USAGE_STATS_INTERACTION_INTERVAL)) {
            state.setInteractionEventTime(nowElapsed);
            state.setInteractionEventTime(nowElapsed);
            String[] packages = app.getPackageList();
            String[] packages = app.getPackageList();
            if (packages != null) {
            if (packages != null) {
+36 −5
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@ import android.app.ActivityManager;
import android.app.usage.UsageStatsManagerInternal;
import android.app.usage.UsageStatsManagerInternal;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManagerInternal;
import android.content.pm.PackageManagerInternal;


import com.android.server.LocalServices;
import com.android.server.LocalServices;
@@ -57,8 +58,36 @@ public class OomAdjusterTests {
    private ProcessRecord mProcessRecord;
    private ProcessRecord mProcessRecord;


    private static final long ZERO = 0L;
    private static final long ZERO = 0L;
    private static final long USAGE_STATS_INTERACTION = 2 * 60 * 60 * 1000L;
    private static final long USAGE_STATS_INTERACTION = 10 * 60 * 1000L;
    private static final long SERVICE_USAGE_INTERACTION = 30 * 60 * 1000;
    private static final long SERVICE_USAGE_INTERACTION = 60 * 1000;

    static class MyOomAdjuster extends OomAdjuster {

        private final PlatformCompatCache mPlatformCompatCache;

        MyOomAdjuster(ActivityManagerService service, ProcessList processList,
                ActiveUids activeUids) {
            super(service, processList, activeUids);
            mPlatformCompatCache = new MyPlatformCompatCache(new long[]{});
        }

        static class MyPlatformCompatCache extends PlatformCompatCache {

            MyPlatformCompatCache(long[] compatChanges) {
                super(compatChanges);
            }

            @Override
            boolean isChangeEnabled(long changeId, ApplicationInfo app, boolean defaultValue) {
                return true;
            }
        }

        @Override
        protected OomAdjuster.PlatformCompatCache getPlatformCompatCache() {
            return mPlatformCompatCache;
        }
    }


    @BeforeClass
    @BeforeClass
    public static void setUpOnce() {
    public static void setUpOnce() {
@@ -84,7 +113,7 @@ public class OomAdjusterTests {
            final AppProfiler profiler = mock(AppProfiler.class);
            final AppProfiler profiler = mock(AppProfiler.class);
            setFieldValue(AppProfiler.class, profiler, "mProfilerLock", new Object());
            setFieldValue(AppProfiler.class, profiler, "mProfilerLock", new Object());
            setFieldValue(ActivityManagerService.class, sService, "mAppProfiler", profiler);
            setFieldValue(ActivityManagerService.class, sService, "mAppProfiler", profiler);
            sService.mOomAdjuster = new OomAdjuster(sService, sService.mProcessList, null);
            sService.mOomAdjuster = new MyOomAdjuster(sService, sService.mProcessList, null);
            LocalServices.addService(UsageStatsManagerInternal.class,
            LocalServices.addService(UsageStatsManagerInternal.class,
                    mock(UsageStatsManagerInternal.class));
                    mock(UsageStatsManagerInternal.class));
            sService.mUsageStatsService = LocalServices.getService(UsageStatsManagerInternal.class);
            sService.mUsageStatsService = LocalServices.getService(UsageStatsManagerInternal.class);
@@ -119,8 +148,10 @@ public class OomAdjusterTests {


        // Ensure certain services and constants are defined properly
        // Ensure certain services and constants are defined properly
        assertNotNull(sService.mUsageStatsService);
        assertNotNull(sService.mUsageStatsService);
        assertEquals(USAGE_STATS_INTERACTION, sService.mConstants.USAGE_STATS_INTERACTION_INTERVAL);
        assertEquals(USAGE_STATS_INTERACTION,
        assertEquals(SERVICE_USAGE_INTERACTION, sService.mConstants.SERVICE_USAGE_INTERACTION_TIME);
                sService.mConstants.USAGE_STATS_INTERACTION_INTERVAL_POST_S);
        assertEquals(SERVICE_USAGE_INTERACTION,
                sService.mConstants.SERVICE_USAGE_INTERACTION_TIME_POST_S);
    }
    }


    @Test
    @Test