Add PowerWhitelistManager.isWhitelisted.
The "XXXExceptIdle" lists and methods are expected to be a superset of the XXX methods. That's not immediately obvious from the method names. This effort is to clean up the naming and better document actual behavior. As part of this, we're moving the isApplicationWhitelisted methods to PowerWhitelistManager to also help clean up the interface between the apex and the rest of the system. Bug: 142420609 Bug: 144864180 Bug: 145014493 Test: atest CtsBatterySavingTestCases:DeviceIdleTest Test: atest CtsSecurityTestCases:DeviceIdleControllerTest Test: atest FrameworksServicesTests:AppStandbyControllerTests Change-Id: I1d248a075992e2dc279a7bfec44f38c7e51780b4
This commit is contained in:
@@ -70,17 +70,4 @@ public class DeviceIdleManager {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether a given package is in the power-save whitelist or not.
|
||||
* @hide
|
||||
*/
|
||||
public boolean isApplicationWhitelisted(@NonNull String packageName) {
|
||||
try {
|
||||
return mService.isPowerSaveWhitelistApp(packageName);
|
||||
} catch (RemoteException e) {
|
||||
e.rethrowFromSystemServer();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +123,26 @@ public class PowerWhitelistManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the app is whitelisted from power save restrictions. This does not include
|
||||
* temporarily whitelisted apps.
|
||||
*
|
||||
* @param includingIdle Set to true if the app should be whitelisted from device
|
||||
* idle as well as other power save restrictions
|
||||
* @hide
|
||||
*/
|
||||
public boolean isWhitelisted(@NonNull String packageName, boolean includingIdle) {
|
||||
try {
|
||||
if (includingIdle) {
|
||||
return mService.isPowerSaveWhitelistApp(packageName);
|
||||
} else {
|
||||
return mService.isPowerSaveWhitelistExceptIdleApp(packageName);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an app to the temporary whitelist for a short amount of time.
|
||||
*
|
||||
|
||||
@@ -79,10 +79,10 @@ import android.os.BatteryStats;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.os.IDeviceIdleController;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.PowerManager;
|
||||
import android.os.PowerWhitelistManager;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
@@ -1009,7 +1009,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
// 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 controlling who participates vs. doze mode.
|
||||
if (mInjector.isPowerSaveWhitelistExceptIdleApp(packageName)) {
|
||||
if (mInjector.isNonIdleWhitelisted(packageName)) {
|
||||
return true;
|
||||
}
|
||||
} catch (RemoteException re) {
|
||||
@@ -1636,12 +1636,12 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
|
||||
private final Context mContext;
|
||||
private final Looper mLooper;
|
||||
private IDeviceIdleController mDeviceIdleController;
|
||||
private IBatteryStats mBatteryStats;
|
||||
private BatteryManager mBatteryManager;
|
||||
private PackageManagerInternal mPackageManagerInternal;
|
||||
private DisplayManager mDisplayManager;
|
||||
private PowerManager mPowerManager;
|
||||
private PowerWhitelistManager mPowerWhitelistManager;
|
||||
private CrossProfileAppsInternal mCrossProfileAppsInternal;
|
||||
int mBootPhase;
|
||||
/**
|
||||
@@ -1665,8 +1665,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
|
||||
void onBootPhase(int phase) {
|
||||
if (phase == PHASE_SYSTEM_SERVICES_READY) {
|
||||
mDeviceIdleController = IDeviceIdleController.Stub.asInterface(
|
||||
ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
|
||||
mPowerWhitelistManager = mContext.getSystemService(PowerWhitelistManager.class);
|
||||
mBatteryStats = IBatteryStats.Stub.asInterface(
|
||||
ServiceManager.getService(BatteryStats.SERVICE_NAME));
|
||||
mPackageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
|
||||
@@ -1717,8 +1716,8 @@ public class AppStandbyController implements AppStandbyInternal {
|
||||
return mBatteryManager.isCharging();
|
||||
}
|
||||
|
||||
boolean isPowerSaveWhitelistExceptIdleApp(String packageName) throws RemoteException {
|
||||
return mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName);
|
||||
boolean isNonIdleWhitelisted(String packageName) throws RemoteException {
|
||||
return mPowerWhitelistManager.isWhitelisted(packageName, false);
|
||||
}
|
||||
|
||||
File getDataSystemDirectory() {
|
||||
|
||||
@@ -922,7 +922,7 @@ public final class PowerManager {
|
||||
final IThermalService mThermalService;
|
||||
|
||||
/** We lazily initialize it.*/
|
||||
private DeviceIdleManager mDeviceIdleManager;
|
||||
private PowerWhitelistManager mPowerWhitelistManager;
|
||||
|
||||
private final ArrayMap<OnThermalStatusChangedListener, IThermalStatusListener>
|
||||
mListenerMap = new ArrayMap<>();
|
||||
@@ -938,12 +938,12 @@ public final class PowerManager {
|
||||
mHandler = handler;
|
||||
}
|
||||
|
||||
private DeviceIdleManager getDeviceIdleManager() {
|
||||
if (mDeviceIdleManager == null) {
|
||||
private PowerWhitelistManager getPowerWhitelistManager() {
|
||||
if (mPowerWhitelistManager == null) {
|
||||
// No need for synchronization; getSystemService() will return the same object anyway.
|
||||
mDeviceIdleManager = mContext.getSystemService(DeviceIdleManager.class);
|
||||
mPowerWhitelistManager = mContext.getSystemService(PowerWhitelistManager.class);
|
||||
}
|
||||
return mDeviceIdleManager;
|
||||
return mPowerWhitelistManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1786,7 +1786,7 @@ public final class PowerManager {
|
||||
* {@link android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS}.
|
||||
*/
|
||||
public boolean isIgnoringBatteryOptimizations(String packageName) {
|
||||
return getDeviceIdleManager().isApplicationWhitelisted(packageName);
|
||||
return getPowerWhitelistManager().isWhitelisted(packageName, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -161,7 +161,7 @@ public class AppStandbyControllerTests {
|
||||
long mElapsedRealtime;
|
||||
boolean mIsAppIdleEnabled = true;
|
||||
boolean mIsCharging;
|
||||
List<String> mPowerSaveWhitelistExceptIdle = new ArrayList<>();
|
||||
List<String> mNonIdleWhitelistApps = new ArrayList<>();
|
||||
boolean mDisplayOn;
|
||||
DisplayManager.DisplayListener mDisplayListener;
|
||||
String mBoundWidgetPackage = PACKAGE_EXEMPTED_1;
|
||||
@@ -203,8 +203,8 @@ public class AppStandbyControllerTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isPowerSaveWhitelistExceptIdleApp(String packageName) throws RemoteException {
|
||||
return mPowerSaveWhitelistExceptIdle.contains(packageName);
|
||||
boolean isNonIdleWhitelisted(String packageName) throws RemoteException {
|
||||
return mNonIdleWhitelistApps.contains(packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user