Fix battery optimization display problems
Root cause: RequestIgnoreBatteryOptimizations adds package in PowerWhitelistManager#addToWhitelist for intent Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS. Settings UI uses PowerAllowlistBackend to check if an APP is in power allow list. Each UI component should PowerAllowlistBackend#refreshList() or UI will get a stale result. Solution: This change fixes below display problems by refreshing allow list from DeviceIdleController service. 1. Battery optimization summary in Battery usage details. 2. Battery optimization list. BYPASS_INCLUSIVE_LANGUAGE_REASON=I need the object name to describe the root cause. Bug: 171064162 Test: make RunSettingsRoboTests ROBOTEST_FILTER=BatteryOptimizationPreferenceControllerTest manual Switch battery optimazion of a APP and observer the UI display. Change-Id: I75b269eec5d1b904dcaa71948798f169d4e4ddfa
This commit is contained in:
@@ -1045,6 +1045,7 @@ public class ManageApplications extends InstrumentedFragment
|
||||
} else if (mManageApplications.mListType == LIST_TYPE_USAGE_ACCESS) {
|
||||
mExtraInfoBridge = new AppStateUsageBridge(mContext, mState, this);
|
||||
} else if (mManageApplications.mListType == LIST_TYPE_HIGH_POWER) {
|
||||
mBackend.refreshList();
|
||||
mExtraInfoBridge = new AppStatePowerBridge(mContext, mState, this);
|
||||
} else if (mManageApplications.mListType == LIST_TYPE_OVERLAY) {
|
||||
mExtraInfoBridge = new AppStateOverlayBridge(mContext, mState, this);
|
||||
|
@@ -69,6 +69,7 @@ public class BatteryOptimizationPreferenceController extends AbstractPreferenceC
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
mBackend.refreshList();
|
||||
final boolean isAllowlisted = mBackend.isAllowlisted(mPackageName);
|
||||
preference.setSummary(isAllowlisted ? R.string.high_power_on : R.string.high_power_off);
|
||||
}
|
||||
|
@@ -112,6 +112,13 @@ public class BatteryOptimizationPreferenceControllerTest {
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mContext.getString(R.string.high_power_off));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_refreshList() {
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mBackend).refreshList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this test class so we could mock it
|
||||
*/
|
||||
|
Reference in New Issue
Block a user