Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5946fcb9 authored by Kweku Adams's avatar Kweku Adams Committed by Android (Google) Code Review
Browse files

Merge "Update sticky battery saver off notification."

parents a98a0c6f 3ff74379
Loading
Loading
Loading
Loading
+5 −16
Original line number Diff line number Diff line
@@ -5219,25 +5219,14 @@
    <!-- Battery saver strings -->
    <!-- The user visible name of the notification channel for battery saver notifications [CHAR_LIMIT=80] -->
    <string name="battery_saver_notification_channel_name">Battery Saver</string>
    <!-- Title 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_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 that battery saver is now off [CHAR_LIMIT=80] -->
    <string name="battery_saver_off_notification_title">Battery Saver turned off</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>
    <string name="battery_saver_charged_notification_summary" product="default">Phone has enough charge. Features no longer restricted.</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>
    <string name="battery_saver_charged_notification_summary" product="tablet">Tablet has enough charge. Features no longer restricted.</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>
    <string name="battery_saver_charged_notification_summary" product="device">Device has enough charge. 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>
+2 −5
Original line number Diff line number Diff line
@@ -3654,11 +3654,8 @@
  <java-symbol type="bool" name="config_useSystemProvidedLauncherForSecondary" />

  <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="battery_saver_off_notification_title" />
  <java-symbol type="string" name="battery_saver_charged_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" />
+5 −9
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import com.android.server.EventLogTags;
import com.android.server.power.BatterySaverStateMachineProto;

import java.io.PrintWriter;
import java.text.NumberFormat;

/**
 * Decides when to enable / disable battery saver.
@@ -796,8 +795,7 @@ public class BatterySaverStateMachine {

            manager.notifyAsUser(TAG, DYNAMIC_MODE_NOTIFICATION_ID,
                    buildNotification(DYNAMIC_MODE_NOTIF_CHANNEL_ID,
                            mContext.getResources().getString(
                                    R.string.dynamic_mode_notification_title),
                            R.string.dynamic_mode_notification_title,
                            R.string.dynamic_mode_notification_summary,
                            Intent.ACTION_POWER_USAGE_SUMMARY),
                    UserHandle.ALL);
@@ -813,13 +811,10 @@ public class BatterySaverStateMachine {
            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.notifyAsUser(TAG, STICKY_AUTO_DISABLED_NOTIFICATION_ID,
                    buildNotification(BATTERY_SAVER_NOTIF_CHANNEL_ID,
                            mContext.getResources().getString(
                                    R.string.battery_saver_charged_notification_title, percentage),
                            R.string.battery_saver_off_notification_summary,
                            R.string.battery_saver_off_notification_title,
                            R.string.battery_saver_charged_notification_summary,
                            Settings.ACTION_BATTERY_SAVER_SETTINGS),
                    UserHandle.ALL);
        });
@@ -834,13 +829,14 @@ public class BatterySaverStateMachine {
        manager.createNotificationChannel(channel);
    }

    private Notification buildNotification(@NonNull String channelId, @NonNull String title,
    private Notification buildNotification(@NonNull String channelId, @StringRes int titleId,
            @StringRes int summaryId, @NonNull String intentAction) {
        Resources res = mContext.getResources();
        Intent intent = new Intent(intentAction);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent batterySaverIntent = PendingIntent.getActivity(
                mContext, 0 /* requestCode */, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        final String title = res.getString(titleId);
        final String summary = res.getString(summaryId);

        return new Notification.Builder(mContext, channelId)