Change battery tip text

Fixes: 121042353
Test: adb shell settings put global battery_tip_constants test_low_battery_tip=true
      Then go to Settings -> battery to see the text
Change-Id: Ie3c4a89ccb7c2724840dc886a502ef919e13a856
This commit is contained in:
Raff Tsai
2019-03-06 10:27:42 +08:00
parent 131eeac4aa
commit 2441b94c6d
3 changed files with 23 additions and 1 deletions

View File

@@ -47,6 +47,7 @@ public class BatteryInfo {
public long averageTimeToDischarge = Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN; public long averageTimeToDischarge = Estimate.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN;
public String batteryPercentString; public String batteryPercentString;
public String statusLabel; public String statusLabel;
public String suggestionLabel;
private boolean mCharging; private boolean mCharging;
private BatteryStats mStats; private BatteryStats mStats;
private static final String LOG_TAG = "BatteryInfo"; private static final String LOG_TAG = "BatteryInfo";
@@ -247,6 +248,7 @@ public class BatteryInfo {
final int status = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS, final int status = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_STATUS,
BatteryManager.BATTERY_STATUS_UNKNOWN); BatteryManager.BATTERY_STATUS_UNKNOWN);
info.discharging = false; info.discharging = false;
info.suggestionLabel = null;
if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) { if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
info.remainingTimeUs = chargeTime; info.remainingTimeUs = chargeTime;
CharSequence timeString = StringUtil.formatElapsedTime(context, CharSequence timeString = StringUtil.formatElapsedTime(context,
@@ -282,8 +284,11 @@ public class BatteryInfo {
info.batteryPercentString, info.batteryPercentString,
estimate.isBasedOnUsage && !shortString estimate.isBasedOnUsage && !shortString
); );
info.suggestionLabel = PowerUtil.getBatterySuggestionStringFormatted(
context, PowerUtil.convertUsToMs(drainTimeUs));
} else { } else {
info.remainingLabel = null; info.remainingLabel = null;
info.suggestionLabel = null;
info.chargeLabel = info.batteryPercentString; info.chargeLabel = info.batteryPercentString;
} }
} }

View File

@@ -62,6 +62,6 @@ public class LowBatteryDetector implements BatteryTipDetector {
} }
return new LowBatteryTip( return new LowBatteryTip(
state, powerSaveModeOn, mBatteryInfo.remainingLabel); state, powerSaveModeOn, mBatteryInfo.suggestionLabel);
} }
} }

View File

@@ -65,7 +65,9 @@ public class BatteryInfoTest {
private static final String STATUS_NOT_CHARGING = "Not charging"; private static final String STATUS_NOT_CHARGING = "Not charging";
private static final long REMAINING_TIME_NULL = -1; private static final long REMAINING_TIME_NULL = -1;
private static final long REMAINING_TIME = 2; private static final long REMAINING_TIME = 2;
// Strings are defined in frameworks/base/packages/SettingsLib/res/values/strings.xml
private static final String ENHANCED_STRING_SUFFIX = "based on your usage"; private static final String ENHANCED_STRING_SUFFIX = "based on your usage";
private static final String EXTEND_PREFIX = "Extend battery life past";
private static final long TEST_CHARGE_TIME_REMAINING = TimeUnit.MINUTES.toMicros(1); private static final long TEST_CHARGE_TIME_REMAINING = TimeUnit.MINUTES.toMicros(1);
private static final String TEST_CHARGE_TIME_REMAINING_STRINGIFIED = private static final String TEST_CHARGE_TIME_REMAINING_STRINGIFIED =
"1 min left until fully charged"; "1 min left until fully charged";
@@ -148,8 +150,10 @@ public class BatteryInfoTest {
// We only add special mention for the long string // We only add special mention for the long string
assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX); assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
assertThat(info.suggestionLabel).contains(EXTEND_PREFIX);
// shortened string should not have extra text // shortened string should not have extra text
assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX); assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
assertThat(info2.suggestionLabel).contains(EXTEND_PREFIX);
} }
@Test @Test
@@ -169,6 +173,19 @@ public class BatteryInfoTest {
mContext.getString(R.string.power_remaining_duration_only_shutdown_imminent)); mContext.getString(R.string.power_remaining_duration_only_shutdown_imminent));
assertThat(info2.remainingLabel.toString()).isEqualTo( assertThat(info2.remainingLabel.toString()).isEqualTo(
mContext.getString(R.string.power_remaining_duration_only_shutdown_imminent)); mContext.getString(R.string.power_remaining_duration_only_shutdown_imminent));
assertThat(info2.suggestionLabel).contains(EXTEND_PREFIX);
}
@Test
public void getBatteryInfo_MoreThanOneDay_suggestionLabelIsCorrectString() {
Estimate estimate = new Estimate(Duration.ofDays(3).toMillis(),
true /* isBasedOnUsage */,
1000 /* averageDischargeTime */);
BatteryInfo info = BatteryInfo.getBatteryInfo(mContext, mDisChargingBatteryBroadcast,
mBatteryStats, estimate, SystemClock.elapsedRealtime() * 1000,
false /* shortString */);
assertThat(info.suggestionLabel).doesNotContain(EXTEND_PREFIX);
} }
@Test @Test