From a7a93b53049c25a74119eaa5b9b0672aa68882c4 Mon Sep 17 00:00:00 2001 From: Robert Horvath Date: Tue, 14 Feb 2023 09:28:00 +0100 Subject: [PATCH] Open POLICY_CHANGED broadcast up to public API (Non-privileged) apps can query aspects of the Low Power Standby policy. They should also be able to react to changes in the policy. Bug: 234002812 Test: atest LowPowerStandbyTest Change-Id: Id475e8799611444dda77b00c7a4eec103002cdc8 --- core/api/current.txt | 1 + core/api/system-current.txt | 1 - core/java/android/os/PowerManager.java | 10 ++++------ .../server/power/LowPowerStandbyController.java | 4 +--- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 88ee3a4c7cf47..600ad08524232 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -33305,6 +33305,7 @@ package android.os { field public static final String ACTION_DEVICE_IDLE_MODE_CHANGED = "android.os.action.DEVICE_IDLE_MODE_CHANGED"; field public static final String ACTION_DEVICE_LIGHT_IDLE_MODE_CHANGED = "android.os.action.LIGHT_DEVICE_IDLE_MODE_CHANGED"; field public static final String ACTION_LOW_POWER_STANDBY_ENABLED_CHANGED = "android.os.action.LOW_POWER_STANDBY_ENABLED_CHANGED"; + field public static final String ACTION_LOW_POWER_STANDBY_POLICY_CHANGED = "android.os.action.LOW_POWER_STANDBY_POLICY_CHANGED"; field public static final String ACTION_POWER_SAVE_MODE_CHANGED = "android.os.action.POWER_SAVE_MODE_CHANGED"; field @Deprecated public static final int FULL_WAKE_LOCK = 26; // 0x1a field public static final int LOCATION_MODE_ALL_DISABLED_WHEN_SCREEN_OFF = 2; // 0x2 diff --git a/core/api/system-current.txt b/core/api/system-current.txt index fde95bd3fb1e4..4e5a684d08cad 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -10638,7 +10638,6 @@ package android.os { method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setPowerSaveModeEnabled(boolean); method @RequiresPermission(android.Manifest.permission.WRITE_DREAM_STATE) public void suppressAmbientDisplay(@NonNull String, boolean); method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.USER_ACTIVITY}) public void userActivity(long, int, int); - field @RequiresPermission(android.Manifest.permission.MANAGE_LOW_POWER_STANDBY) public static final String ACTION_LOW_POWER_STANDBY_POLICY_CHANGED = "android.os.action.LOW_POWER_STANDBY_POLICY_CHANGED"; field public static final int POWER_SAVE_MODE_TRIGGER_DYNAMIC = 1; // 0x1 field public static final int POWER_SAVE_MODE_TRIGGER_PERCENTAGE = 0; // 0x0 field public static final String REBOOT_USERSPACE = "userspace"; diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index 13d54ef7b12a2..c021cadd36669 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -2968,15 +2968,13 @@ public final class PowerManager { "android.os.action.LOW_POWER_STANDBY_ENABLED_CHANGED"; /** - * Intent that is broadcast when Low Power Standby is enabled or disabled. + * Intent that is broadcast when Low Power Standby policy is changed. * This broadcast is only sent to registered receivers. * - * @see #getLowPowerStandbyPolicy - * @see #setLowPowerStandbyPolicy - * @hide + * @see #isExemptFromLowPowerStandby() + * @see #isAllowedInLowPowerStandby(int) + * @see #isAllowedInLowPowerStandby(String) */ - @SystemApi - @RequiresPermission(android.Manifest.permission.MANAGE_LOW_POWER_STANDBY) @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) public static final String ACTION_LOW_POWER_STANDBY_POLICY_CHANGED = "android.os.action.LOW_POWER_STANDBY_POLICY_CHANGED"; diff --git a/services/core/java/com/android/server/power/LowPowerStandbyController.java b/services/core/java/com/android/server/power/LowPowerStandbyController.java index 0dc5f76dfd92d..cf59a7cd98277 100644 --- a/services/core/java/com/android/server/power/LowPowerStandbyController.java +++ b/services/core/java/com/android/server/power/LowPowerStandbyController.java @@ -19,7 +19,6 @@ package com.android.server.power; import static android.os.PowerManager.LOW_POWER_STANDBY_ALLOWED_REASON_TEMP_POWER_SAVE_ALLOWLIST; import static android.os.PowerManager.lowPowerStandbyAllowedReasonsToString; -import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; import android.app.AlarmManager; @@ -692,8 +691,7 @@ public class LowPowerStandbyController { final Intent intent = new Intent( PowerManager.ACTION_LOW_POWER_STANDBY_POLICY_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_FOREGROUND); - mContext.sendBroadcastAsUser(intent, UserHandle.ALL, - Manifest.permission.MANAGE_LOW_POWER_STANDBY); + mContext.sendBroadcastAsUser(intent, UserHandle.ALL); } private void onStandbyTimeoutExpired() {