Merge "Moving AppStandbyController to the module background thread."

This commit is contained in:
TreeHugger Robot
2020-07-16 01:35:39 +00:00
committed by Android (Google) Code Review
3 changed files with 7 additions and 9 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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() {