Hide uninstalled app in restrict app dialog

Change-Id: Ic615d8b1150890e6ad0d393e410d0f5ab8648986
Fixes: 77429442
Test: RunSettingsRoboTests
This commit is contained in:
Lei Yu
2018-04-02 18:08:03 -07:00
parent cf60ff7e08
commit 499644b8a9
2 changed files with 57 additions and 9 deletions

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.support.annotation.VisibleForTesting;
import android.text.format.DateUtils;
import com.android.settings.Utils;
import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
import com.android.settings.fuelgauge.batterytip.AppInfo;
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
@@ -29,6 +30,7 @@ import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
/**
* Detector whether to show summary tip. This detector should be executed as the last
@@ -40,8 +42,17 @@ public class RestrictAppDetector implements BatteryTipDetector {
private BatteryTipPolicy mPolicy;
@VisibleForTesting
BatteryDatabaseManager mBatteryDatabaseManager;
private Context mContext;
private Predicate<AppInfo> mAppInfoPredicate = new Predicate<AppInfo>() {
@Override
public boolean test(AppInfo appInfo) {
return Utils.getApplicationLabel(mContext, appInfo.packageName) == null;
}
};
public RestrictAppDetector(Context context, BatteryTipPolicy policy) {
mContext = context;
mPolicy = policy;
mBatteryDatabaseManager = BatteryDatabaseManager.getInstance(context);
}
@@ -56,6 +67,7 @@ public class RestrictAppDetector implements BatteryTipDetector {
final long oneDayBeforeMs = System.currentTimeMillis() - DateUtils.DAY_IN_MILLIS;
final List<AppInfo> highUsageApps = mBatteryDatabaseManager.queryAllAnomalies(
oneDayBeforeMs, AnomalyDatabaseHelper.State.NEW);
highUsageApps.removeIf(mAppInfoPredicate);
if (!highUsageApps.isEmpty()) {
// If there are new anomalies, show them
return new RestrictAppTip(BatteryTip.StateType.NEW, highUsageApps);
@@ -63,6 +75,7 @@ public class RestrictAppDetector implements BatteryTipDetector {
// Otherwise, show auto-handled one if it exists
final List<AppInfo> autoHandledApps = mBatteryDatabaseManager.queryAllAnomalies(
oneDayBeforeMs, AnomalyDatabaseHelper.State.AUTO_HANDLED);
autoHandledApps.removeIf(mAppInfoPredicate);
return new RestrictAppTip(autoHandledApps.isEmpty() ? BatteryTip.StateType.INVISIBLE
: BatteryTip.StateType.HANDLED, autoHandledApps);
}