Merge changes Ifa91ad93,I14f9696a into pi-dev
* changes: Update the BatteryTipPolicy Update and expose the low battery tip.
This commit is contained in:
@@ -67,7 +67,7 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
|
||||
final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG);
|
||||
final Context context = getContext();
|
||||
|
||||
tips.add(new LowBatteryDetector(policy, batteryInfo).detect());
|
||||
tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
|
||||
tips.add(new HighUsageDetector(context, policy, mBatteryStatsHelper,
|
||||
batteryInfo.discharging).detect());
|
||||
tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
|
||||
@@ -87,7 +87,8 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
|
||||
final List<BatteryTip> tips = new ArrayList<>();
|
||||
tips.add(new SummaryTip(BatteryTip.StateType.NEW,
|
||||
Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
|
||||
tips.add(new LowBatteryTip(BatteryTip.StateType.NEW));
|
||||
tips.add(new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */,
|
||||
"Fake data"));
|
||||
|
||||
return tips;
|
||||
}
|
||||
|
@@ -50,6 +50,7 @@ public class BatteryTipPolicy {
|
||||
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";
|
||||
private static final String KEY_TEST_LOW_BATTERY_TIP = "test_low_battery_tip";
|
||||
|
||||
/**
|
||||
* {@code true} if general battery tip is enabled
|
||||
@@ -192,6 +193,14 @@ public class BatteryTipPolicy {
|
||||
*/
|
||||
public final boolean testSmartBatteryTip;
|
||||
|
||||
/**
|
||||
* {@code true} if we want to test low battery tip.
|
||||
*
|
||||
* @see Settings.Global#BATTERY_TIP_CONSTANTS
|
||||
* @see #KEY_TEST_LOW_BATTERY_TIP
|
||||
*/
|
||||
public final boolean testLowBatteryTip;
|
||||
|
||||
private final KeyValueListParser mParser;
|
||||
|
||||
public BatteryTipPolicy(Context context) {
|
||||
@@ -222,13 +231,14 @@ public class BatteryTipPolicy {
|
||||
reducedBatteryEnabled = mParser.getBoolean(KEY_REDUCED_BATTERY_ENABLED, false);
|
||||
reducedBatteryPercent = mParser.getInt(KEY_REDUCED_BATTERY_PERCENT, 50);
|
||||
lowBatteryEnabled = mParser.getBoolean(KEY_LOW_BATTERY_ENABLED, false);
|
||||
lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 16);
|
||||
lowBatteryHour = mParser.getInt(KEY_LOW_BATTERY_HOUR, 3);
|
||||
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);
|
||||
testLowBatteryTip = mParser.getBoolean(KEY_TEST_LOW_BATTERY_TIP, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,31 +16,52 @@
|
||||
|
||||
package com.android.settings.fuelgauge.batterytip.detectors;
|
||||
|
||||
import android.text.format.DateUtils;
|
||||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import com.android.settings.fuelgauge.BatteryInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Detect whether the battery is too low
|
||||
*/
|
||||
public class LowBatteryDetector implements BatteryTipDetector {
|
||||
private BatteryInfo mBatteryInfo;
|
||||
private BatteryTipPolicy mPolicy;
|
||||
private PowerManager mPowerManager;
|
||||
private int mWarningLevel;
|
||||
|
||||
public LowBatteryDetector(BatteryTipPolicy policy, BatteryInfo batteryInfo) {
|
||||
public LowBatteryDetector(Context context, BatteryTipPolicy policy, BatteryInfo batteryInfo) {
|
||||
mPolicy = policy;
|
||||
mBatteryInfo = batteryInfo;
|
||||
mPowerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
mWarningLevel = context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_lowBatteryWarningLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
// Show it if battery life is less than mPolicy.lowBatteryHour
|
||||
final boolean isShown = mPolicy.lowBatteryEnabled && mBatteryInfo.discharging
|
||||
&& mBatteryInfo.remainingTimeUs < mPolicy.lowBatteryHour * DateUtils.HOUR_IN_MILLIS;
|
||||
final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
|
||||
final boolean lowBattery = mBatteryInfo.batteryLevel <= mWarningLevel
|
||||
|| (mBatteryInfo.discharging
|
||||
&& mBatteryInfo.remainingTimeUs < TimeUnit.HOURS.toMicros(mPolicy.lowBatteryHour));
|
||||
|
||||
int state = BatteryTip.StateType.INVISIBLE;
|
||||
if (mPolicy.lowBatteryEnabled) {
|
||||
if (powerSaveModeOn) {
|
||||
// Show it is handled if battery saver is on
|
||||
state = BatteryTip.StateType.HANDLED;
|
||||
} else if (mPolicy.testLowBatteryTip || (mBatteryInfo.discharging && lowBattery)) {
|
||||
// Show it is new if in test or in discharging low battery state
|
||||
state = BatteryTip.StateType.NEW;
|
||||
}
|
||||
}
|
||||
|
||||
return new LowBatteryTip(
|
||||
isShown ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE);
|
||||
state, powerSaveModeOn, mBatteryInfo.remainingLabel);
|
||||
}
|
||||
}
|
||||
|
@@ -74,10 +74,10 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
TIP_ORDER.append(TipType.APP_RESTRICTION, 0);
|
||||
TIP_ORDER.append(TipType.BATTERY_SAVER, 1);
|
||||
TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 2);
|
||||
TIP_ORDER.append(TipType.SUMMARY, 3);
|
||||
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 4);
|
||||
TIP_ORDER.append(TipType.REDUCED_BATTERY, 5);
|
||||
TIP_ORDER.append(TipType.LOW_BATTERY, 6);
|
||||
TIP_ORDER.append(TipType.LOW_BATTERY, 3);
|
||||
TIP_ORDER.append(TipType.SUMMARY, 4);
|
||||
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 5);
|
||||
TIP_ORDER.append(TipType.REDUCED_BATTERY, 6);
|
||||
TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 7);
|
||||
}
|
||||
|
||||
|
@@ -25,36 +25,32 @@ import com.android.settings.R;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Tip to show current battery life is short
|
||||
* Tip to show current battery level is low or remaining time is less than a certain period
|
||||
*/
|
||||
public class LowBatteryTip extends BatteryTip {
|
||||
public class LowBatteryTip extends EarlyWarningTip {
|
||||
private CharSequence mSummary;
|
||||
|
||||
public LowBatteryTip(@StateType int state) {
|
||||
super(TipType.LOW_BATTERY, state, false /* showDialog */);
|
||||
public LowBatteryTip(@StateType int state, boolean powerSaveModeOn, CharSequence summary) {
|
||||
super(state, powerSaveModeOn);
|
||||
mType = TipType.LOW_BATTERY;
|
||||
mSummary = summary;
|
||||
}
|
||||
|
||||
private LowBatteryTip(Parcel in) {
|
||||
public LowBatteryTip(Parcel in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle(Context context) {
|
||||
return context.getString(R.string.battery_tip_low_battery_title);
|
||||
mSummary = in.readCharSequence();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary(Context context) {
|
||||
return context.getString(R.string.battery_tip_low_battery_summary);
|
||||
return mState == StateType.HANDLED ? context.getString(
|
||||
R.string.battery_tip_early_heads_up_done_summary) : mSummary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconId() {
|
||||
return R.drawable.ic_perm_device_information_red_24dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(BatteryTip tip) {
|
||||
mState = tip.mState;
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeCharSequence(mSummary);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user