1616
1717package android .os ;
1818
19+ import android .content .Context ;
1920import android .util .Log ;
2021
2122/**
4243 * wl.release();
4344 * }
4445 * </p><p>
45- * The following flags are defined, with varying effects on system power.
46- * <i>These flags are mutually exclusive - you may only specify one of them.</i>
46+ * The following wake lock levels are defined, with varying effects on system power.
47+ * <i>These levels are mutually exclusive - you may only specify one of them.</i>
4748 *
4849 * <table border="2" width="85%" align="center" frame="hsides" rules="rows">
4950 * <thead>
@@ -177,7 +178,7 @@ public final class PowerManager {
177178 /**
178179 * Wake lock level: Turns the screen off when the proximity sensor activates.
179180 * <p>
180- * Since not all devices have proximity sensors, use {@link #getSupportedWakeLockFlags }
181+ * Since not all devices have proximity sensors, use {@link #isWakeLockLevelSupported }
181182 * to determine whether this wake lock level is supported.
182183 * </p>
183184 *
@@ -226,29 +227,24 @@ public final class PowerManager {
226227 */
227228 public static final int WAIT_FOR_PROXIMITY_NEGATIVE = 1 ;
228229
229- /**
230- * Brightness value to use when battery is low.
231- * @hide
232- */
233- public static final int BRIGHTNESS_LOW_BATTERY = 10 ;
234-
235230 /**
236231 * Brightness value for fully on.
237232 * @hide
238233 */
239234 public static final int BRIGHTNESS_ON = 255 ;
240235
241236 /**
242- * Brightness value for dim backlight .
237+ * Brightness value for fully off .
243238 * @hide
244239 */
245- public static final int BRIGHTNESS_DIM = 20 ;
240+ public static final int BRIGHTNESS_OFF = 0 ;
246241
247242 /**
248- * Brightness value for fully off.
243+ * A nominal default brightness value.
244+ * Use {@link #getDefaultScreenBrightnessSetting()} instead.
249245 * @hide
250246 */
251- public static final int BRIGHTNESS_OFF = 0 ;
247+ private static final int BRIGHTNESS_DEFAULT = 102 ;
252248
253249 // Note: Be sure to update android.os.BatteryStats and PowerManager.h
254250 // if adding or modifying user activity event constants.
@@ -271,17 +267,81 @@ public final class PowerManager {
271267 */
272268 public static final int USER_ACTIVITY_EVENT_TOUCH = 2 ;
273269
270+ /**
271+ * User activity flag: Do not restart the user activity timeout or brighten
272+ * the display in response to user activity if it is already dimmed.
273+ * @hide
274+ */
275+ public static final int USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS = 1 << 0 ;
276+
277+ /**
278+ * Special wake lock tag used for the wake lock in the Window Manager that handles the
279+ * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} flag.
280+ * @hide
281+ */
282+ public static final String KEEP_SCREEN_ON_FLAG_TAG = "KEEP_SCREEN_ON_FLAG" ;
283+
284+ /**
285+ * Go to sleep reason code: Going to sleep due by user request.
286+ * @hide
287+ */
288+ public static final int GO_TO_SLEEP_REASON_USER = 0 ;
289+
290+ /**
291+ * Go to sleep reason code: Going to sleep due by request of the
292+ * device administration policy.
293+ * @hide
294+ */
295+ public static final int GO_TO_SLEEP_REASON_DEVICE_ADMIN = 1 ;
296+
297+ /**
298+ * Go to sleep reason code: Going to sleep due to a screen timeout.
299+ * @hide
300+ */
301+ public static final int GO_TO_SLEEP_REASON_TIMEOUT = 2 ;
302+
303+ final Context mContext ;
274304 final IPowerManager mService ;
275305 final Handler mHandler ;
276306
277307 /**
278308 * {@hide}
279309 */
280- public PowerManager (IPowerManager service , Handler handler ) {
310+ public PowerManager (Context context , IPowerManager service , Handler handler ) {
311+ mContext = context ;
281312 mService = service ;
282313 mHandler = handler ;
283314 }
284315
316+ /**
317+ * Gets the minimum supported screen brightness setting.
318+ * The screen may be allowed to become dimmer than this value but
319+ * this is the minimum value that can be set by the user.
320+ * @hide
321+ */
322+ public int getMinimumScreenBrightnessSetting () {
323+ return mContext .getResources ().getInteger (
324+ com .android .internal .R .integer .config_screenBrightnessDim );
325+ }
326+
327+ /**
328+ * Gets the maximum supported screen brightness setting.
329+ * The screen may be allowed to become dimmer than this value but
330+ * this is the maximum value that can be set by the user.
331+ * @hide
332+ */
333+ public int getMaximumScreenBrightnessSetting () {
334+ return BRIGHTNESS_ON ;
335+ }
336+
337+ /**
338+ * Gets the default screen brightness setting.
339+ * @hide
340+ */
341+ public int getDefaultScreenBrightnessSetting () {
342+ return BRIGHTNESS_DEFAULT ;
343+ }
344+
285345 /**
286346 * Creates a new wake lock with the specified level and flags.
287347 * <p>
@@ -360,8 +420,10 @@ public static void validateWakeLockParameters(int levelAndFlags, String tag) {
360420 /**
361421 * Notifies the power manager that user activity happened.
362422 * <p>
363- * Turns the device from whatever state it's in to full on, and resets
364- * the auto-off timer.
423+ * Resets the auto-off timer and brightens the screen if the device
424+ * is not asleep. This is what happens normally when a key or the touch
425+ * screen is pressed or when some other user activity occurs.
426+ * This method does not wake up the device if it has been put to sleep.
365427 * </p><p>
366428 * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission.
367429 * </p>
@@ -375,19 +437,23 @@ public static void validateWakeLockParameters(int levelAndFlags, String tag) {
375437 * We want the device to stay on while the button is down, but we're about
376438 * to turn off the screen so we don't want the keyboard backlight to turn on again.
377439 * Otherwise the lights flash on and then off and it looks weird.
440+ *
441+ * @see #wakeUp
442+ * @see #goToSleep
378443 */
379444 public void userActivity (long when , boolean noChangeLights ) {
380445 try {
381- mService .userActivity (when , noChangeLights );
446+ mService .userActivity (when , USER_ACTIVITY_EVENT_OTHER ,
447+ noChangeLights ? USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS : 0 );
382448 } catch (RemoteException e ) {
383449 }
384450 }
385451
386452 /**
387453 * Forces the device to go to sleep.
388454 * <p>
389- * Overrides all the wake locks that are held. This is what happen when the power
390- * key is pressed to turn off the screen.
455+ * Overrides all the wake locks that are held.
456+ * This is what happens when the power key is pressed to turn off the screen.
391457 * </p><p>
392458 * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission.
393459 * </p>
@@ -396,10 +462,37 @@ public void userActivity(long when, boolean noChangeLights) {
396462 * {@link SystemClock#uptimeMillis()} time base. This timestamp is used to correctly
397463 * order the user activity with other power management functions. It should be set
398464 * to the timestamp of the input event that caused the request to go to sleep.
465+ *
466+ * @see #userActivity
467+ * @see #wakeUp
399468 */
400469 public void goToSleep (long time ) {
401470 try {
402- mService .goToSleep (time );
471+ mService .goToSleep (time , GO_TO_SLEEP_REASON_USER );
472+ } catch (RemoteException e ) {
473+ }
474+ }
475+
476+ /**
477+ * Forces the device to wake up from sleep.
478+ * <p>
479+ * If the device is currently asleep, wakes it up, otherwise does nothing.
480+ * This is what happens when the power key is pressed to turn on the screen.
481+ * </p><p>
482+ * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission.
483+ * </p>
484+ *
485+ * @param time The time when the request to wake up was issued, in the
486+ * {@link SystemClock#uptimeMillis()} time base. This timestamp is used to correctly
487+ * order the user activity with other power management functions. It should be set
488+ * to the timestamp of the input event that caused the request to wake up.
489+ *
490+ * @see #userActivity
491+ * @see #goToSleep
492+ */
493+ public void wakeUp (long time ) {
494+ try {
495+ mService .wakeUp (time );
403496 } catch (RemoteException e ) {
404497 }
405498 }
@@ -416,34 +509,24 @@ public void goToSleep(long time) {
416509 */
417510 public void setBacklightBrightness (int brightness ) {
418511 try {
419- mService .setBacklightBrightness (brightness );
512+ mService .setTemporaryScreenBrightnessSettingOverride (brightness );
420513 } catch (RemoteException e ) {
421514 }
422515 }
423516
424517 /**
425- * Returns the set of wake lock levels and flags for {@link #newWakeLock}
426- * that are supported on the device.
427- * <p>
428- * For example, to test to see if the {@link #PROXIMITY_SCREEN_OFF_WAKE_LOCK}
429- * is supported:
430- * {@samplecode
431- * PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
432- * int supportedFlags = pm.getSupportedWakeLockFlags();
433- * boolean proximitySupported = ((supportedFlags & PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)
434- * == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK);
435- * }
436- * </p>
518+ * Returns true if the specified wake lock level is supported.
437519 *
438- * @return The set of supported WakeLock flags.
520+ * @param level The wake lock level to check.
521+ * @return True if the specified wake lock level is supported.
439522 *
440523 * {@hide}
441524 */
442- public int getSupportedWakeLockFlags ( ) {
525+ public boolean isWakeLockLevelSupported ( int level ) {
443526 try {
444- return mService .getSupportedWakeLockFlags ( );
527+ return mService .isWakeLockLevelSupported ( level );
445528 } catch (RemoteException e ) {
446- return 0 ;
529+ return false ;
447530 }
448531 }
449532
@@ -593,7 +676,7 @@ private void acquireLocked() {
593676 // been explicitly released by the keyguard.
594677 mHandler .removeCallbacks (mReleaser );
595678 try {
596- mService .acquireWakeLock (mFlags , mToken , mTag , mWorkSource );
679+ mService .acquireWakeLock (mToken , mFlags , mTag , mWorkSource );
597680 } catch (RemoteException e ) {
598681 }
599682 mHeld = true ;
0 commit comments