summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wesley Wang <wesleycwwang@google.com> 2022-02-25 00:24:55 +0800
committer Wesley Wang <wesleycwwang@google.com> 2022-02-28 16:18:12 +0000
commit0ab99c38f445619712942c86f2cd88a4b9ea9692 (patch)
tree9a8bffb71af15891dc0bd9018df6000f1460716c
parent17a66a2236e52dc055b57b543e2732a95aace308 (diff)
Update low battery notification mechanism
- Update warning and severe trigger percentage - Update low battery notification trigger condition to fixed value instead of remaining time - Update low battery notification text - Update start saver confirmation notification text - Use severe low battery dialog if available Screenshot: https://screenshot.googleplex.com/iZt43YU6fHQPNpy.png Bug: 207470943 Bug: 209932572 Test: atest SystemUITests Change-Id: I851e635e748a5315f9780a1344c2068cda14d95e
-rw-r--r--core/res/res/values/config.xml4
-rw-r--r--packages/SystemUI/res/values/config.xml3
-rw-r--r--packages/SystemUI/res/values/strings.xml8
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java43
-rw-r--r--packages/SystemUI/src/com/android/systemui/power/PowerUI.java26
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java6
6 files changed, 49 insertions, 41 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 5ac30de631c5..c2cb57d84b34 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -1207,13 +1207,13 @@
<!-- Display low battery warning when battery level dips to this value.
Also, the battery stats are flushed to disk when we hit this level. -->
- <integer name="config_criticalBatteryWarningLevel">5</integer>
+ <integer name="config_criticalBatteryWarningLevel">10</integer>
<!-- Shutdown if the battery temperature exceeds (this value * 0.1) Celsius. -->
<integer name="config_shutdownBatteryTemperature">680</integer>
<!-- Display low battery warning when battery level dips to this value -->
- <integer name="config_lowBatteryWarningLevel">15</integer>
+ <integer name="config_lowBatteryWarningLevel">20</integer>
<!-- The default suggested battery % at which we enable battery saver automatically. -->
<integer name="config_lowBatteryAutoTriggerDefaultLevel">15</integer>
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 178f93ae3c93..3ed217007081 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -482,6 +482,9 @@
space -->
<bool name="config_showBatteryEstimateQSBH">false</bool>
+ <!-- Whether to show a severe low battery dialog. -->
+ <bool name="config_severe_battery_dialog">false</bool>
+
<!-- A path similar to frameworks/base/core/res/res/values/config.xml
config_mainBuiltInDisplayCutout that describes a path larger than the exact path of a display
cutout. If present as well as config_enableDisplayCutoutProtection is set to true, then
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index df16b0d45228..27e188674006 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -21,7 +21,13 @@
<string name="app_label">System UI</string>
<!-- When the battery is low, this is displayed to the user in a dialog. The title of the low battery alert. [CHAR LIMIT=NONE]-->
- <string name="battery_low_title">Battery may run out soon</string>
+ <string name="battery_low_title">Turn on Battery Saver?</string>
+
+ <!-- When the battery is low, this is displayed to the user in a dialog. The description of the low battery alert. [CHAR LIMIT=NONE]-->
+ <string name="battery_low_description">You have <xliff:g id="percentage" example="20%">%s</xliff:g> battery left. Battery Saver turns on Dark theme, restricts background activity, and delays notifications.</string>
+
+ <!-- When the battery is low at first time, this is displayed to the user in a dialog. The description of the low battery alert. [CHAR LIMIT=NONE]-->
+ <string name="battery_low_intro">Battery Saver turns on Dark theme, restricts background activity, and delays notifications.</string>
<!-- A message that appears when the battery level is getting low in a dialog. This is
appended to the subtitle of the low battery alert. "percentage" is the percentage of battery
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
index dbd641bffe7e..039c33315741 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
@@ -118,6 +118,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
private static final String ACTION_AUTO_SAVER_NO_THANKS =
"PNW.autoSaverNoThanks";
+ private static final String ACTION_ENABLE_SEVERE_BATTERY_DIALOG = "PNW.enableSevereDialog";
+
private static final String SETTINGS_ACTION_OPEN_BATTERY_SAVER_SETTING =
"android.settings.BATTERY_SAVER_SETTINGS";
public static final String BATTERY_SAVER_SCHEDULE_SCREEN_INTENT_ACTION =
@@ -253,20 +255,25 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
}
protected void showWarningNotification() {
- final String percentage = NumberFormat.getPercentInstance()
- .format((double) mCurrentBatterySnapshot.getBatteryLevel() / 100.0);
-
- // get shared standard notification copy
- String title = mContext.getString(R.string.battery_low_title);
- String contentText;
-
- // get correct content text if notification is hybrid or not
- if (mCurrentBatterySnapshot.isHybrid()) {
- contentText = getHybridContentString(percentage);
- } else {
- contentText = mContext.getString(R.string.battery_low_percent_format, percentage);
+ if (showSevereLowBatteryDialog()) {
+ mContext.sendBroadcast(new Intent(ACTION_ENABLE_SEVERE_BATTERY_DIALOG)
+ .setPackage(mContext.getPackageName())
+ .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
+ | Intent.FLAG_RECEIVER_FOREGROUND));
+ // Reset the state once dialog been enabled
+ dismissLowBatteryNotification();
+ mPlaySound = false;
+ return;
}
+ final int warningLevel = mContext.getResources().getInteger(
+ com.android.internal.R.integer.config_lowBatteryWarningLevel);
+ final String percentage = NumberFormat.getPercentInstance()
+ .format((double) warningLevel / 100.0);
+ final String title = mContext.getString(R.string.battery_low_title);
+ final String contentText = mContext.getString(
+ R.string.battery_low_description, percentage);
+
final Notification.Builder nb =
new Notification.Builder(mContext, NotificationChannels.BATTERY)
.setSmallIcon(R.drawable.ic_power_low)
@@ -284,7 +291,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
}
// Make the notification red if the percentage goes below a certain amount or the time
// remaining estimate is disabled
- if (!mCurrentBatterySnapshot.isHybrid() || mBucket < 0
+ if (!mCurrentBatterySnapshot.isHybrid() || mBucket < -1
|| mCurrentBatterySnapshot.getTimeRemainingMillis()
< mCurrentBatterySnapshot.getSevereThresholdMillis()) {
nb.setColor(Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorError));
@@ -303,6 +310,13 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
mNoMan.notifyAsUser(TAG_BATTERY, SystemMessage.NOTE_POWER_LOW, n, UserHandle.ALL);
}
+ private boolean showSevereLowBatteryDialog() {
+ final boolean isSevereState = !mCurrentBatterySnapshot.isHybrid() || mBucket < -1;
+ final boolean useSevereDialog = mContext.getResources().getBoolean(
+ R.bool.config_severe_battery_dialog);
+ return isSevereState && useSevereDialog;
+ }
+
private void showAutoSaverSuggestionNotification() {
final CharSequence message = mContext.getString(R.string.auto_saver_text);
final Notification.Builder nb =
@@ -662,8 +676,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
// If there's no link, use the string with no "learn more".
if (TextUtils.isEmpty(learnMoreUrl)) {
- return mContext.getText(
- com.android.internal.R.string.battery_saver_description);
+ return mContext.getText(R.string.battery_low_intro);
}
// If we have a link, use the string with the "learn more" link.
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
index 642af593c211..81ec5844f4ac 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerUI.java
@@ -69,7 +69,7 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks {
private static final long TEMPERATURE_LOGGING_INTERVAL = DateUtils.HOUR_IN_MILLIS;
private static final int MAX_RECENT_TEMPS = 125; // TEMPERATURE_LOGGING_INTERVAL plus a buffer
static final long THREE_HOURS_IN_MILLIS = DateUtils.HOUR_IN_MILLIS * 3;
- private static final int CHARGE_CYCLE_PERCENT_RESET = 45;
+ private static final int CHARGE_CYCLE_PERCENT_RESET = 30;
private static final long SIX_HOURS_MILLIS = Duration.ofHours(6).toMillis();
public static final int NO_ESTIMATE_AVAILABLE = -1;
private static final String BOOT_COUNT_KEY = "boot_count";
@@ -206,7 +206,8 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks {
*
* 1 means that the battery is "ok"
* 0 means that the battery is between "ok" and what we should warn about.
- * less than 0 means that the battery is low
+ * less than 0 means that the battery is low, -1 means the battery is reaching warning level,
+ * -2 means the battery is reaching severe level.
*/
private int findBatteryLevelBucket(int level) {
if (level >= mLowBatteryAlertCloseLevel) {
@@ -388,12 +389,8 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks {
@VisibleForTesting
void maybeShowHybridWarning(BatteryStateSnapshot currentSnapshot,
BatteryStateSnapshot lastSnapshot) {
- // if we are now over 45% battery & 6 hours remaining so we can trigger hybrid
- // notification again
- final long timeRemainingMillis = currentSnapshot.getTimeRemainingMillis();
- if (currentSnapshot.getBatteryLevel() >= CHARGE_CYCLE_PERCENT_RESET
- && (timeRemainingMillis > SIX_HOURS_MILLIS
- || timeRemainingMillis == NO_ESTIMATE_AVAILABLE)) {
+ // if we are now over 30% battery, we can trigger hybrid notification again
+ if (currentSnapshot.getBatteryLevel() >= CHARGE_CYCLE_PERCENT_RESET) {
mLowWarningShownThisChargeCycle = false;
mSevereWarningShownThisChargeCycle = false;
if (DEBUG) {
@@ -403,6 +400,7 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks {
final boolean playSound = currentSnapshot.getBucket() != lastSnapshot.getBucket()
|| lastSnapshot.getPlugged();
+ final long timeRemainingMillis = currentSnapshot.getTimeRemainingMillis();
if (shouldShowHybridWarning(currentSnapshot)) {
mWarnings.showLowBatteryWarning(playSound);
@@ -444,19 +442,13 @@ public class PowerUI extends CoreStartable implements CommandQueue.Callbacks {
return false;
}
- final long timeRemainingMillis = snapshot.getTimeRemainingMillis();
// Only show the low warning if enabled once per charge cycle & no battery saver
- final boolean canShowWarning = snapshot.isLowWarningEnabled()
- && !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver()
- && ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
- && timeRemainingMillis < snapshot.getLowThresholdMillis())
- || snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold());
+ final boolean canShowWarning = !mLowWarningShownThisChargeCycle && !snapshot.isPowerSaver()
+ && snapshot.getBatteryLevel() <= snapshot.getLowLevelThreshold();
// Only show the severe warning once per charge cycle
final boolean canShowSevereWarning = !mSevereWarningShownThisChargeCycle
- && ((timeRemainingMillis != NO_ESTIMATE_AVAILABLE
- && timeRemainingMillis < snapshot.getSevereThresholdMillis())
- || snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold());
+ && snapshot.getBatteryLevel() <= snapshot.getSevereLevelThreshold();
final boolean canShow = canShowWarning || canShowSevereWarning;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
index 721809c83cd8..533048abd6df 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerUITest.java
@@ -430,12 +430,6 @@ public class PowerUITest extends SysuiTestCase {
state.mIsPowerSaver = true;
shouldShow = mPowerUI.shouldShowHybridWarning(state.get());
assertThat(shouldShow).isFalse();
-
- state.mIsPowerSaver = false;
- // if disabled we should not show the low warning.
- state.mIsLowLevelWarningEnabled = false;
- shouldShow = mPowerUI.shouldShowHybridWarning(state.get());
- assertThat(shouldShow).isFalse();
}
@Test