diff options
| author | Nicholas Ambur <nambur@google.com> | 2020-12-04 08:34:48 -0800 |
|---|---|---|
| committer | Nicholas Ambur <nambur@google.com> | 2021-01-25 09:43:51 -0800 |
| commit | 4838c0051cfd6b796fad272ead42a95c6f2f28d6 (patch) | |
| tree | 376edefc0be659eb96b992470218c71679ea4a44 /core/java/android/os/PowerManager.java | |
| parent | 8b317b15a3316cece158708db4913b05334c800d (diff) | |
add full battery saver runtime modification API
New system API added for privledged clients to modify the full battery
saver mode policy. This API is used to override static settings at
runtime, and any overridden settings are cleared when exiting full
battery saver mode.
Bug: 172294448
Test: atest PowerManagerTest
Test: atest PowerManagerServiceTest
Test: atest BatterySaverPolicyTest
Test: build and boot ensuring SoundTrigger service behavior is not
changed
Change-Id: I41f968799b184a5dac702553379294795614be0a
Diffstat (limited to 'core/java/android/os/PowerManager.java')
| -rw-r--r-- | core/java/android/os/PowerManager.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 90648325ae0e..9a102a7c4b00 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -1638,6 +1638,65 @@ public final class PowerManager { } /** + * Gets the current policy for full power save mode. + * + * @return The {@link BatterySaverPolicyConfig} which is currently set for the full power save + * policy level. + * + * @hide + */ + @SystemApi + @NonNull + public BatterySaverPolicyConfig getFullPowerSavePolicy() { + try { + return mService.getFullPowerSavePolicy(); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** + * Sets the policy for full power save mode. + * + * Any settings set by this API will persist for only one session of full battery saver mode. + * The settings set by this API are cleared upon exit of full battery saver mode, and the + * caller is expected to set the desired values again for the next full battery saver mode + * session if desired. + * + * Use-cases: + * 1. Set policy outside of full battery saver mode + * - full policy set -> enter BS -> policy setting applied -> exit BS -> setting cleared + * 2. Set policy inside of full battery saver mode + * - enter BS -> full policy set -> policy setting applied -> exit BS -> setting cleared + * + * This API is intended to be used with {@link #getFullPowerSavePolicy()} API when a client only + * wants to modify a specific setting(s) and leave the remaining policy attributes the same. + * Example: + * BatterySaverPolicyConfig newFullPolicyConfig = + * new BatterySaverPolicyConfig.Builder(powerManager.getFullPowerSavePolicy()) + * .setSoundTriggerMode(PowerManager.SOUND_TRIGGER_MODE_ALL_DISABLED) + * .build(); + * powerManager.setFullPowerSavePolicy(newFullPolicyConfig); + * + * @return true if there was an effectual change. If full battery saver is enabled, then this + * will return true. + * + * @hide + */ + @SystemApi + @RequiresPermission(anyOf = { + android.Manifest.permission.DEVICE_POWER, + android.Manifest.permission.POWER_SAVER + }) + public boolean setFullPowerSavePolicy(@NonNull BatterySaverPolicyConfig config) { + try { + return mService.setFullPowerSavePolicy(config); + } catch (RemoteException e) { + throw e.rethrowFromSystemServer(); + } + } + + /** * Updates the current state of dynamic power savings and disable threshold. This is * a signal to the system which an app can update to serve as an indicator that * the user will be in a battery critical situation before being able to plug in. |
