Merge "Cache power whitelisted apps." into rvc-dev am: 8a4ea8bb12
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11881555 Change-Id: I405dd21e0c6da092021cd5775b452be3897898ce
This commit is contained in:
@@ -82,10 +82,10 @@ import android.os.BatteryStats;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.IDeviceIdleController;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.PowerWhitelistManager;
|
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
@@ -390,6 +390,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
DeviceStateReceiver deviceStateReceiver = new DeviceStateReceiver();
|
DeviceStateReceiver deviceStateReceiver = new DeviceStateReceiver();
|
||||||
IntentFilter deviceStates = new IntentFilter(BatteryManager.ACTION_CHARGING);
|
IntentFilter deviceStates = new IntentFilter(BatteryManager.ACTION_CHARGING);
|
||||||
deviceStates.addAction(BatteryManager.ACTION_DISCHARGING);
|
deviceStates.addAction(BatteryManager.ACTION_DISCHARGING);
|
||||||
|
deviceStates.addAction(PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED);
|
||||||
mContext.registerReceiver(deviceStateReceiver, deviceStates);
|
mContext.registerReceiver(deviceStateReceiver, deviceStates);
|
||||||
|
|
||||||
synchronized (mAppIdleLock) {
|
synchronized (mAppIdleLock) {
|
||||||
@@ -445,6 +446,9 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
|
|
||||||
mSystemServicesReady = true;
|
mSystemServicesReady = true;
|
||||||
|
|
||||||
|
// Offload to handler thread to avoid boot time impact.
|
||||||
|
mHandler.post(mInjector::updatePowerWhitelistCache);
|
||||||
|
|
||||||
boolean userFileExists;
|
boolean userFileExists;
|
||||||
synchronized (mAppIdleLock) {
|
synchronized (mAppIdleLock) {
|
||||||
userFileExists = mAppIdleHistory.userFileExists(UserHandle.USER_SYSTEM);
|
userFileExists = mAppIdleHistory.userFileExists(UserHandle.USER_SYSTEM);
|
||||||
@@ -1083,16 +1087,12 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
return STANDBY_BUCKET_EXEMPTED;
|
return STANDBY_BUCKET_EXEMPTED;
|
||||||
}
|
}
|
||||||
if (mSystemServicesReady) {
|
if (mSystemServicesReady) {
|
||||||
try {
|
|
||||||
// We allow all whitelisted apps, including those that don't want to be whitelisted
|
// We allow all whitelisted apps, including those that don't want to be whitelisted
|
||||||
// for idle mode, because app idle (aka app standby) is really not as big an issue
|
// for idle mode, because app idle (aka app standby) is really not as big an issue
|
||||||
// for controlling who participates vs. doze mode.
|
// for controlling who participates vs. doze mode.
|
||||||
if (mInjector.isNonIdleWhitelisted(packageName)) {
|
if (mInjector.isNonIdleWhitelisted(packageName)) {
|
||||||
return STANDBY_BUCKET_EXEMPTED;
|
return STANDBY_BUCKET_EXEMPTED;
|
||||||
}
|
}
|
||||||
} catch (RemoteException re) {
|
|
||||||
throw re.rethrowFromSystemServer();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isActiveDeviceAdmin(packageName, userId)) {
|
if (isActiveDeviceAdmin(packageName, userId)) {
|
||||||
return STANDBY_BUCKET_EXEMPTED;
|
return STANDBY_BUCKET_EXEMPTED;
|
||||||
@@ -1757,7 +1757,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Call on a system update to temporarily reset system app buckets. */
|
/** Call on system boot to get the initial set of headless system apps. */
|
||||||
private void loadHeadlessSystemAppCache() {
|
private void loadHeadlessSystemAppCache() {
|
||||||
Slog.d(TAG, "Loading headless system app cache. appIdleEnabled=" + mAppIdleEnabled);
|
Slog.d(TAG, "Loading headless system app cache. appIdleEnabled=" + mAppIdleEnabled);
|
||||||
final List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser(
|
final List<PackageInfo> packages = mPackageManager.getInstalledPackagesAsUser(
|
||||||
@@ -1809,8 +1809,6 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
+ "): " + mCarrierPrivilegedApps);
|
+ "): " + mCarrierPrivilegedApps);
|
||||||
}
|
}
|
||||||
|
|
||||||
final long now = System.currentTimeMillis();
|
|
||||||
|
|
||||||
pw.println();
|
pw.println();
|
||||||
pw.println("Settings:");
|
pw.println("Settings:");
|
||||||
|
|
||||||
@@ -1876,6 +1874,8 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
}
|
}
|
||||||
pw.println("]");
|
pw.println("]");
|
||||||
pw.println();
|
pw.println();
|
||||||
|
|
||||||
|
mInjector.dump(pw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1892,7 +1892,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
private PackageManagerInternal mPackageManagerInternal;
|
private PackageManagerInternal mPackageManagerInternal;
|
||||||
private DisplayManager mDisplayManager;
|
private DisplayManager mDisplayManager;
|
||||||
private PowerManager mPowerManager;
|
private PowerManager mPowerManager;
|
||||||
private PowerWhitelistManager mPowerWhitelistManager;
|
private IDeviceIdleController mDeviceIdleController;
|
||||||
private CrossProfileAppsInternal mCrossProfileAppsInternal;
|
private CrossProfileAppsInternal mCrossProfileAppsInternal;
|
||||||
int mBootPhase;
|
int mBootPhase;
|
||||||
/**
|
/**
|
||||||
@@ -1900,6 +1900,11 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
* automatically placed in the RESTRICTED bucket.
|
* automatically placed in the RESTRICTED bucket.
|
||||||
*/
|
*/
|
||||||
long mAutoRestrictedBucketDelayMs = ONE_DAY;
|
long mAutoRestrictedBucketDelayMs = ONE_DAY;
|
||||||
|
/**
|
||||||
|
* Cached set of apps that are power whitelisted, including those not whitelisted from idle.
|
||||||
|
*/
|
||||||
|
@GuardedBy("mPowerWhitelistedApps")
|
||||||
|
private final ArraySet<String> mPowerWhitelistedApps = new ArraySet<>();
|
||||||
|
|
||||||
Injector(Context context, Looper looper) {
|
Injector(Context context, Looper looper) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -1916,7 +1921,8 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
|
|
||||||
void onBootPhase(int phase) {
|
void onBootPhase(int phase) {
|
||||||
if (phase == PHASE_SYSTEM_SERVICES_READY) {
|
if (phase == PHASE_SYSTEM_SERVICES_READY) {
|
||||||
mPowerWhitelistManager = mContext.getSystemService(PowerWhitelistManager.class);
|
mDeviceIdleController = IDeviceIdleController.Stub.asInterface(
|
||||||
|
ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
|
||||||
mBatteryStats = IBatteryStats.Stub.asInterface(
|
mBatteryStats = IBatteryStats.Stub.asInterface(
|
||||||
ServiceManager.getService(BatteryStats.SERVICE_NAME));
|
ServiceManager.getService(BatteryStats.SERVICE_NAME));
|
||||||
mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
|
mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
|
||||||
@@ -1967,8 +1973,34 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
return mBatteryManager.isCharging();
|
return mBatteryManager.isCharging();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isNonIdleWhitelisted(String packageName) throws RemoteException {
|
boolean isNonIdleWhitelisted(String packageName) {
|
||||||
return mPowerWhitelistManager.isWhitelisted(packageName, false);
|
if (mBootPhase < PHASE_SYSTEM_SERVICES_READY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
synchronized (mPowerWhitelistedApps) {
|
||||||
|
return mPowerWhitelistedApps.contains(packageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePowerWhitelistCache() {
|
||||||
|
if (mBootPhase < PHASE_SYSTEM_SERVICES_READY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Don't call out to DeviceIdleController with the lock held.
|
||||||
|
final String[] whitelistedPkgs =
|
||||||
|
mDeviceIdleController.getFullPowerWhitelistExceptIdle();
|
||||||
|
synchronized (mPowerWhitelistedApps) {
|
||||||
|
mPowerWhitelistedApps.clear();
|
||||||
|
final int len = whitelistedPkgs.length;
|
||||||
|
for (int i = 0; i < len; ++i) {
|
||||||
|
mPowerWhitelistedApps.add(whitelistedPkgs[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// Should not happen.
|
||||||
|
Slog.wtf(TAG, "Failed to get power whitelist", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isRestrictedBucketEnabled() {
|
boolean isRestrictedBucketEnabled() {
|
||||||
@@ -2055,6 +2087,19 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
}
|
}
|
||||||
return mCrossProfileAppsInternal.getTargetUserProfiles(pkg, userId);
|
return mCrossProfileAppsInternal.getTargetUserProfiles(pkg, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dump(PrintWriter pw) {
|
||||||
|
pw.println("mPowerWhitelistedApps=[");
|
||||||
|
synchronized (mPowerWhitelistedApps) {
|
||||||
|
for (int i = mPowerWhitelistedApps.size() - 1; i >= 0; --i) {
|
||||||
|
pw.print(" ");
|
||||||
|
pw.print(mPowerWhitelistedApps.valueAt(i));
|
||||||
|
pw.println(",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pw.println("]");
|
||||||
|
pw.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AppStandbyHandler extends Handler {
|
class AppStandbyHandler extends Handler {
|
||||||
@@ -2140,6 +2185,11 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
case BatteryManager.ACTION_DISCHARGING:
|
case BatteryManager.ACTION_DISCHARGING:
|
||||||
setChargingState(false);
|
setChargingState(false);
|
||||||
break;
|
break;
|
||||||
|
case PowerManager.ACTION_POWER_SAVE_WHITELIST_CHANGED:
|
||||||
|
if (mSystemServicesReady) {
|
||||||
|
mHandler.post(mInjector::updatePowerWhitelistCache);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ public class AppStandbyControllerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isNonIdleWhitelisted(String packageName) throws RemoteException {
|
boolean isNonIdleWhitelisted(String packageName) {
|
||||||
return mNonIdleWhitelistApps.contains(packageName);
|
return mNonIdleWhitelistApps.contains(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user