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

Commit 2c75eb86 authored by Kweku Adams's avatar Kweku Adams
Browse files

Moving AppStandbyController to the module background thread.

Move AppStandbyController's handler to use the JS mainline module's
background thread looper to decouple it from the rest of the system and
from BackgroundThread.

Bug: 160873128
Test: atest CtsUsageStatsTestCases:UsageStatsTest
Test: atest FrameworksServicesTests:AppIdleHistoryTests
Test: atest FrameworksServicesTests:AppStandbyControllerTes
Change-Id: Ic64ccf6b4437060cb4ea83b1c5c6053421081ef8
parent 79d4a4c1
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ import android.app.usage.UsageEvents;
import android.app.usage.UsageStatsManager.StandbyBuckets;
import android.app.usage.UsageStatsManager.SystemForcedReasons;
import android.content.Context;
import android.os.Looper;
import android.util.IndentingPrintWriter;

import java.io.PrintWriter;
@@ -21,13 +20,12 @@ public interface AppStandbyInternal {
     * TODO AppStandbyController should probably be a binder service, and then we shouldn't need
     * this method.
     */
    static AppStandbyInternal newAppStandbyController(ClassLoader loader, Context context,
            Looper looper) {
    static AppStandbyInternal newAppStandbyController(ClassLoader loader, Context context) {
        try {
            final Class<?> clazz = Class.forName("com.android.server.usage.AppStandbyController",
                    true, loader);
            final Constructor<?> ctor =  clazz.getConstructor(Context.class, Looper.class);
            return (AppStandbyInternal) ctor.newInstance(context, looper);
            final Constructor<?> ctor =  clazz.getConstructor(Context.class);
            return (AppStandbyInternal) ctor.newInstance(context);
        } catch (NoSuchMethodException | InstantiationException
                | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
            throw new RuntimeException("Unable to instantiate AppStandbyController!", e);
+3 −2
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IBatteryStats;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.ConcurrentUtils;
import com.android.server.JobSchedulerBackgroundThread;
import com.android.server.LocalServices;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.usage.AppIdleHistory.AppUsageHistory;
@@ -418,8 +419,8 @@ public class AppStandbyController implements AppStandbyInternal {
        }
    }

    public AppStandbyController(Context context, Looper looper) {
        this(new Injector(context, looper));
    public AppStandbyController(Context context) {
        this(new Injector(context, JobSchedulerBackgroundThread.get().getLooper()));
    }

    AppStandbyController(Injector injector) {
+1 −2
Original line number Diff line number Diff line
@@ -215,8 +215,7 @@ public class UsageStatsService extends SystemService implements
        mHandler = new H(BackgroundThread.get().getLooper());

        mAppStandby = AppStandbyInternal.newAppStandbyController(
                UsageStatsService.class.getClassLoader(), getContext(),
                BackgroundThread.get().getLooper());
                UsageStatsService.class.getClassLoader(), getContext());

        mAppTimeLimit = new AppTimeLimitController(
                new AppTimeLimitController.TimeLimitCallbackListener() {