Revert "Revert "Change battery tip text""
This reverts commit 39beb2533f
.
Reason for revert: <start to implement>
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: I83cc187d5bfda5312410e91ee636373f305ef449
This commit is contained in:
@@ -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.getBatteryTipStringFormatted(
|
||||||
|
context, PowerUtil.convertUsToMs(drainTimeUs));
|
||||||
} else {
|
} else {
|
||||||
info.remainingLabel = null;
|
info.remainingLabel = null;
|
||||||
|
info.suggestionLabel = null;
|
||||||
info.chargeLabel = info.batteryPercentString;
|
info.chargeLabel = info.batteryPercentString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -62,6 +62,6 @@ public class LowBatteryDetector implements BatteryTipDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new LowBatteryTip(
|
return new LowBatteryTip(
|
||||||
state, powerSaveModeOn, mBatteryInfo.remainingLabel);
|
state, powerSaveModeOn, mBatteryInfo.suggestionLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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
|
||||||
|
Reference in New Issue
Block a user