[Dock Defend] Udpate the content description to account for dock defend
if needed. Bug: 255625888 Test: manual: Verify battery content description in all states Test: atest BatteryMeterViewTest Change-Id: I497c14096da2693cc35bf01d76287c021ddc3bf8
This commit is contained in:
@@ -444,6 +444,12 @@
|
||||
<!-- Content description of the battery level icon for accessibility while the device is charging (not shown on the screen). [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_battery_level_charging">Battery charging, <xliff:g id="battery_percentage">%d</xliff:g> percent.</string>
|
||||
|
||||
<!-- Content description of the battery level icon for accessibility, with information that the device charging is paused in order to protect the lifetime of the battery (not shown on screen). [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_battery_level_charging_paused">Battery <xliff:g id="percentage" example="90%">%d</xliff:g> percent. Charging paused for battery protection.</string>
|
||||
|
||||
<!-- Content description of the battery level icon for accessibility, including the estimated time remaining before the phone runs out of battery *and* information that the device charging is paused in order to protect the lifetime of the battery (not shown on screen). [CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_battery_level_charging_paused_with_estimate">Battery <xliff:g id="percentage" example="90%">%1$d</xliff:g> percent, about <xliff:g id="time" example="Until 3:15pm">%2$s</xliff:g> left based on your usage. Charging paused for battery protection.</string>
|
||||
|
||||
<!-- Content description of overflow icon container of the notifications for accessibility (not shown on the screen)[CHAR LIMIT=NONE] -->
|
||||
<string name="accessibility_overflow_action">See all notifications</string>
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
|
||||
private boolean mShowPercentAvailable;
|
||||
private String mEstimateText = null;
|
||||
private boolean mCharging;
|
||||
private boolean mDisplayShield;
|
||||
private boolean mIsOverheated;
|
||||
private boolean mDisplayShieldEnabled;
|
||||
// Error state where we know nothing about the current battery state
|
||||
private boolean mBatteryStateUnknown;
|
||||
@@ -207,16 +207,14 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
|
||||
}
|
||||
|
||||
void onIsOverheatedChanged(boolean isOverheated) {
|
||||
// The battery drawable is a different size depending on whether it's currently overheated
|
||||
// or not, so we need to re-scale the view when overheated changes.
|
||||
boolean requiresScaling = mDisplayShield != isOverheated;
|
||||
// If the battery is marked as overheated, we should display a shield indicating that the
|
||||
// battery is being "defended".
|
||||
mDisplayShield = isOverheated;
|
||||
if (requiresScaling) {
|
||||
boolean valueChanged = mIsOverheated != isOverheated;
|
||||
mIsOverheated = isOverheated;
|
||||
if (valueChanged) {
|
||||
updateContentDescription();
|
||||
// The battery drawable is a different size depending on whether it's currently
|
||||
// overheated or not, so we need to re-scale the view when overheated changes.
|
||||
scaleBatteryMeterViews();
|
||||
}
|
||||
// TODO(b/255625888): We should also update the content description.
|
||||
}
|
||||
|
||||
private TextView loadPercentView() {
|
||||
@@ -303,9 +301,14 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
|
||||
contentDescription = context.getString(R.string.accessibility_battery_unknown);
|
||||
} else if (mShowPercentMode == MODE_ESTIMATE && !TextUtils.isEmpty(mEstimateText)) {
|
||||
contentDescription = context.getString(
|
||||
R.string.accessibility_battery_level_with_estimate,
|
||||
mIsOverheated
|
||||
? R.string.accessibility_battery_level_charging_paused_with_estimate
|
||||
: R.string.accessibility_battery_level_with_estimate,
|
||||
mLevel,
|
||||
mEstimateText);
|
||||
} else if (mIsOverheated) {
|
||||
contentDescription =
|
||||
context.getString(R.string.accessibility_battery_level_charging_paused, mLevel);
|
||||
} else if (mCharging) {
|
||||
contentDescription =
|
||||
context.getString(R.string.accessibility_battery_level_charging, mLevel);
|
||||
@@ -390,7 +393,9 @@ public class BatteryMeterView extends LinearLayout implements DarkReceiver {
|
||||
float mainBatteryWidth =
|
||||
res.getDimensionPixelSize(R.dimen.status_bar_battery_icon_width) * iconScaleFactor;
|
||||
|
||||
boolean displayShield = mDisplayShieldEnabled && mDisplayShield;
|
||||
// If the battery is marked as overheated, we should display a shield indicating that the
|
||||
// battery is being "defended".
|
||||
boolean displayShield = mDisplayShieldEnabled && mIsOverheated;
|
||||
float fullBatteryIconHeight =
|
||||
BatterySpecs.getFullBatteryHeight(mainBatteryHeight, displayShield);
|
||||
float fullBatteryIconWidth =
|
||||
|
||||
@@ -84,6 +84,34 @@ class BatteryMeterViewTest : SysuiTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentDescription_estimateAndOverheated() {
|
||||
mBatteryMeterView.onBatteryLevelChanged(17, false)
|
||||
mBatteryMeterView.onIsOverheatedChanged(true)
|
||||
mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_ESTIMATE)
|
||||
mBatteryMeterView.setBatteryEstimateFetcher(Fetcher())
|
||||
|
||||
mBatteryMeterView.updatePercentText()
|
||||
|
||||
assertThat(mBatteryMeterView.contentDescription).isEqualTo(
|
||||
context.getString(
|
||||
R.string.accessibility_battery_level_charging_paused_with_estimate,
|
||||
17,
|
||||
ESTIMATE,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentDescription_overheated() {
|
||||
mBatteryMeterView.onBatteryLevelChanged(90, false)
|
||||
mBatteryMeterView.onIsOverheatedChanged(true)
|
||||
|
||||
assertThat(mBatteryMeterView.contentDescription).isEqualTo(
|
||||
context.getString(R.string.accessibility_battery_level_charging_paused, 90)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentDescription_charging() {
|
||||
mBatteryMeterView.onBatteryLevelChanged(45, true)
|
||||
@@ -125,6 +153,50 @@ class BatteryMeterViewTest : SysuiTestCase() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun contentDescription_manyUpdates_alwaysUpdated() {
|
||||
// Overheated
|
||||
mBatteryMeterView.onBatteryLevelChanged(90, false)
|
||||
mBatteryMeterView.onIsOverheatedChanged(true)
|
||||
assertThat(mBatteryMeterView.contentDescription).isEqualTo(
|
||||
context.getString(R.string.accessibility_battery_level_charging_paused, 90)
|
||||
)
|
||||
|
||||
// Overheated & estimate
|
||||
mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_ESTIMATE)
|
||||
mBatteryMeterView.setBatteryEstimateFetcher(Fetcher())
|
||||
mBatteryMeterView.updatePercentText()
|
||||
assertThat(mBatteryMeterView.contentDescription).isEqualTo(
|
||||
context.getString(
|
||||
R.string.accessibility_battery_level_charging_paused_with_estimate,
|
||||
90,
|
||||
ESTIMATE,
|
||||
)
|
||||
)
|
||||
|
||||
// Just estimate
|
||||
mBatteryMeterView.onIsOverheatedChanged(false)
|
||||
assertThat(mBatteryMeterView.contentDescription).isEqualTo(
|
||||
context.getString(
|
||||
R.string.accessibility_battery_level_with_estimate,
|
||||
90,
|
||||
ESTIMATE,
|
||||
)
|
||||
)
|
||||
|
||||
// Just percent
|
||||
mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_ON)
|
||||
assertThat(mBatteryMeterView.contentDescription).isEqualTo(
|
||||
context.getString(R.string.accessibility_battery_level, 90)
|
||||
)
|
||||
|
||||
// Charging
|
||||
mBatteryMeterView.onBatteryLevelChanged(90, true)
|
||||
assertThat(mBatteryMeterView.contentDescription).isEqualTo(
|
||||
context.getString(R.string.accessibility_battery_level_charging, 90)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isOverheatedChanged_true_drawableGetsTrue() {
|
||||
mBatteryMeterView.setDisplayShieldEnabled(true)
|
||||
|
||||
Reference in New Issue
Block a user