Update detector and action for restrict app
1. In detector, read data from database and display it. 2. Update the RestrictAppAction to mark anomaly as handled if restriction is toggled. 3. Update the RestrictAppTip to handle state change. Bug: 72385333 Test: RunSettingsRoboTests Change-Id: I0bbe6f6fd049bf2e7a2bee1dee08d5199f922e31
This commit is contained in:
@@ -71,7 +71,7 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
|
||||
tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
|
||||
tips.add(new EarlyWarningDetector(policy, context).detect());
|
||||
tips.add(new SummaryDetector(policy).detect());
|
||||
tips.add(new RestrictAppDetector(policy).detect());
|
||||
tips.add(new RestrictAppDetector(context, policy).detect());
|
||||
|
||||
Collections.sort(tips);
|
||||
return tips;
|
||||
|
@@ -21,7 +21,9 @@ import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
|
||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
|
||||
import java.util.List;
|
||||
@@ -32,12 +34,15 @@ import java.util.List;
|
||||
public class RestrictAppAction extends BatteryTipAction {
|
||||
private RestrictAppTip mRestrictAppTip;
|
||||
@VisibleForTesting
|
||||
BatteryDatabaseManager mBatteryDatabaseManager;
|
||||
@VisibleForTesting
|
||||
BatteryUtils mBatteryUtils;
|
||||
|
||||
public RestrictAppAction(Context context, RestrictAppTip tip) {
|
||||
super(context);
|
||||
mRestrictAppTip = tip;
|
||||
mBatteryUtils = BatteryUtils.getInstance(context);
|
||||
mBatteryDatabaseManager = new BatteryDatabaseManager(context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,5 +58,7 @@ public class RestrictAppAction extends BatteryTipAction {
|
||||
mBatteryUtils.setForceAppStandby(mBatteryUtils.getPackageUid(packageName), packageName,
|
||||
AppOpsManager.MODE_IGNORED);
|
||||
}
|
||||
|
||||
mBatteryDatabaseManager.updateAnomalies(appInfos, AnomalyDatabaseHelper.State.HANDLED);
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,13 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batterytip.detectors;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.format.DateUtils;
|
||||
|
||||
import com.android.settings.fuelgauge.batterytip.AnomalyDatabaseHelper;
|
||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryDatabaseManager;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
@@ -29,18 +35,47 @@ import java.util.List;
|
||||
* {@link BatteryTipDetector} since it need the most up-to-date {@code visibleTips}
|
||||
*/
|
||||
public class RestrictAppDetector implements BatteryTipDetector {
|
||||
@VisibleForTesting
|
||||
static final boolean USE_FAKE_DATA = false;
|
||||
private BatteryTipPolicy mPolicy;
|
||||
@VisibleForTesting
|
||||
BatteryDatabaseManager mBatteryDatabaseManager;
|
||||
|
||||
public RestrictAppDetector(BatteryTipPolicy policy) {
|
||||
public RestrictAppDetector(Context context, BatteryTipPolicy policy) {
|
||||
mPolicy = policy;
|
||||
mBatteryDatabaseManager = new BatteryDatabaseManager(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
// TODO(b/70570352): Detect restrict apps here, get data from database
|
||||
if (USE_FAKE_DATA) {
|
||||
return getFakeData();
|
||||
}
|
||||
if (mPolicy.appRestrictionEnabled) {
|
||||
// TODO(b/72385333): hook up the query timestamp to server side
|
||||
final long oneDayBeforeMs = System.currentTimeMillis() - DateUtils.DAY_IN_MILLIS;
|
||||
final List<AppInfo> highUsageApps = mBatteryDatabaseManager.queryAllAnomalies(
|
||||
oneDayBeforeMs, AnomalyDatabaseHelper.State.NEW);
|
||||
if (!highUsageApps.isEmpty()) {
|
||||
// If there are new anomalies, show them
|
||||
return new RestrictAppTip(BatteryTip.StateType.NEW, highUsageApps);
|
||||
} else {
|
||||
// Otherwise, show auto-handled one if it exists
|
||||
final List<AppInfo> autoHandledApps = mBatteryDatabaseManager.queryAllAnomalies(
|
||||
oneDayBeforeMs, AnomalyDatabaseHelper.State.AUTO_HANDLED);
|
||||
return new RestrictAppTip(autoHandledApps.isEmpty() ? BatteryTip.StateType.INVISIBLE
|
||||
: BatteryTip.StateType.HANDLED, autoHandledApps);
|
||||
}
|
||||
} else {
|
||||
return new RestrictAppTip(BatteryTip.StateType.INVISIBLE, new ArrayList<>());
|
||||
}
|
||||
}
|
||||
|
||||
private BatteryTip getFakeData() {
|
||||
final List<AppInfo> highUsageApps = new ArrayList<>();
|
||||
return new RestrictAppTip(
|
||||
highUsageApps.isEmpty() ? BatteryTip.StateType.INVISIBLE : BatteryTip.StateType.NEW,
|
||||
highUsageApps);
|
||||
highUsageApps.add(new AppInfo.Builder()
|
||||
.setPackageName("com.android.settings")
|
||||
.build());
|
||||
return new RestrictAppTip(BatteryTip.StateType.NEW, highUsageApps);
|
||||
}
|
||||
}
|
||||
|
@@ -81,7 +81,14 @@ public class RestrictAppTip extends BatteryTip {
|
||||
|
||||
@Override
|
||||
public void updateState(BatteryTip tip) {
|
||||
mState = tip.mState;
|
||||
if (tip.mState == StateType.NEW) {
|
||||
// Display it if new anomaly comes
|
||||
mState = StateType.NEW;
|
||||
mRestrictAppList = ((RestrictAppTip) tip).mRestrictAppList;
|
||||
} else if (mState == StateType.NEW && tip.mState == StateType.INVISIBLE) {
|
||||
// If anomaly becomes invisible, show it as handled
|
||||
mState = StateType.HANDLED;
|
||||
}
|
||||
}
|
||||
|
||||
public List<AppInfo> getRestrictAppList() {
|
||||
|
Reference in New Issue
Block a user