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

Commit c49fa4a7 authored by Wesley Wang's avatar Wesley Wang Committed by Android (Google) Code Review
Browse files

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

parents c0666397 0685bc26
Loading
Loading
Loading
Loading
+10 −15
Original line number Diff line number Diff line
@@ -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() {