Package battery saver schedule mode in severe battery intent

 - Add extra info to enable severe battery dialog intent
 - Adjust method names

Bug: 223732451
Test: atest SystemUITests
Change-Id: I535c69d773e0cc37d5f75712087df9868160ed66
diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
index 369a552..2435497 100644
--- a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
+++ b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java
@@ -120,7 +120,8 @@
             "PNW.autoSaverNoThanks";
 
     private static final String ACTION_ENABLE_SEVERE_BATTERY_DIALOG = "PNW.enableSevereDialog";
-
+    private static final String EXTRA_SCHEDULED_BY_PERCENTAGE =
+            "extra_scheduled_by_percentage";
     public static final String BATTERY_SAVER_SCHEDULE_SCREEN_INTENT_ACTION =
             "com.android.settings.BATTERY_SAVER_SCHEDULE_SETTINGS";
 
@@ -264,6 +265,7 @@
         if (showSevereLowBatteryDialog()) {
             mBroadcastSender.sendBroadcast(new Intent(ACTION_ENABLE_SEVERE_BATTERY_DIALOG)
                     .setPackage(mContext.getPackageName())
+                    .putExtra(EXTRA_SCHEDULED_BY_PERCENTAGE, isScheduledByPercentage())
                     .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
                             | Intent.FLAG_RECEIVER_FOREGROUND));
             // Reset the state once dialog been enabled
@@ -271,7 +273,7 @@
             mPlaySound = false;
             return;
         }
-        if (!showLowBatteryNotification()) {
+        if (isScheduledByPercentage()) {
             return;
         }
 
@@ -327,26 +329,19 @@
     }
 
     /**
-     * Disable low battery warning notification if battery saver schedule mode set as
-     * "Based on percentage".
+     * Checking battery saver schedule mode is set as "Based on percentage" or not.
      *
-     * return {@code false} if scheduled by percentage.
+     * return {@code true} if scheduled by percentage.
      */
-    private boolean showLowBatteryNotification() {
+    private boolean isScheduledByPercentage() {
         final ContentResolver resolver = mContext.getContentResolver();
         final int mode = Settings.Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVE_MODE,
                 PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
 
-        // Return true if battery saver schedule mode will not trigger by percentage.
-        if (mode != PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE) {
-            return true;
-        }
-
-        // Return true if battery saver mode trigger percentage is less than 0, which means it is
+        // Return false if battery saver mode trigger percentage is less than 0, which means it is
         // set as "Based on routine" mode, otherwise it will be "Based on percentage" mode.
-        final int threshold =
-                Settings.Global.getInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
-        return threshold <= 0;
+        return mode == PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE
+                && Settings.Global.getInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) > 0;
     }
 
     private void showAutoSaverSuggestionNotification() {