Merge "Only user whitelist gets allow_while_idle_unrestricted" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
3d70d20c88
@@ -25,7 +25,7 @@ option java_multiple_files = true;
|
||||
|
||||
// Dump from com.android.server.ForceAppStandbyTracker.
|
||||
//
|
||||
// Next ID: 12
|
||||
// Next ID: 13
|
||||
message ForceAppStandbyTrackerProto {
|
||||
option (.android.msg_privacy).dest = DEST_AUTOMATIC;
|
||||
|
||||
@@ -41,6 +41,9 @@ message ForceAppStandbyTrackerProto {
|
||||
// App ids that are in power-save whitelist.
|
||||
repeated int32 power_save_whitelist_app_ids = 3;
|
||||
|
||||
// App ids that are in power-save user whitelist.
|
||||
repeated int32 power_save_user_whitelist_app_ids = 12;
|
||||
|
||||
// App ids that are in temporary power-save whitelist.
|
||||
repeated int32 temp_power_save_whitelist_app_ids = 4;
|
||||
|
||||
|
||||
@@ -1776,7 +1776,7 @@ class AlarmManagerService extends SystemService {
|
||||
} else if (workSource == null && (callingUid < Process.FIRST_APPLICATION_UID
|
||||
|| UserHandle.isSameApp(callingUid, mSystemUiUid)
|
||||
|| ((mAppStateTracker != null)
|
||||
&& mAppStateTracker.isUidPowerSaveWhitelisted(callingUid)))) {
|
||||
&& mAppStateTracker.isUidPowerSaveUserWhitelisted(callingUid)))) {
|
||||
flags |= AlarmManager.FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED;
|
||||
flags &= ~AlarmManager.FLAG_ALLOW_WHILE_IDLE;
|
||||
}
|
||||
|
||||
@@ -117,6 +117,12 @@ public class AppStateTracker {
|
||||
@GuardedBy("mLock")
|
||||
private int[] mPowerWhitelistedAllAppIds = new int[0];
|
||||
|
||||
/**
|
||||
* User whitelisted apps in the device idle controller.
|
||||
*/
|
||||
@GuardedBy("mLock")
|
||||
private int[] mPowerWhitelistedUserAppIds = new int[0];
|
||||
|
||||
@GuardedBy("mLock")
|
||||
private int[] mTempWhitelistedAppIds = mPowerWhitelistedAllAppIds;
|
||||
|
||||
@@ -983,13 +989,16 @@ public class AppStateTracker {
|
||||
* Called by device idle controller to update the power save whitelists.
|
||||
*/
|
||||
public void setPowerSaveWhitelistAppIds(
|
||||
int[] powerSaveWhitelistAllAppIdArray, int[] tempWhitelistAppIdArray) {
|
||||
int[] powerSaveWhitelistExceptIdleAppIdArray,
|
||||
int[] powerSaveWhitelistUserAppIdArray,
|
||||
int[] tempWhitelistAppIdArray) {
|
||||
synchronized (mLock) {
|
||||
final int[] previousWhitelist = mPowerWhitelistedAllAppIds;
|
||||
final int[] previousTempWhitelist = mTempWhitelistedAppIds;
|
||||
|
||||
mPowerWhitelistedAllAppIds = powerSaveWhitelistAllAppIdArray;
|
||||
mPowerWhitelistedAllAppIds = powerSaveWhitelistExceptIdleAppIdArray;
|
||||
mTempWhitelistedAppIds = tempWhitelistAppIdArray;
|
||||
mPowerWhitelistedUserAppIds = powerSaveWhitelistUserAppIdArray;
|
||||
|
||||
if (isAnyAppIdUnwhitelisted(previousWhitelist, mPowerWhitelistedAllAppIds)) {
|
||||
mHandler.notifyAllUnwhitelisted();
|
||||
@@ -1193,6 +1202,16 @@ public class AppStateTracker {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uid the uid to check for
|
||||
* @return whether a UID is in the user defined power-save whitelist or not.
|
||||
*/
|
||||
public boolean isUidPowerSaveUserWhitelisted(int uid) {
|
||||
synchronized (mLock) {
|
||||
return ArrayUtils.contains(mPowerWhitelistedUserAppIds, UserHandle.getAppId(uid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether a UID is in the temp power-save whitelist or not.
|
||||
*
|
||||
@@ -1231,9 +1250,12 @@ public class AppStateTracker {
|
||||
pw.print("Foreground uids: ");
|
||||
dumpUids(pw, mForegroundUids);
|
||||
|
||||
pw.print("Whitelist appids: ");
|
||||
pw.print("Except-idle + user whitelist appids: ");
|
||||
pw.println(Arrays.toString(mPowerWhitelistedAllAppIds));
|
||||
|
||||
pw.print("User whitelist appids: ");
|
||||
pw.println(Arrays.toString(mPowerWhitelistedUserAppIds));
|
||||
|
||||
pw.print("Temp whitelist appids: ");
|
||||
pw.println(Arrays.toString(mTempWhitelistedAppIds));
|
||||
|
||||
@@ -1311,6 +1333,10 @@ public class AppStateTracker {
|
||||
proto.write(ForceAppStandbyTrackerProto.POWER_SAVE_WHITELIST_APP_IDS, appId);
|
||||
}
|
||||
|
||||
for (int appId : mPowerWhitelistedUserAppIds) {
|
||||
proto.write(ForceAppStandbyTrackerProto.POWER_SAVE_USER_WHITELIST_APP_IDS, appId);
|
||||
}
|
||||
|
||||
for (int appId : mTempWhitelistedAppIds) {
|
||||
proto.write(ForceAppStandbyTrackerProto.TEMP_POWER_SAVE_WHITELIST_APP_IDS, appId);
|
||||
}
|
||||
|
||||
@@ -1540,7 +1540,7 @@ public class DeviceIdleController extends SystemService
|
||||
|
||||
mLocalActivityManager.registerScreenObserver(mScreenObserver);
|
||||
|
||||
passWhiteListToForceAppStandbyTrackerLocked();
|
||||
passWhiteListsToForceAppStandbyTrackerLocked();
|
||||
updateInteractivityLocked();
|
||||
}
|
||||
updateConnectivityState(null);
|
||||
@@ -1631,7 +1631,7 @@ public class DeviceIdleController extends SystemService
|
||||
mPowerSaveWhitelistAppsExceptIdle, mPowerSaveWhitelistUserApps,
|
||||
mPowerSaveWhitelistExceptIdleAppIds);
|
||||
|
||||
passWhiteListToForceAppStandbyTrackerLocked();
|
||||
passWhiteListsToForceAppStandbyTrackerLocked();
|
||||
}
|
||||
return true;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
@@ -1650,7 +1650,7 @@ public class DeviceIdleController extends SystemService
|
||||
mPowerSaveWhitelistExceptIdleAppIds);
|
||||
mPowerSaveWhitelistUserAppsExceptIdle.clear();
|
||||
|
||||
passWhiteListToForceAppStandbyTrackerLocked();
|
||||
passWhiteListsToForceAppStandbyTrackerLocked();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2589,7 +2589,7 @@ public class DeviceIdleController extends SystemService
|
||||
}
|
||||
mLocalPowerManager.setDeviceIdleWhitelist(mPowerSaveWhitelistAllAppIdArray);
|
||||
}
|
||||
passWhiteListToForceAppStandbyTrackerLocked();
|
||||
passWhiteListsToForceAppStandbyTrackerLocked();
|
||||
}
|
||||
|
||||
private void updateTempWhitelistAppIdsLocked(int appId, boolean adding) {
|
||||
@@ -2615,7 +2615,7 @@ public class DeviceIdleController extends SystemService
|
||||
}
|
||||
mLocalPowerManager.setDeviceIdleTempWhitelist(mTempWhitelistAppIdArray);
|
||||
}
|
||||
passWhiteListToForceAppStandbyTrackerLocked();
|
||||
passWhiteListsToForceAppStandbyTrackerLocked();
|
||||
}
|
||||
|
||||
private void reportPowerSaveWhitelistChangedLocked() {
|
||||
@@ -2630,9 +2630,10 @@ public class DeviceIdleController extends SystemService
|
||||
getContext().sendBroadcastAsUser(intent, UserHandle.SYSTEM);
|
||||
}
|
||||
|
||||
private void passWhiteListToForceAppStandbyTrackerLocked() {
|
||||
private void passWhiteListsToForceAppStandbyTrackerLocked() {
|
||||
mAppStateTracker.setPowerSaveWhitelistAppIds(
|
||||
mPowerSaveWhitelistExceptIdleAppIdArray,
|
||||
mPowerSaveWhitelistUserAppIdArray,
|
||||
mTempWhitelistAppIdArray);
|
||||
}
|
||||
|
||||
|
||||
@@ -445,7 +445,7 @@ public class AppStateTrackerTest {
|
||||
areRestricted(instance, UID_10_3, PACKAGE_3, JOBS_AND_ALARMS);
|
||||
areRestricted(instance, Process.SYSTEM_UID, PACKAGE_SYSTEM, NONE);
|
||||
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_1}, new int[] {UID_2});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_1}, new int[] {}, new int[] {UID_2});
|
||||
|
||||
areRestricted(instance, UID_1, PACKAGE_1, NONE);
|
||||
areRestricted(instance, UID_10_1, PACKAGE_1, NONE);
|
||||
@@ -481,6 +481,15 @@ public class AppStateTrackerTest {
|
||||
assertTrue(instance.isUidTempPowerSaveWhitelisted(UID_10_2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPowerSaveUserWhitelist() throws Exception {
|
||||
final AppStateTrackerTestable instance = newInstance();
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {}, new int[] {UID_1, UID_2}, new int[] {});
|
||||
assertTrue(instance.isUidPowerSaveUserWhitelisted(UID_1));
|
||||
assertTrue(instance.isUidPowerSaveUserWhitelisted(UID_2));
|
||||
assertFalse(instance.isUidPowerSaveUserWhitelisted(UID_3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUidStateForeground() throws Exception {
|
||||
final AppStateTrackerTestable instance = newInstance();
|
||||
@@ -861,7 +870,7 @@ public class AppStateTrackerTest {
|
||||
// -------------------------------------------------------------------------
|
||||
// Tests with system/user/temp whitelist.
|
||||
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_1, UID_2}, new int[] {});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_1, UID_2}, new int[] {}, new int[] {});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
verify(l, times(1)).updateAllJobs();
|
||||
@@ -873,7 +882,7 @@ public class AppStateTrackerTest {
|
||||
verify(l, times(0)).unblockAlarmsForUidPackage(anyInt(), anyString());
|
||||
reset(l);
|
||||
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {}, new int[] {});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
verify(l, times(1)).updateAllJobs();
|
||||
@@ -886,7 +895,8 @@ public class AppStateTrackerTest {
|
||||
reset(l);
|
||||
|
||||
// Update temp whitelist.
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {UID_1, UID_3});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {},
|
||||
new int[] {UID_1, UID_3});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
verify(l, times(1)).updateAllJobs();
|
||||
@@ -898,7 +908,7 @@ public class AppStateTrackerTest {
|
||||
verify(l, times(0)).unblockAlarmsForUidPackage(anyInt(), anyString());
|
||||
reset(l);
|
||||
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {UID_3});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {}, new int[] {UID_3});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
verify(l, times(1)).updateAllJobs();
|
||||
@@ -924,7 +934,7 @@ public class AppStateTrackerTest {
|
||||
verify(l, times(0)).unblockAlarmsForUidPackage(anyInt(), anyString());
|
||||
reset(l);
|
||||
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_1, UID_2}, new int[] {});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_1, UID_2}, new int[] {}, new int[] {});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
// Called once for updating all whitelist and once for updating temp whitelist
|
||||
@@ -937,7 +947,7 @@ public class AppStateTrackerTest {
|
||||
verify(l, times(0)).unblockAlarmsForUidPackage(anyInt(), anyString());
|
||||
reset(l);
|
||||
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {}, new int[] {});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
verify(l, times(1)).updateAllJobs();
|
||||
@@ -950,7 +960,8 @@ public class AppStateTrackerTest {
|
||||
reset(l);
|
||||
|
||||
// Update temp whitelist.
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {UID_1, UID_3});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {},
|
||||
new int[] {UID_1, UID_3});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
verify(l, times(1)).updateAllJobs();
|
||||
@@ -962,7 +973,7 @@ public class AppStateTrackerTest {
|
||||
verify(l, times(0)).unblockAlarmsForUidPackage(anyInt(), anyString());
|
||||
reset(l);
|
||||
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {UID_3});
|
||||
instance.setPowerSaveWhitelistAppIds(new int[] {UID_2}, new int[] {}, new int[] {UID_3});
|
||||
|
||||
waitUntilMainHandlerDrain();
|
||||
verify(l, times(1)).updateAllJobs();
|
||||
|
||||
Reference in New Issue
Block a user