Take as Unrestricted Mode in the UI if current Mode is Unknown.

- Battery usage mode MODE_UNKNOWN is (1) apps in allowlist and (2) app's OP_RUN_ANY_IN_BACKGROUND = MODE_IGNORED.
For this case, mode should be displayed as Unrestricted on UI since it is in allowlist; and should be logged as unknown mode for the potential compatibility issues.

- After Backup & Restore, the MODE_UNKNOWN will be reset to Optimized(Default) Mode on target device.

Bug: 372831500
Test: manual
Test: atest BatteryOptimizeUtilsTest
Test: atest AppOptModeSharedPreferencesUtilsTest
Flag: EXEMPT for simple fix
Change-Id: Ic18e026f71a4a50ffa1711e2ca0782aeb8b33076
This commit is contained in:
mxyyiyi
2024-10-14 13:32:17 +08:00
parent fdc8eb3e00
commit 7bfa060c5f
7 changed files with 37 additions and 18 deletions

View File

@@ -127,6 +127,15 @@ public class BatteryOptimizeUtilsTest {
assertThat(mBatteryOptimizeUtils.getAppOptimizationMode()).isEqualTo(MODE_OPTIMIZED);
}
@Test
public void testGetAppOptimizationMode_unknownMode_returnOptimized() throws Exception {
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(true);
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
.thenReturn(AppOpsManager.MODE_IGNORED);
assertThat(mBatteryOptimizeUtils.getAppOptimizationMode()).isEqualTo(MODE_UNRESTRICTED);
}
@Test
public void testIsSystemOrDefaultApp_isSystemOrDefaultApp_returnTrue() {
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(true);