From 72671fbb2036e13fccb0b8eeb98be606de1819dd Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Thu, 21 Aug 2014 21:41:09 -0700 Subject: Require DEVICE_POWER permission for DOZE_WAKE_LOCK. This wake lock is only intended to be used internally. Change-Id: I8d109c492605673616cf7f4f31f082a42fb1d912 --- core/java/android/os/PowerManager.java | 14 ++++++++------ .../java/com/android/server/power/PowerManagerService.java | 4 ++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java index b167549..67ec563 100644 --- a/core/java/android/os/PowerManager.java +++ b/core/java/android/os/PowerManager.java @@ -195,6 +195,8 @@ public final class PowerManager { *

* This is used by the dream manager to implement doze mode. It currently * has no effect unless the power manager is in the dozing state. + *

+ * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. *

* * {@hide} @@ -331,6 +333,12 @@ public final class PowerManager { public static final int GO_TO_SLEEP_REASON_HDMI = 5; /** + * Go to sleep flag: Skip dozing state and directly go to full sleep. + * @hide + */ + public static final int GO_TO_SLEEP_FLAG_NO_DOZE = 1 << 0; + + /** * The value to pass as the 'reason' argument to reboot() to * reboot into recovery mode (for applying system updates, doing * factory resets, etc.). @@ -343,12 +351,6 @@ public final class PowerManager { */ public static final String REBOOT_RECOVERY = "recovery"; - /** - * Go to sleep flag: Skip dozing state and directly go to full sleep. - * @hide - */ - public static final int GO_TO_SLEEP_FLAG_NO_DOZE = 1 << 0; - final Context mContext; final IPowerManager mService; final Handler mHandler; diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index 9734bd4..a10136b 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -2774,6 +2774,10 @@ public final class PowerManagerService extends com.android.server.SystemService PowerManager.validateWakeLockParameters(flags, tag); mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null); + if ((flags & PowerManager.DOZE_WAKE_LOCK) != 0) { + mContext.enforceCallingOrSelfPermission( + android.Manifest.permission.DEVICE_POWER, null); + } if (ws != null && ws.size() != 0) { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.UPDATE_DEVICE_STATS, null); -- cgit v1.1