Merge "Adding new strings for battery saver sticky off notification."
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 370cd72..79bf738 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -5320,6 +5320,21 @@
<string name="battery_saver_sticky_disabled_notification_title">Battery Saver won\u2019t reactivate until battery low again</string>
<!-- Summary of notification letting users know why battery saver didn't turn back on automatically after the device was unplugged [CHAR_LIMIT=NONE] -->
<string name="battery_saver_sticky_disabled_notification_summary">Battery has been charged to a sufficient level. Battery Saver won\u2019t reactivate until the battery is low again.</string>
+ <!-- Title of notification letting users know the battery level at the time the notification was posted [CHAR_LIMIT=80] -->
+ <string name="battery_saver_charged_notification_title" product="default">Phone <xliff:g id="charge level" example="90%">%1$s</xliff:g> charged</string>
+ <!-- Title of notification letting users know the battery level at the time the notification was posted [CHAR_LIMIT=80] -->
+ <string name="battery_saver_charged_notification_title" product="tablet">Tablet <xliff:g id="charge level" example="90%">%1$s</xliff:g> charged</string>
+ <!-- Title of notification letting users know the battery level at the time the notification was posted [CHAR_LIMIT=80] -->
+ <string name="battery_saver_charged_notification_title" product="device">Device <xliff:g id="charge level" example="90%">%1$s</xliff:g> charged</string>
+ <!-- Summary of notification letting users know that battery saver is now off [CHAR_LIMIT=NONE] -->
+ <string name="battery_saver_off_notification_summary">Battery Saver is off. Features no longer restricted.</string>
+ <!-- Alternative summary of notification letting users know that battery saver has been turned off.
+ If it's easy to translate the difference between "Battery Saver turned off. Features no longer restricted."
+ and "Battery Saver is off. Features no longer restricted." into the target language,
+ then translate "Battery Saver turned off. Features no longer restricted."
+ If the translation doesn't make a difference or the difference is hard to capture in the target language,
+ then translate "Battery Saver is off. Features no longer restricted." instead. [CHAR_LIMIT=NONE] -->
+ <string name="battery_saver_off_alternative_notification_summary">Battery Saver turned off. Features no longer restricted.</string>
<!-- Description of media type: folder or directory that contains additional files. [CHAR LIMIT=32] -->
<string name="mime_type_folder">Folder</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 0562f4c..012f736 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3653,6 +3653,9 @@
<java-symbol type="string" name="battery_saver_notification_channel_name" />
<java-symbol type="string" name="battery_saver_sticky_disabled_notification_title" />
<java-symbol type="string" name="battery_saver_sticky_disabled_notification_summary" />
+ <java-symbol type="string" name="battery_saver_charged_notification_title" />
+ <java-symbol type="string" name="battery_saver_off_notification_summary" />
+ <java-symbol type="string" name="battery_saver_off_alternative_notification_summary" />
<java-symbol type="string" name="dynamic_mode_notification_channel_name" />
<java-symbol type="string" name="dynamic_mode_notification_title" />
<java-symbol type="string" name="dynamic_mode_notification_summary" />
diff --git a/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java b/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
index b7be768..fe0b9a6 100644
--- a/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
+++ b/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
@@ -45,6 +45,7 @@
import com.android.server.power.BatterySaverStateMachineProto;
import java.io.PrintWriter;
+import java.text.NumberFormat;
/**
* Decides when to enable / disable battery saver.
@@ -791,7 +792,7 @@
manager.notify(DYNAMIC_MODE_NOTIFICATION_ID,
buildNotification(DYNAMIC_MODE_NOTIF_CHANNEL_ID,
- R.string.dynamic_mode_notification_title,
+ mContext.getResources().getString(R.string.dynamic_mode_notification_title),
R.string.dynamic_mode_notification_summary,
Intent.ACTION_POWER_USAGE_SUMMARY));
}
@@ -801,10 +802,13 @@
ensureNotificationChannelExists(manager, BATTERY_SAVER_NOTIF_CHANNEL_ID,
R.string.battery_saver_notification_channel_name);
+ final String percentage = NumberFormat.getPercentInstance()
+ .format((double) mBatteryLevel / 100.0);
manager.notify(STICKY_AUTO_DISABLED_NOTIFICATION_ID,
buildNotification(BATTERY_SAVER_NOTIF_CHANNEL_ID,
- R.string.battery_saver_sticky_disabled_notification_title,
- R.string.battery_saver_sticky_disabled_notification_summary,
+ mContext.getResources().getString(
+ R.string.battery_saver_charged_notification_title, percentage),
+ R.string.battery_saver_off_notification_summary,
Settings.ACTION_BATTERY_SAVER_SETTINGS));
}
@@ -816,7 +820,7 @@
manager.createNotificationChannel(channel);
}
- private Notification buildNotification(@NonNull String channelId, @StringRes int titleId,
+ private Notification buildNotification(@NonNull String channelId, @NonNull String title,
@StringRes int summaryId, @NonNull String intentAction) {
Resources res = mContext.getResources();
Intent intent = new Intent(intentAction);
@@ -827,11 +831,12 @@
return new Notification.Builder(mContext, channelId)
.setSmallIcon(R.drawable.ic_battery)
- .setContentTitle(res.getString(titleId))
+ .setContentTitle(title)
.setContentText(summary)
.setContentIntent(batterySaverIntent)
.setStyle(new Notification.BigTextStyle().bigText(summary))
.setOnlyAlertOnce(true)
+ .setAutoCancel(true)
.build();
}