Merge "Add PowerWhitelistManager.isWhitelisted." into rvc-dev am: b65d429e3f
Change-Id: I3a74e7d61f827f9576b84346290615750aa0e30d
This commit is contained in:
@@ -70,17 +70,4 @@ public class DeviceIdleManager {
|
|||||||
return new String[0];
|
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.
|
* 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.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;
|
||||||
@@ -1009,7 +1009,7 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
// 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.isPowerSaveWhitelistExceptIdleApp(packageName)) {
|
if (mInjector.isNonIdleWhitelisted(packageName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
@@ -1636,12 +1636,12 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final Looper mLooper;
|
private final Looper mLooper;
|
||||||
private IDeviceIdleController mDeviceIdleController;
|
|
||||||
private IBatteryStats mBatteryStats;
|
private IBatteryStats mBatteryStats;
|
||||||
private BatteryManager mBatteryManager;
|
private BatteryManager mBatteryManager;
|
||||||
private PackageManagerInternal mPackageManagerInternal;
|
private PackageManagerInternal mPackageManagerInternal;
|
||||||
private DisplayManager mDisplayManager;
|
private DisplayManager mDisplayManager;
|
||||||
private PowerManager mPowerManager;
|
private PowerManager mPowerManager;
|
||||||
|
private PowerWhitelistManager mPowerWhitelistManager;
|
||||||
private CrossProfileAppsInternal mCrossProfileAppsInternal;
|
private CrossProfileAppsInternal mCrossProfileAppsInternal;
|
||||||
int mBootPhase;
|
int mBootPhase;
|
||||||
/**
|
/**
|
||||||
@@ -1665,8 +1665,7 @@ 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) {
|
||||||
mDeviceIdleController = IDeviceIdleController.Stub.asInterface(
|
mPowerWhitelistManager = mContext.getSystemService(PowerWhitelistManager.class);
|
||||||
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);
|
||||||
@@ -1717,8 +1716,8 @@ public class AppStandbyController implements AppStandbyInternal {
|
|||||||
return mBatteryManager.isCharging();
|
return mBatteryManager.isCharging();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isPowerSaveWhitelistExceptIdleApp(String packageName) throws RemoteException {
|
boolean isNonIdleWhitelisted(String packageName) throws RemoteException {
|
||||||
return mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName);
|
return mPowerWhitelistManager.isWhitelisted(packageName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
File getDataSystemDirectory() {
|
File getDataSystemDirectory() {
|
||||||
|
|||||||
@@ -922,7 +922,7 @@ public final class PowerManager {
|
|||||||
final IThermalService mThermalService;
|
final IThermalService mThermalService;
|
||||||
|
|
||||||
/** We lazily initialize it.*/
|
/** We lazily initialize it.*/
|
||||||
private DeviceIdleManager mDeviceIdleManager;
|
private PowerWhitelistManager mPowerWhitelistManager;
|
||||||
|
|
||||||
private final ArrayMap<OnThermalStatusChangedListener, IThermalStatusListener>
|
private final ArrayMap<OnThermalStatusChangedListener, IThermalStatusListener>
|
||||||
mListenerMap = new ArrayMap<>();
|
mListenerMap = new ArrayMap<>();
|
||||||
@@ -938,12 +938,12 @@ public final class PowerManager {
|
|||||||
mHandler = handler;
|
mHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DeviceIdleManager getDeviceIdleManager() {
|
private PowerWhitelistManager getPowerWhitelistManager() {
|
||||||
if (mDeviceIdleManager == null) {
|
if (mPowerWhitelistManager == null) {
|
||||||
// No need for synchronization; getSystemService() will return the same object anyway.
|
// 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}.
|
* {@link android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS}.
|
||||||
*/
|
*/
|
||||||
public boolean isIgnoringBatteryOptimizations(String packageName) {
|
public boolean isIgnoringBatteryOptimizations(String packageName) {
|
||||||
return getDeviceIdleManager().isApplicationWhitelisted(packageName);
|
return getPowerWhitelistManager().isWhitelisted(packageName, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ public class AppStandbyControllerTests {
|
|||||||
long mElapsedRealtime;
|
long mElapsedRealtime;
|
||||||
boolean mIsAppIdleEnabled = true;
|
boolean mIsAppIdleEnabled = true;
|
||||||
boolean mIsCharging;
|
boolean mIsCharging;
|
||||||
List<String> mPowerSaveWhitelistExceptIdle = new ArrayList<>();
|
List<String> mNonIdleWhitelistApps = new ArrayList<>();
|
||||||
boolean mDisplayOn;
|
boolean mDisplayOn;
|
||||||
DisplayManager.DisplayListener mDisplayListener;
|
DisplayManager.DisplayListener mDisplayListener;
|
||||||
String mBoundWidgetPackage = PACKAGE_EXEMPTED_1;
|
String mBoundWidgetPackage = PACKAGE_EXEMPTED_1;
|
||||||
@@ -203,8 +203,8 @@ public class AppStandbyControllerTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isPowerSaveWhitelistExceptIdleApp(String packageName) throws RemoteException {
|
boolean isNonIdleWhitelisted(String packageName) throws RemoteException {
|
||||||
return mPowerSaveWhitelistExceptIdle.contains(packageName);
|
return mNonIdleWhitelistApps.contains(packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user