From aced6da68798c9fe9fc145a6fe070ea5f8a31304 Mon Sep 17 00:00:00 2001 From: Caitlin Shkuratov Date: Thu, 10 Nov 2022 20:38:34 +0000 Subject: [PATCH] [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 --- packages/SystemUI/res/values/strings.xml | 6 ++ .../systemui/battery/BatteryMeterView.java | 27 ++++--- .../systemui/battery/BatteryMeterViewTest.kt | 72 +++++++++++++++++++ 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 53cd059288e31..72641cc55497d 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -444,6 +444,12 @@ Battery charging, %d percent. + + Battery %d percent. Charging paused for battery protection. + + + Battery %1$d percent, about %2$s left based on your usage. Charging paused for battery protection. + See all notifications diff --git a/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java b/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java index b918655dbbb6c..1ab8453c61157 100644 --- a/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java +++ b/packages/SystemUI/src/com/android/systemui/battery/BatteryMeterView.java @@ -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 = diff --git a/packages/SystemUI/tests/src/com/android/systemui/battery/BatteryMeterViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/battery/BatteryMeterViewTest.kt index b38d0b787dbc8..eb7d9c3900f10 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/battery/BatteryMeterViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/battery/BatteryMeterViewTest.kt @@ -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)