Hook up Adaptive Battery to new flag.

APP_STANDBY_ENABLED is controlled by server side to do experiment.
Before this CL, Adaptive Battery is hooked up to this flag, so
even though if user turns it off, it may be turned on by server.

Add a high level ADAPTIVE_BATTERY_MANAGEMENT_ENABLED to control
the feature in settings UI side.

Bug: 78153913
Test: RunSettingsRoboTests
Change-Id: I1a18d622ddc31ec4d45db918bf981516fbb926c1
This commit is contained in:
Lei Yu
2018-04-19 10:46:37 -07:00
parent 1257466d0b
commit df5beee68b
7 changed files with 19 additions and 14 deletions

View File

@@ -52,15 +52,15 @@ public class SmartBatteryPreferenceController extends BasePreferenceController i
public void updateState(Preference preference) { public void updateState(Preference preference) {
super.updateState(preference); super.updateState(preference);
final boolean smartBatteryOn = Settings.Global.getInt(mContext.getContentResolver(), final boolean smartBatteryOn = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.APP_STANDBY_ENABLED, ON) == ON; Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON) == ON;
((SwitchPreference) preference).setChecked(smartBatteryOn); ((SwitchPreference) preference).setChecked(smartBatteryOn);
} }
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean smartBatteryOn = (Boolean) newValue; final boolean smartBatteryOn = (Boolean) newValue;
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.APP_STANDBY_ENABLED, Settings.Global.putInt(mContext.getContentResolver(),
smartBatteryOn ? ON : OFF); Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, smartBatteryOn ? ON : OFF);
return true; return true;
} }
} }

View File

@@ -142,7 +142,7 @@ public class AnomalyDetectionJobService extends JobService {
final int uid = extractUidFromStatsDimensionsValue(intentDimsValue); final int uid = extractUidFromStatsDimensionsValue(intentDimsValue);
final boolean autoFeatureOn = powerUsageFeatureProvider.isSmartBatterySupported() final boolean autoFeatureOn = powerUsageFeatureProvider.isSmartBatterySupported()
? Settings.Global.getInt(contentResolver, ? Settings.Global.getInt(contentResolver,
Settings.Global.APP_STANDBY_ENABLED, ON) == ON Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON) == ON
: Settings.Global.getInt(contentResolver, : Settings.Global.getInt(contentResolver,
Settings.Global.APP_AUTO_RESTRICTION_ENABLED, ON) == ON; Settings.Global.APP_AUTO_RESTRICTION_ENABLED, ON) == ON;
final String packageName = batteryUtils.getPackageName(uid); final String packageName = batteryUtils.getPackageName(uid);

View File

@@ -56,7 +56,7 @@ public class BatteryManagerPreferenceController extends BasePreferenceController
super.updateState(preference); super.updateState(preference);
final int num = BatteryTipUtils.getRestrictedAppsList(mAppOpsManager, mUserManager).size(); final int num = BatteryTipUtils.getRestrictedAppsList(mAppOpsManager, mUserManager).size();
final String setting = mPowerUsageFeatureProvider.isSmartBatterySupported() final String setting = mPowerUsageFeatureProvider.isSmartBatterySupported()
? Settings.Global.APP_STANDBY_ENABLED ? Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED
: Settings.Global.APP_AUTO_RESTRICTION_ENABLED; : Settings.Global.APP_AUTO_RESTRICTION_ENABLED;
final boolean featureOn = final boolean featureOn =
Settings.Global.getInt(mContext.getContentResolver(), setting, ON) == ON; Settings.Global.getInt(mContext.getContentResolver(), setting, ON) == ON;

View File

@@ -39,7 +39,8 @@ public class SmartBatteryDetector implements BatteryTipDetector {
public BatteryTip detect() { public BatteryTip detect() {
// Show it if there is no other tips shown // Show it if there is no other tips shown
final boolean smartBatteryOff = Settings.Global.getInt(mContentResolver, final boolean smartBatteryOff = Settings.Global.getInt(mContentResolver,
Settings.Global.APP_STANDBY_ENABLED, 1) == 0 || mPolicy.testSmartBatteryTip; Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 1) == 0
|| mPolicy.testSmartBatteryTip;
final int state = final int state =
smartBatteryOff ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE; smartBatteryOff ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
return new SmartBatteryTip(state); return new SmartBatteryTip(state);

View File

@@ -107,10 +107,12 @@ public class SmartBatteryPreferenceControllerTest {
} }
private void putSmartBatteryValue(int value) { private void putSmartBatteryValue(int value) {
Settings.Global.putInt(mContentResolver, Settings.Global.APP_STANDBY_ENABLED, value); Settings.Global.putInt(mContentResolver,
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, value);
} }
private int getSmartBatteryValue() { private int getSmartBatteryValue() {
return Settings.Global.getInt(mContentResolver, Settings.Global.APP_STANDBY_ENABLED, ON); return Settings.Global.getInt(mContentResolver,
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON);
} }
} }

View File

@@ -71,8 +71,8 @@ public class BatteryManagerPreferenceControllerTest {
@Test @Test
public void updateState_smartBatteryOnWithoutRestriction_showSummary() { public void updateState_smartBatteryOnWithoutRestriction_showSummary() {
when(mFeatureFactory.powerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true); when(mFeatureFactory.powerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.APP_STANDBY_ENABLED, Settings.Global.putInt(mContext.getContentResolver(),
ON); Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON);
mController.updateState(mPreference); mController.updateState(mPreference);
@@ -82,8 +82,8 @@ public class BatteryManagerPreferenceControllerTest {
@Test @Test
public void updateState_smartBatteryOff_showSummary() { public void updateState_smartBatteryOff_showSummary() {
when(mFeatureFactory.powerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true); when(mFeatureFactory.powerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.APP_STANDBY_ENABLED, Settings.Global.putInt(mContext.getContentResolver(),
OFF); Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, OFF);
mController.updateState(mPreference); mController.updateState(mPreference);

View File

@@ -61,14 +61,16 @@ public class SmartBatteryDetectorTest {
@Test @Test
public void testDetect_smartBatteryOff_tipVisible() { public void testDetect_smartBatteryOff_tipVisible() {
Settings.Global.putInt(mContentResolver, Settings.Global.APP_STANDBY_ENABLED, 0); Settings.Global.putInt(mContentResolver,
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 0);
assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue(); assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
} }
@Test @Test
public void testDetect_smartBatteryOn_tipInvisible() { public void testDetect_smartBatteryOn_tipInvisible() {
Settings.Global.putInt(mContentResolver, Settings.Global.APP_STANDBY_ENABLED, 1); Settings.Global.putInt(mContentResolver,
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, 1);
assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse(); assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();
} }