Implement OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS exemption
OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS details: * An app with this appop will be made exempt from all power restrictions, including app standby and doze. * In addition, the app will be able to start fgs from the bg, and the user will not be able to stop fgs run by the app. Changes: * Implement the OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS Bug: 246330879 Test: atest PowerAllowlistBackendTest Manual testing: - Give OP_SYSTEM_EXEMPT_FROM_POWER_RESTRICTIONS appop to TestDPC app - Verify the app can start fg services from the bg - Verify fgs started by the app cannot be stopped - Verify the app cannot be put into background restricted via Settings Change-Id: If9e76076c59195f1e6e5f3eee3c8e7a0c754d8de
This commit is contained in:
@@ -94,7 +94,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetAppOptimizationMode_returnRestricted() {
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(false);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(false);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_IGNORED);
|
||||
|
||||
@@ -104,7 +104,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetAppOptimizationMode_returnUnrestricted() {
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(true);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
@@ -114,7 +114,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetAppOptimizationMode_returnOptimized() {
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(false);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(false);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
@@ -124,8 +124,8 @@ public class BatteryOptimizeUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testIsSystemOrDefaultApp_isSystemOrDefaultApp_returnTrue() {
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isDefaultActiveApp(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(true);
|
||||
when(mMockBackend.isDefaultActiveApp(anyString(), anyInt())).thenReturn(true);
|
||||
|
||||
assertThat(mBatteryOptimizeUtils.isSystemOrDefaultApp()).isTrue();
|
||||
}
|
||||
@@ -151,7 +151,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
@Test
|
||||
public void testSetAppUsageState_Restricted_verifyAction() throws Exception {
|
||||
// Sets the current mode as MODE_UNRESTRICTED.
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(true);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
@@ -164,7 +164,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
@Test
|
||||
public void testSetAppUsageState_Unrestricted_verifyAction() throws Exception {
|
||||
// Sets the current mode as MODE_RESTRICTED.
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(false);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(false);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_IGNORED);
|
||||
|
||||
@@ -178,7 +178,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
@Test
|
||||
public void testSetAppUsageState_Optimized_verifyAction() throws Exception {
|
||||
// Sets the current mode as MODE_UNRESTRICTED.
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(true);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
@@ -191,7 +191,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
@Test
|
||||
public void testSetAppUsageState_sameUnrestrictedMode_verifyNoAction() throws Exception {
|
||||
// Sets the current mode as MODE_UNRESTRICTED.
|
||||
when(mMockBackend.isAllowlisted(anyString())).thenReturn(true);
|
||||
when(mMockBackend.isAllowlisted(anyString(), anyInt())).thenReturn(true);
|
||||
when(mMockAppOpsManager.checkOpNoThrow(anyInt(), anyInt(), anyString()))
|
||||
.thenReturn(AppOpsManager.MODE_ALLOWED);
|
||||
|
||||
@@ -267,7 +267,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
|
||||
final InOrder inOrder = inOrder(mMockBackend);
|
||||
inOrder.verify(mMockBackend).refreshList();
|
||||
inOrder.verify(mMockBackend).isAllowlisted(PACKAGE_NAME);
|
||||
inOrder.verify(mMockBackend).isAllowlisted(PACKAGE_NAME, UID);
|
||||
verifyNoMoreInteractions(mMockBackend);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ public class BatteryOptimizeUtilsTest {
|
||||
|
||||
final InOrder inOrder = inOrder(mMockBackend);
|
||||
inOrder.verify(mMockBackend).refreshList();
|
||||
inOrder.verify(mMockBackend).isAllowlisted(PACKAGE_NAME);
|
||||
inOrder.verify(mMockBackend).isAllowlisted(PACKAGE_NAME, UID);
|
||||
inOrder.verify(mMockBackend).isSysAllowlisted(PACKAGE_NAME);
|
||||
verifyNoMoreInteractions(mMockBackend);
|
||||
}
|
||||
@@ -324,13 +324,13 @@ public class BatteryOptimizeUtilsTest {
|
||||
.checkOpNoThrow(anyInt(), anyInt(), anyString());
|
||||
doReturn(allowListed)
|
||||
.when(mMockBackend)
|
||||
.isAllowlisted(anyString());
|
||||
.isAllowlisted(anyString(), anyInt());
|
||||
doReturn(isSystemOrDefaultApp)
|
||||
.when(mMockBackend)
|
||||
.isSysAllowlisted(anyString());
|
||||
doReturn(isSystemOrDefaultApp)
|
||||
.when(mMockBackend)
|
||||
.isDefaultActiveApp(anyString());
|
||||
.isDefaultActiveApp(anyString(), anyInt());
|
||||
|
||||
BatteryOptimizeUtils.resetAppOptimizationMode(
|
||||
mContext, mMockIPackageManager, mMockAppOpsManager, mMockBackend,
|
||||
|
Reference in New Issue
Block a user