OSDN Git Service

Fix "battery saver" notification keeping coming back.
authorMakoto Onuki <omakoto@google.com>
Mon, 7 May 2018 20:56:40 +0000 (13:56 -0700)
committerMakoto Onuki <omakoto@google.com>
Mon, 7 May 2018 21:05:56 +0000 (14:05 -0700)
We have a delete intent set on this notification and but apparently
in this case it wasn't delivered or delayed. So add an extra check to make sure
we don't post it more than needed.

Also set FLAG_RECEIVER_FOREGROUND to pending broadcasts to make sure it won't
delayed too much.

Fixes: 79313125
Test: Manual test with:
1. Clear all battery saver settings
adb shell settings delete global low_power
adb shell settings delete global low_power_sticky
adb shell settings delete global low_power_trigger_level
adb shell settings delete secure low_power_manual_activation_count
adb shell settings delete secure low_power_warning_acknowledged
adb shell settings delete secure suppress_auto_battery_saver_suggestion
2. ./development/scripts/battery_simulator.py and set level to 10

3. Dismiss battery saver notification

Change-Id: I659fdb8a4dc8136e6c159fb566f30642c8a53fb2

packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java

index c6bb17c..065e9cc 100644 (file)
@@ -198,7 +198,13 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
             showWarningNotification();
             mShowing = SHOWING_WARNING;
         } else if (mShowAutoSaverSuggestion) {
-            showAutoSaverSuggestionNotification();
+            // Once we showed the notification, don't show it again until it goes SHOWING_NOTHING.
+            // This shouldn't be needed, because we have a delete intent on this notification
+            // so when it's dismissed we should notice it and clear mShowAutoSaverSuggestion,
+            // However we double check here just in case the dismiss intent broadcast is delayed.
+            if (mShowing != SHOWING_AUTO_SAVER_SUGGESTION) {
+                showAutoSaverSuggestionNotification();
+            }
             mShowing = SHOWING_AUTO_SAVER_SUGGESTION;
         } else {
             mNoMan.cancelAsUser(TAG_BATTERY, SystemMessage.NOTE_BAD_CHARGER, UserHandle.ALL);
@@ -303,7 +309,9 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
 
     private PendingIntent pendingBroadcast(String action) {
         return PendingIntent.getBroadcastAsUser(mContext, 0,
-                new Intent(action).setPackage(mContext.getPackageName()), 0, UserHandle.CURRENT);
+                new Intent(action).setPackage(mContext.getPackageName())
+                    .setFlags(Intent.FLAG_RECEIVER_FOREGROUND),
+                0, UserHandle.CURRENT);
     }
 
     private static Intent settings(String action) {