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

Commit 62ec08f7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Suppress battery saver suggestion notification" into rvc-dev

parents 8ab31819 418c85f1
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.PowerManager;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.text.TextUtils;

import com.android.settingslib.fuelgauge.BatterySaverUtils;

/**
@@ -112,6 +113,10 @@ public class BatterySaverScheduleRadioButtonsController {
        if (mode != PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC) {
            Settings.Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, triggerLevel);
        }
        // Suppress battery saver suggestion notification if enabling scheduling battery saver.
        if (mode == PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC || triggerLevel != 0) {
            BatterySaverUtils.suppressAutoBatterySaver(mContext);
        }
        mSeekBarController.updateSeekBar();
        return true;
    }
+29 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.os.PowerManager;
import android.provider.Settings;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -64,4 +65,31 @@ public class BatterySaverScheduleRadioButtonsControllerTest {
        assertThat(mController.getDefaultKey())
                .isEqualTo(BatterySaverScheduleRadioButtonsController.KEY_NO_SCHEDULE);
    }

    @Test
    public void setDefaultKey_percentage_shouldSuppressNotification() {
        Secure.putInt(
                mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1);
        Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
                PowerManager.POWER_SAVE_MODE_TRIGGER_PERCENTAGE);
        Settings.Global.putInt(mResolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 5);
        mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_PERCENTAGE);

        final int result = Settings.Secure.getInt(mResolver,
                Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0);
        assertThat(result).isEqualTo(1);
    }

    @Test
    public void setDefaultKey_routine_shouldSuppressNotification() {
        Secure.putInt(
                mContext.getContentResolver(), Secure.LOW_POWER_WARNING_ACKNOWLEDGED, 1);
        Settings.Global.putInt(mResolver, Global.AUTOMATIC_POWER_SAVE_MODE,
                PowerManager.POWER_SAVE_MODE_TRIGGER_DYNAMIC);
        mController.setDefaultKey(BatterySaverScheduleRadioButtonsController.KEY_ROUTINE);

        final int result = Settings.Secure.getInt(mResolver,
                Secure.SUPPRESS_AUTO_BATTERY_SAVER_SUGGESTION, 0);
        assertThat(result).isEqualTo(1);
    }
}