Merge "Add test flags for battery tips." into pi-dev
This commit is contained in:
@@ -47,6 +47,10 @@ public class BatteryTipPolicy {
|
||||
private static final String KEY_DATA_HISTORY_RETAIN_DAY = "data_history_retain_day";
|
||||
private static final String KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE = "excessive_bg_drain_percentage";
|
||||
|
||||
private static final String KEY_TEST_BATTERY_SAVER_TIP = "test_battery_saver_tip";
|
||||
private static final String KEY_TEST_HIGH_USAGE_TIP = "test_high_usage_tip";
|
||||
private static final String KEY_TEST_SMART_BATTERY_TIP = "test_smart_battery_tip";
|
||||
|
||||
/**
|
||||
* {@code true} if general battery tip is enabled
|
||||
*
|
||||
@@ -164,6 +168,30 @@ public class BatteryTipPolicy {
|
||||
*/
|
||||
public final int excessiveBgDrainPercentage;
|
||||
|
||||
/**
|
||||
* {@code true} if we want to test battery saver tip.
|
||||
*
|
||||
* @see Settings.Global#BATTERY_TIP_CONSTANTS
|
||||
* @see #KEY_TEST_BATTERY_SAVER_TIP
|
||||
*/
|
||||
public final boolean testBatterySaverTip;
|
||||
|
||||
/**
|
||||
* {@code true} if we want to test high usage tip.
|
||||
*
|
||||
* @see Settings.Global#BATTERY_TIP_CONSTANTS
|
||||
* @see #KEY_TEST_HIGH_USAGE_TIP
|
||||
*/
|
||||
public final boolean testHighUsageTip;
|
||||
|
||||
/**
|
||||
* {@code true} if we want to test smart battery tip.
|
||||
*
|
||||
* @see Settings.Global#BATTERY_TIP_CONSTANTS
|
||||
* @see #KEY_TEST_SMART_BATTERY_TIP
|
||||
*/
|
||||
public final boolean testSmartBatteryTip;
|
||||
|
||||
private final KeyValueListParser mParser;
|
||||
|
||||
public BatteryTipPolicy(Context context) {
|
||||
@@ -197,6 +225,10 @@ public class BatteryTipPolicy {
|
||||
lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 16);
|
||||
dataHistoryRetainDay = mParser.getInt(KEY_DATA_HISTORY_RETAIN_DAY, 30);
|
||||
excessiveBgDrainPercentage = mParser.getInt(KEY_EXCESSIVE_BG_DRAIN_PERCENTAGE, 10);
|
||||
|
||||
testBatterySaverTip = mParser.getBoolean(KEY_TEST_BATTERY_SAVER_TIP, false);
|
||||
testHighUsageTip = mParser.getBoolean(KEY_TEST_HIGH_USAGE_TIP, false);
|
||||
testSmartBatteryTip = mParser.getBoolean(KEY_TEST_SMART_BATTERY_TIP, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ public class EarlyWarningDetector implements BatteryTipDetector {
|
||||
batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
|
||||
final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
|
||||
final boolean earlyWarning = mPowerUsageFeatureProvider.getEarlyWarningSignal(mContext,
|
||||
EarlyWarningDetector.class.getName());
|
||||
EarlyWarningDetector.class.getName()) || mPolicy.testBatterySaverTip;
|
||||
|
||||
final int state = powerSaveModeOn
|
||||
? BatteryTip.StateType.HANDLED
|
||||
|
@@ -34,6 +34,7 @@ import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Detector whether to show summary tip. This detector should be executed as the last
|
||||
@@ -65,7 +66,7 @@ public class HighUsageDetector implements BatteryTipDetector {
|
||||
final long screenUsageTimeMs = mBatteryUtils.calculateScreenUsageTime(mBatteryStatsHelper);
|
||||
if (mPolicy.highUsageEnabled) {
|
||||
parseBatteryData();
|
||||
if (mDataParser.isDeviceHeavilyUsed()) {
|
||||
if (mDataParser.isDeviceHeavilyUsed() || mPolicy.testHighUsageTip) {
|
||||
final List<BatterySipper> batterySippers = mBatteryStatsHelper.getUsageList();
|
||||
for (int i = 0, size = batterySippers.size(); i < size; i++) {
|
||||
final BatterySipper batterySipper = batterySippers.get(i);
|
||||
@@ -84,6 +85,14 @@ public class HighUsageDetector implements BatteryTipDetector {
|
||||
}
|
||||
}
|
||||
|
||||
// When in test mode, add an app if necessary
|
||||
if (mPolicy.testHighUsageTip && mHighUsageAppList.isEmpty()) {
|
||||
mHighUsageAppList.add(new AppInfo.Builder()
|
||||
.setPackageName("com.android.settings")
|
||||
.setScreenOnTimeMs(TimeUnit.HOURS.toMillis(3))
|
||||
.build());
|
||||
}
|
||||
|
||||
Collections.sort(mHighUsageAppList, Collections.reverseOrder());
|
||||
mHighUsageAppList = mHighUsageAppList.subList(0,
|
||||
Math.min(mPolicy.highUsageAppCount, mHighUsageAppList.size()));
|
||||
|
@@ -38,10 +38,10 @@ public class SmartBatteryDetector implements BatteryTipDetector {
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
// Show it if there is no other tips shown
|
||||
final boolean smartBatteryOn = Settings.Global.getInt(mContentResolver,
|
||||
Settings.Global.APP_STANDBY_ENABLED, 1) != 0;
|
||||
final boolean smartBatteryOff = Settings.Global.getInt(mContentResolver,
|
||||
Settings.Global.APP_STANDBY_ENABLED, 1) == 0 || mPolicy.testSmartBatteryTip;
|
||||
final int state =
|
||||
smartBatteryOn ? BatteryTip.StateType.INVISIBLE : BatteryTip.StateType.NEW;
|
||||
smartBatteryOff ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
|
||||
return new SmartBatteryTip(state);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user