Merge "Add util for reverting schedule mode"
This commit is contained in:
committed by
Android (Google) Code Review
commit
339699b59f
@@ -1165,6 +1165,10 @@
|
||||
<!-- The default suggested battery % at which we enable battery saver automatically. -->
|
||||
<integer name="config_lowBatteryAutoTriggerDefaultLevel">15</integer>
|
||||
|
||||
<!-- The app which will handle routine based automatic battery saver, if empty the UI for
|
||||
routine based battery saver will be hidden -->
|
||||
<string name="config_batterySaverScheduleProvider"></string>
|
||||
|
||||
<!-- Close low battery warning when battery level reaches the lowBatteryWarningLevel
|
||||
plus this -->
|
||||
<integer name="config_lowBatteryCloseWarningBump">5</integer>
|
||||
|
||||
@@ -3463,6 +3463,7 @@
|
||||
<java-symbol type="integer" name="config_lowBatteryAutoTriggerDefaultLevel" />
|
||||
<java-symbol type="bool" name="config_batterySaverStickyBehaviourDisabled" />
|
||||
<java-symbol type="integer" name="config_dynamicPowerSavingsDefaultDisableThreshold" />
|
||||
<java-symbol type="string" name="config_batterySaverScheduleProvider" />
|
||||
|
||||
<!-- For car devices -->
|
||||
<java-symbol type="string" name="car_loading_profile" />
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.content.Intent;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings.Global;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.text.TextUtils;
|
||||
import android.util.KeyValueListParser;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
@@ -176,4 +177,22 @@ public class BatterySaverUtils {
|
||||
setAutoBatterySaverTriggerLevel(context, level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts battery saver schedule mode to none if we are in a bad state where routine mode
|
||||
* is selected but no app is configured to actually provide the signal.
|
||||
* @param context a valid context
|
||||
*/
|
||||
public static void revertScheduleToNoneIfNeeded(Context context) {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
final int currentMode = Global.getInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
||||
boolean providerConfigured = !TextUtils.isEmpty(context.getString(
|
||||
com.android.internal.R.string.config_batterySaverScheduleProvider));
|
||||
if (currentMode == PowerManager.POWER_SAVER_MODE_DYNAMIC && !providerConfigured) {
|
||||
Global.putInt(resolver, Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
|
||||
Global.putInt(resolver, Global.AUTOMATIC_POWER_SAVER_MODE,
|
||||
PowerManager.POWER_SAVER_MODE_PERCENTAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user