@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;
* 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();
}
/**
+ * @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.
*
* Note clients normally shouldn't need to access it. It's only for dumpsys.
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));
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);
}
mLocalActivityManager.registerScreenObserver(mScreenObserver);
- passWhiteListToForceAppStandbyTrackerLocked();
+ passWhiteListsToForceAppStandbyTrackerLocked();
updateInteractivityLocked();
}
updateConnectivityState(null);
mPowerSaveWhitelistAppsExceptIdle, mPowerSaveWhitelistUserApps,
mPowerSaveWhitelistExceptIdleAppIds);
- passWhiteListToForceAppStandbyTrackerLocked();
+ passWhiteListsToForceAppStandbyTrackerLocked();
}
return true;
} catch (PackageManager.NameNotFoundException e) {
mPowerSaveWhitelistExceptIdleAppIds);
mPowerSaveWhitelistUserAppsExceptIdle.clear();
- passWhiteListToForceAppStandbyTrackerLocked();
+ passWhiteListsToForceAppStandbyTrackerLocked();
}
}
}
}
mLocalPowerManager.setDeviceIdleWhitelist(mPowerSaveWhitelistAllAppIdArray);
}
- passWhiteListToForceAppStandbyTrackerLocked();
+ passWhiteListsToForceAppStandbyTrackerLocked();
}
private void updateTempWhitelistAppIdsLocked(int appId, boolean adding) {
}
mLocalPowerManager.setDeviceIdleTempWhitelist(mTempWhitelistAppIdArray);
}
- passWhiteListToForceAppStandbyTrackerLocked();
+ passWhiteListsToForceAppStandbyTrackerLocked();
}
private void reportPowerSaveWhitelistChangedLocked() {
getContext().sendBroadcastAsUser(intent, UserHandle.SYSTEM);
}
- private void passWhiteListToForceAppStandbyTrackerLocked() {
+ private void passWhiteListsToForceAppStandbyTrackerLocked() {
mAppStateTracker.setPowerSaveWhitelistAppIds(
mPowerSaveWhitelistExceptIdleAppIdArray,
+ mPowerSaveWhitelistUserAppIdArray,
mTempWhitelistAppIdArray);
}
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);
}
@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();
callStart(instance);
// -------------------------------------------------------------------------
// 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();
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();
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();
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();
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
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();
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();
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();