diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 67cd6c22651d0..641c79a58986a 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -2375,7 +2375,7 @@ Tap to schedule Battery Saver - Turn on automatically when battery is at %d%% + Turn on when battery is likely to run out No thanks diff --git a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java index f6cd199f076e6..4982dd49fecba 100644 --- a/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java +++ b/packages/SystemUI/src/com/android/systemui/power/PowerNotificationWarnings.java @@ -118,6 +118,8 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private static final String SETTINGS_ACTION_OPEN_BATTERY_SAVER_SETTING = "android.settings.BATTERY_SAVER_SETTINGS"; + public static final String BATTERY_SAVER_SCHEDULE_SCREEN_INTENT_ACTION = + "com.android.settings.BATTERY_SAVER_SCHEDULE_SETTINGS"; private static final String BATTERY_SAVER_DESCRIPTION_URL_KEY = "url"; @@ -152,16 +154,18 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { private SystemUIDialog mThermalShutdownDialog; @VisibleForTesting SystemUIDialog mUsbHighTempDialog; private BatteryStateSnapshot mCurrentBatterySnapshot; + private ActivityStarter mActivityStarter; /** */ @Inject - public PowerNotificationWarnings(Context context) { + public PowerNotificationWarnings(Context context, ActivityStarter activityStarter) { mContext = context; mNoMan = mContext.getSystemService(NotificationManager.class); mPowerMan = (PowerManager) context.getSystemService(Context.POWER_SERVICE); mKeyguard = mContext.getSystemService(KeyguardManager.class); mReceiver.init(); + mActivityStarter = activityStarter; } @Override @@ -172,7 +176,6 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { pw.print("mShowing="); pw.println(SHOWING_STRINGS[mShowing]); pw.print("mSaverConfirmation="); pw.println(mSaverConfirmation != null ? "not null" : null); pw.print("mSaverEnabledConfirmation="); - pw.println(mSaverEnabledConfirmation != null ? "not null" : null); pw.print("mHighTempWarning="); pw.println(mHighTempWarning); pw.print("mHighTempDialog="); pw.println(mHighTempDialog != null ? "not null" : null); pw.print("mThermalShutdownDialog="); @@ -305,8 +308,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { .setWhen(0) .setShowWhen(false) .setContentTitle(mContext.getString(R.string.auto_saver_title)) - .setContentText(mContext.getString(R.string.auto_saver_text, - getLowBatteryAutoTriggerDefaultLevel())); + .setContentText(mContext.getString(R.string.auto_saver_text)); nb.setContentIntent(pendingBroadcast(ACTION_ENABLE_AUTO_SAVER)); nb.setDeleteIntent(pendingBroadcast(ACTION_DISMISS_AUTO_SAVER_SUGGESTION)); nb.addAction(0, @@ -673,51 +675,14 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { return builder; } - private void showAutoSaverEnabledConfirmation() { - if (mSaverEnabledConfirmation != null) return; - - // Open the Battery Saver setting page. - final Intent actionBatterySaverSetting = - new Intent(SETTINGS_ACTION_OPEN_BATTERY_SAVER_SETTING) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - final SystemUIDialog d = new SystemUIDialog(mContext); - d.setTitle(R.string.auto_saver_enabled_title); - d.setMessage(mContext.getString(R.string.auto_saver_enabled_text, - getLowBatteryAutoTriggerDefaultLevel())); - - // "Got it". Just close the dialog. Automatic battery has been enabled already. - d.setPositiveButton(R.string.auto_saver_okay_action, - (dialog, which) -> onAutoSaverEnabledConfirmationClosed()); - - // "Settings" -> Opens the battery saver settings activity. - d.setNeutralButton(R.string.open_saver_setting_action, (dialog, which) -> { - mContext.startActivity(actionBatterySaverSetting); - onAutoSaverEnabledConfirmationClosed(); - }); - d.setShowForAllUsers(true); - d.setOnDismissListener((dialog) -> onAutoSaverEnabledConfirmationClosed()); - d.show(); - mSaverEnabledConfirmation = d; - } - - private void onAutoSaverEnabledConfirmationClosed() { - mSaverEnabledConfirmation = null; - } - private void setSaverMode(boolean mode, boolean needFirstTimeWarning) { BatterySaverUtils.setPowerSaveMode(mContext, mode, needFirstTimeWarning); } - private void scheduleAutoBatterySaver() { - int autoTriggerThreshold = mContext.getResources().getInteger( - com.android.internal.R.integer.config_lowBatteryWarningLevel); - if (autoTriggerThreshold == 0) { - autoTriggerThreshold = 15; - } - - BatterySaverUtils.ensureAutoBatterySaver(mContext, autoTriggerThreshold); - showAutoSaverEnabledConfirmation(); + private void startBatterySaverSchedulePage() { + Intent intent = new Intent(BATTERY_SAVER_SCHEDULE_SCREEN_INTENT_ACTION); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + mActivityStarter.startActivity(intent, true /* dismissShade */); } private final class Receiver extends BroadcastReceiver { @@ -771,7 +736,7 @@ public class PowerNotificationWarnings implements PowerUI.WarningsUI { dismissAutoSaverSuggestion(); } else if (ACTION_ENABLE_AUTO_SAVER.equals(action)) { dismissAutoSaverSuggestion(); - scheduleAutoBatterySaver(); + startBatterySaverSchedulePage(); } else if (ACTION_AUTO_SAVER_NO_THANKS.equals(action)) { dismissAutoSaverSuggestion(); BatterySaverUtils.suppressAutoBatterySaver(context); diff --git a/packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java b/packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java index 58c931190c83c..afb63ab0ebcf7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/power/PowerNotificationWarningsTest.java @@ -37,6 +37,7 @@ import androidx.test.runner.AndroidJUnit4; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.systemui.SysuiTestCase; +import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.util.NotificationChannels; import org.junit.Before; @@ -57,7 +58,8 @@ public class PowerNotificationWarningsTest extends SysuiTestCase { public void setUp() throws Exception { // Test Instance. mContext.addMockSystemService(NotificationManager.class, mMockNotificationManager); - mPowerNotificationWarnings = new PowerNotificationWarnings(mContext); + ActivityStarter starter = mDependency.injectMockDependency(ActivityStarter.class); + mPowerNotificationWarnings = new PowerNotificationWarnings(mContext, starter); BatteryStateSnapshot snapshot = new BatteryStateSnapshot(100, false, false, 1, BatteryManager.BATTERY_HEALTH_GOOD, 5, 15); mPowerNotificationWarnings.updateSnapshot(snapshot);