Merge "Require DEVICE_POWER permission for DOZE_WAKE_LOCK." into lmp-dev
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 @@
* <p>
* 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.
+ * </p><p>
+ * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission.
* </p>
*
* {@hide}
@@ -331,6 +333,12 @@
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 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..a10136be 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 @@
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);