diff options
| author | Robert Horvath <robhor@google.com> | 2021-10-21 15:14:25 +0200 |
|---|---|---|
| committer | Robert Horvath <robhor@google.com> | 2022-01-27 23:08:26 +0100 |
| commit | 570645567faacbbdedf5c53cde751f4406366242 (patch) | |
| tree | 4a8e928a10760039960a3c6e1a8334ca748825b5 /core/java/android/os/PowerManager.java | |
| parent | f7e59f08d2737e060f3c708ff0477c58443d4ec0 (diff) | |
Introduce Low Power Standby API and wakelock restrictions
In Low Power Standby, additional restrictions are placed on apps that
are in a process state of FOREGROUND_SERVICE or less important
during standby (while the device is non-interactive):
- Wakelocks are disabled
- Network access is blocked
During doze maintenance windows the restrictions are lifted temporarily.
This change introduces the APIs for Low Power Standby, as well as
the wakelock restrictions.
This feature is targeting TVs. To prevent Low Power Standby from being
enabled on other devices, the feature is guarded by the config flag
config_lowPowerStandbySupported.
Bug: 190822356
Test: atest LowPowerStandbyControllerTest PowerManagerServiceTest
Ignore-AOSP-First: New permission only added internally for now.
Change-Id: Ia40f8a0fc4b366860af58ad76c988f93a5d41936
Diffstat (limited to 'core/java/android/os/PowerManager.java')
| -rw-r--r-- | core/java/android/os/PowerManager.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 881fcedea6f7..87e488b89212 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -2146,6 +2146,64 @@ public final class PowerManager { } /** + * Returns true if Low Power Standby is supported on this device. + * + * @hide + */ + @SystemApi + @RequiresPermission(anyOf = { + android.Manifest.permission.MANAGE_LOW_POWER_STANDBY, + android.Manifest.permission.DEVICE_POWER + }) + public boolean isLowPowerStandbySupported() { + try { + return mService.isLowPowerStandbySupported(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Returns true if Low Power Standby is enabled. + * + * <p>When Low Power Standby is enabled, apps (including apps running foreground services) are + * subject to additional restrictions while the device is non-interactive, outside of device + * idle maintenance windows: Their network access is disabled, and any wakelocks they hold are + * ignored. + * + * <p>When Low Power Standby is enabled or disabled, a Intent with action + * {@link #ACTION_LOW_POWER_STANDBY_ENABLED_CHANGED} is broadcast to registered receivers. + */ + public boolean isLowPowerStandbyEnabled() { + try { + return mService.isLowPowerStandbyEnabled(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Set whether Low Power Standby is enabled. + * Does nothing if Low Power Standby is not supported. + * + * @see #isLowPowerStandbySupported() + * @see #isLowPowerStandbyEnabled() + * @hide + */ + @SystemApi + @RequiresPermission(anyOf = { + android.Manifest.permission.MANAGE_LOW_POWER_STANDBY, + android.Manifest.permission.DEVICE_POWER + }) + public void setLowPowerStandbyEnabled(boolean enabled) { + try { + mService.setLowPowerStandbyEnabled(enabled); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Return whether the given application package name is on the device's power allowlist. * Apps can be placed on the allowlist through the settings UI invoked by * {@link android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS}. @@ -2631,6 +2689,16 @@ public final class PowerManager { = "android.os.action.POWER_SAVE_TEMP_WHITELIST_CHANGED"; /** + * Intent that is broadcast when Low Power Standby is enabled or disabled. + * This broadcast is only sent to registered receivers. + * + * @see #isLowPowerStandbyEnabled() + */ + @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) + public static final String ACTION_LOW_POWER_STANDBY_ENABLED_CHANGED = + "android.os.action.LOW_POWER_STANDBY_ENABLED_CHANGED"; + + /** * Constant for PreIdleTimeout normal mode (default mode, not short nor extend timeout) . * @hide */ |
