Merge "Make app predicates singleton"
This commit is contained in:
committed by
Android (Google) Code Review
commit
39bb6cec3e
@@ -136,8 +136,8 @@ public class BatteryTipUtils {
|
||||
final List<AppInfo> highUsageApps = BatteryDatabaseManager.getInstance(context)
|
||||
.queryAllAnomalies(timeAfterMs, AnomalyDatabaseHelper.State.NEW);
|
||||
// Remove it if it doesn't have label or been restricted
|
||||
highUsageApps.removeIf(
|
||||
new AppLabelPredicate(context).or(new AppRestrictionPredicate(context)));
|
||||
highUsageApps.removeIf(AppLabelPredicate.getInstance(context)
|
||||
.or(AppRestrictionPredicate.getInstance(context)));
|
||||
|
||||
return highUsageApps;
|
||||
}
|
||||
|
@@ -54,8 +54,8 @@ public class RestrictAppDetector implements BatteryTipDetector {
|
||||
mContext = context;
|
||||
mPolicy = policy;
|
||||
mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(context);
|
||||
mAppRestrictionPredicate = new AppRestrictionPredicate(context);
|
||||
mAppLabelPredicate = new AppLabelPredicate(context);
|
||||
mAppRestrictionPredicate = AppRestrictionPredicate.getInstance(context);
|
||||
mAppLabelPredicate = AppLabelPredicate.getInstance(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batterytip.tips;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
@@ -28,12 +27,20 @@ import java.util.function.Predicate;
|
||||
* {@link Predicate} for {@link AppInfo} to check whether it has label
|
||||
*/
|
||||
public class AppLabelPredicate implements Predicate<AppInfo> {
|
||||
private Context mContext;
|
||||
private AppOpsManager mAppOpsManager;
|
||||
|
||||
public AppLabelPredicate(Context context) {
|
||||
private static AppLabelPredicate sInstance;
|
||||
private Context mContext;
|
||||
|
||||
public static AppLabelPredicate getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AppLabelPredicate(context.getApplicationContext());
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private AppLabelPredicate(Context context) {
|
||||
mContext = context;
|
||||
mAppOpsManager = context.getSystemService(AppOpsManager.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -27,9 +27,19 @@ import java.util.function.Predicate;
|
||||
* {@link Predicate} for {@link AppInfo} to check whether it is restricted.
|
||||
*/
|
||||
public class AppRestrictionPredicate implements Predicate<AppInfo> {
|
||||
|
||||
private static AppRestrictionPredicate sInstance;
|
||||
private AppOpsManager mAppOpsManager;
|
||||
|
||||
public AppRestrictionPredicate(Context context) {
|
||||
public static AppRestrictionPredicate getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AppRestrictionPredicate(context.getApplicationContext());
|
||||
}
|
||||
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private AppRestrictionPredicate(Context context) {
|
||||
mAppOpsManager = context.getSystemService(AppOpsManager.class);
|
||||
}
|
||||
|
||||
|
@@ -112,7 +112,7 @@ public class RestrictAppTip extends BatteryTip {
|
||||
super.sanityCheck(context);
|
||||
|
||||
// Set it invisible if there is no valid app
|
||||
mRestrictAppList.removeIf(new AppLabelPredicate(context));
|
||||
mRestrictAppList.removeIf(AppLabelPredicate.getInstance(context));
|
||||
if (mRestrictAppList.isEmpty()) {
|
||||
mState = StateType.INVISIBLE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user