Merge "Package battery saver schedule mode in severe battery intent" into tm-dev

This commit is contained in:
Wesley Wang
2022-03-29 03:31:55 +00:00
committed by Android (Google) Code Review

View File

@@ -120,7 +120,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
"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 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
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 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
mPlaySound = false;
return;
}
if (!showLowBatteryNotification()) {
if (isScheduledByPercentage()) {
return;
}
@@ -327,26 +329,19 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
}
/**
* 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() {