Revert "Add PowerSaveWhitelistExceptIdle as Optimizted modes condition"
- Reverts commit e7cca4cd81
- Add try-catch to handle unexpected operate
Reason for revert: Previous fix will cause a side effect which makes app stuck at Optimize mode after switching state from Unrestricted to Optimize, add a try catch to handle previous issue first
BYPASS_INCLUSIVE_LANGUAGE_REASON=legacy naming, not edit by this code change
Bug: 199892006
Test: make SettingsRoboTests
Change-Id: I3b1850ab66bbf4cd605f14152a244a8ed7edd578
Merged-In: I3b1850ab66bbf4cd605f14152a244a8ed7edd578
This commit is contained in:
committed by
Wesley Wang
parent
3efe6e59f7
commit
d11dec2f82
@@ -361,8 +361,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
||||
final String stateString;
|
||||
final String footerString;
|
||||
|
||||
if (!mBatteryOptimizeUtils.isValidPackageName()
|
||||
|| mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
||||
if (!mBatteryOptimizeUtils.isValidPackageName()) {
|
||||
// Present optimized only string when the package name is invalid or
|
||||
// it's in allow list not idle app.
|
||||
stateString = context.getString(R.string.manager_battery_usage_optimized_only);
|
||||
|
@@ -89,8 +89,16 @@ public class BatteryOptimizeUtils {
|
||||
return getAppOptimizationMode(mMode, mAllowListed);
|
||||
}
|
||||
|
||||
/** Sets the {@link OptimizationMode} for associated app. */
|
||||
public void setAppOptimizationMode(@OptimizationMode int mode) {
|
||||
try {
|
||||
setAppUsageStateInternal(mode);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "setAppUsageState() is failed for " + mPackageName, e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Sets the {@link OptimizationMode} for associated app. */
|
||||
public void setAppUsageStateInternal(@OptimizationMode int mode) {
|
||||
if (getAppOptimizationMode(mMode, mAllowListed) == mode) {
|
||||
Log.w(TAG, "set the same optimization mode for: " + mPackageName);
|
||||
return;
|
||||
@@ -130,13 +138,6 @@ public class BatteryOptimizeUtils {
|
||||
|| mPowerAllowListBackend.isDefaultActiveApp(mPackageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if this package is in allow list except idle app.
|
||||
*/
|
||||
public boolean isAllowlistedExceptIdleApp() {
|
||||
return mPowerAllowListBackend.isAllowlistedExceptIdle(mPackageName);
|
||||
}
|
||||
|
||||
String getPackageName() {
|
||||
return mPackageName == null ? UNKNOWN_PACKAGE : mPackageName;
|
||||
}
|
||||
|
@@ -57,10 +57,6 @@ public class OptimizedPreferenceController extends AbstractPreferenceController
|
||||
Log.d(TAG, "is system or default app, disable pref");
|
||||
((RadioButtonPreference) preference).setChecked(false);
|
||||
preference.setEnabled(false);
|
||||
} else if (mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
||||
Log.d(TAG, "in allow list not idle app, optimized states only");
|
||||
preference.setEnabled(true);
|
||||
((RadioButtonPreference) preference).setChecked(true);
|
||||
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
||||
== BatteryOptimizeUtils.MODE_OPTIMIZED) {
|
||||
Log.d(TAG, "is optimized states");
|
||||
|
@@ -55,9 +55,6 @@ public class RestrictedPreferenceController extends AbstractPreferenceController
|
||||
Log.d(TAG, "is system or default app, disable pref");
|
||||
((RadioButtonPreference) preference).setChecked(false);
|
||||
preference.setEnabled(false);
|
||||
} else if (mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
||||
Log.d(TAG, "in allow list not idle app, disable perf");
|
||||
preference.setEnabled(false);
|
||||
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
||||
== BatteryOptimizeUtils.MODE_RESTRICTED) {
|
||||
Log.d(TAG, "is restricted states");
|
||||
|
@@ -53,9 +53,6 @@ public class UnrestrictedPreferenceController extends AbstractPreferenceControll
|
||||
if (mBatteryOptimizeUtils.isSystemOrDefaultApp()) {
|
||||
Log.d(TAG, "is system or default app, unrestricted states only");
|
||||
((RadioButtonPreference) preference).setChecked(true);
|
||||
} else if (mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()) {
|
||||
Log.d(TAG, "in allow list not idle app, disable perf");
|
||||
preference.setEnabled(false);
|
||||
} else if (mBatteryOptimizeUtils.getAppOptimizationMode()
|
||||
== BatteryOptimizeUtils.MODE_UNRESTRICTED) {
|
||||
Log.d(TAG, "is unrestricted states");
|
||||
|
@@ -745,16 +745,6 @@ public class AdvancedPowerUsageDetailTest {
|
||||
.isEqualTo("This app requires optimized battery usage.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitPreferenceForTriState_isAllowlistedExceptIdleApp_hasCorrectString() {
|
||||
when(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
||||
|
||||
mFragment.initPreferenceForTriState(mContext);
|
||||
|
||||
assertThat(mFooterPreference.getTitle().toString())
|
||||
.isEqualTo("This app requires optimized battery usage.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitPreferenceForTriState_isSystemOrDefaultApp_hasCorrectString() {
|
||||
when(mBatteryOptimizeUtils.isValidPackageName()).thenReturn(true);
|
||||
|
@@ -124,18 +124,6 @@ public class BatteryOptimizeUtilsTest {
|
||||
assertThat(mBatteryOptimizeUtils.isValidPackageName()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAllowlistedExpectIdle_isAllowlistedExceptIdle_returnTrue() {
|
||||
when(mMockBackend.isAllowlistedExceptIdle(anyString())).thenReturn(true);
|
||||
|
||||
assertThat(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAllowlistedExpectIdle_notAllowlistedExpectIdle_returnFalse() {
|
||||
assertThat(mBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAppOptimizationMode_Restricted_verifyAction() {
|
||||
// Sets the current mode as MODE_UNRESTRICTED.
|
||||
|
@@ -93,16 +93,6 @@ public class OptimizedPreferenceControllerTest {
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isAllowlistedExceptIdleApp_prefEnabled() {
|
||||
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
||||
mPreference.setKey(mController.KEY_OPTIMIZED_PREF);
|
||||
|
@@ -101,16 +101,6 @@ public class RestrictedPreferenceControllerTest {
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isAllowlistedExceptIdleApp_prefDisabled() {
|
||||
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
||||
mPreference.setKey(mController.KEY_RESTRICTED_PREF);
|
||||
|
@@ -101,16 +101,6 @@ public class UnrestrictedPreferenceControllerTest {
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_isAllowlistedExceptIdleApp_prefDisabled() {
|
||||
when(mockBatteryOptimizeUtils.isAllowlistedExceptIdleApp()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_samePrefKey_verifyAction() {
|
||||
mPreference.setKey(mController.KEY_UNRESTRICTED_PREF);
|
||||
|
Reference in New Issue
Block a user