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

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

Merge "Add new Settings value for low power reminder"

parents 36182212 5da2d2b7
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -15173,6 +15173,15 @@ public final class Settings {
        public static final String LOW_POWER_MODE_SUGGESTION_PARAMS =
                "low_power_mode_suggestion_params";
        /**
         * Whether low power mode reminder is enabled. If this value is 0, the device will not
         * receive low power notification.
         *
         * @hide
         */
        public static final String LOW_POWER_MODE_REMINDER_ENABLED =
                "low_power_mode_reminder_enabled";
        /**
         * If not 0, the activity manager will aggressively finish activities and
         * processes as soon as they are no longer needed.  If 0, the normal
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ public class GlobalSettings {
        Settings.Global.ENABLE_AUTOMATIC_SYSTEM_SERVER_HEAP_DUMPS,
        Settings.Global.ENCODED_SURROUND_OUTPUT,
        Settings.Global.ENCODED_SURROUND_OUTPUT_ENABLED_FORMATS,
        Settings.Global.LOW_POWER_MODE_REMINDER_ENABLED,
        Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL,
        Settings.Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_ENABLED,
        Settings.Global.LOW_POWER_MODE_STICKY_AUTO_DISABLE_LEVEL,
+1 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ public class GlobalSettingsValidators {
                new DiscreteValueValidator(new String[] {"0", "1"}));
        VALIDATORS.put(Global.LOW_POWER_MODE_TRIGGER_LEVEL, PERCENTAGE_INTEGER_VALIDATOR);
        VALIDATORS.put(Global.LOW_POWER_MODE_TRIGGER_LEVEL_MAX, PERCENTAGE_INTEGER_VALIDATOR);
        VALIDATORS.put(Global.LOW_POWER_MODE_REMINDER_ENABLED, BOOLEAN_VALIDATOR);
        VALIDATORS.put(
                Global.AUTOMATIC_POWER_SAVE_MODE,
                new DiscreteValueValidator(new String[] {"0", "1"}));
+8 −1
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.util.NotificationChannels;
import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.volume.Events;

import java.io.PrintWriter;
@@ -175,6 +176,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    private ActivityStarter mActivityStarter;
    private final BroadcastSender mBroadcastSender;
    private final UiEventLogger mUiEventLogger;
    private GlobalSettings mGlobalSettings;

    private final Lazy<BatteryController> mBatteryControllerLazy;
    private final DialogLaunchAnimator mDialogLaunchAnimator;
@@ -184,7 +186,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    @Inject
    public PowerNotificationWarnings(Context context, ActivityStarter activityStarter,
            BroadcastSender broadcastSender, Lazy<BatteryController> batteryControllerLazy,
            DialogLaunchAnimator dialogLaunchAnimator, UiEventLogger uiEventLogger) {
            DialogLaunchAnimator dialogLaunchAnimator, UiEventLogger uiEventLogger,
            GlobalSettings globalSettings) {
        mContext = context;
        mNoMan = mContext.getSystemService(NotificationManager.class);
        mPowerMan = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
@@ -196,6 +199,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
        mDialogLaunchAnimator = dialogLaunchAnimator;
        mUseSevereDialog = mContext.getResources().getBoolean(R.bool.config_severe_battery_dialog);
        mUiEventLogger = uiEventLogger;
        mGlobalSettings = globalSettings;
    }

    @Override
@@ -281,6 +285,9 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI {
    }

    protected void showWarningNotification() {
        if (mGlobalSettings.getInt(Global.LOW_POWER_MODE_REMINDER_ENABLED, 1) == 0) {
            return;
        }
        if (showSevereLowBatteryDialog()) {
            mBroadcastSender.sendBroadcast(new Intent(ACTION_ENABLE_SEVERE_BATTERY_DIALOG)
                    .setPackage(mContext.getPackageName())
+16 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.UserHandle;
import android.provider.Settings;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -55,6 +56,8 @@ import com.android.systemui.broadcast.BroadcastSender;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.util.NotificationChannels;
import com.android.systemui.util.settings.FakeSettings;
import com.android.systemui.util.settings.GlobalSettings;

import org.junit.Before;
import org.junit.Test;
@@ -73,6 +76,7 @@ public class PowerNotificationWarningsTest extends SysuiTestCase {
    public static final String FORMATTED_45M = "0h 45m";
    public static final String FORMATTED_HOUR = "1h 0m";
    private final NotificationManager mMockNotificationManager = mock(NotificationManager.class);
    private final GlobalSettings mGlobalSettings = new FakeSettings();
    private PowerNotificationWarnings mPowerNotificationWarnings;

    @Mock
@@ -104,7 +108,8 @@ public class PowerNotificationWarningsTest extends SysuiTestCase {
        ActivityStarter starter = mDependency.injectMockDependency(ActivityStarter.class);
        BroadcastSender broadcastSender = mDependency.injectMockDependency(BroadcastSender.class);
        mPowerNotificationWarnings = new PowerNotificationWarnings(wrapper, starter,
                broadcastSender, () -> mBatteryController, mDialogLaunchAnimator, mUiEventLogger);
                broadcastSender, () -> mBatteryController, mDialogLaunchAnimator, mUiEventLogger,
                mGlobalSettings);
        BatteryStateSnapshot snapshot = new BatteryStateSnapshot(100, false, false, 1,
                BatteryManager.BATTERY_HEALTH_GOOD, 5, 15);
        mPowerNotificationWarnings.updateSnapshot(snapshot);
@@ -145,6 +150,16 @@ public class PowerNotificationWarningsTest extends SysuiTestCase {
                eq(SystemMessage.NOTE_BAD_CHARGER), any());
    }

    @Test
    public void testDisableLowBatteryReminder_noNotification() {
        mGlobalSettings.putInt(Settings.Global.LOW_POWER_MODE_REMINDER_ENABLED, 0);

        mPowerNotificationWarnings.showLowBatteryWarning(false);

        verify(mMockNotificationManager, times(0))
                .notifyAsUser(anyString(), eq(SystemMessage.NOTE_POWER_LOW), any(), any());
    }

    @Test
    public void testShowLowBatteryNotification_NotifyAsUser() {
        mPowerNotificationWarnings.showLowBatteryWarning(false);