107107public final class PowerManager {
108108 private static final String TAG = "PowerManager" ;
109109
110- /*
111- * These internal values define the underlying power elements that we might
112- * want to control individually. Eventually we'd like to expose them.
110+ /* NOTE: Wake lock levels were previously defined as a bit field, except that only a few
111+ * combinations were actually supported so the bit field was removed. This explains
112+ * why the numbering scheme is so odd. If adding a new wake lock level, any unused
113+ * value can be used.
113114 */
114- private static final int WAKE_BIT_CPU_STRONG = 1 << 0 ;
115- private static final int WAKE_BIT_CPU_WEAK = 1 << 1 ;
116- private static final int WAKE_BIT_SCREEN_DIM = 1 << 2 ;
117- private static final int WAKE_BIT_SCREEN_BRIGHT = 1 << 3 ;
118- private static final int WAKE_BIT_KEYBOARD_BRIGHT = 1 << 4 ;
119- private static final int WAKE_BIT_PROXIMITY_SCREEN_OFF = 1 << 5 ;
120-
121- private static final int LOCK_MASK = WAKE_BIT_CPU_STRONG
122- | WAKE_BIT_CPU_WEAK
123- | WAKE_BIT_SCREEN_DIM
124- | WAKE_BIT_SCREEN_BRIGHT
125- | WAKE_BIT_KEYBOARD_BRIGHT
126- | WAKE_BIT_PROXIMITY_SCREEN_OFF ;
127115
128116 /**
129117 * Wake lock level: Ensures that the CPU is running; the screen and keyboard
130118 * backlight will be allowed to go off.
119+ * <p>
120+ * If the user presses the power button, then the screen will be turned off
121+ * but the CPU will be kept on until all partial wake locks have been released.
122+ * </p>
131123 */
132- public static final int PARTIAL_WAKE_LOCK = WAKE_BIT_CPU_STRONG ;
124+ public static final int PARTIAL_WAKE_LOCK = 0x00000001 ;
133125
134126 /**
135- * Wake lock level: Ensures that the screen and keyboard backlight are on at
136- * full brightness.
127+ * Wake lock level: Ensures that the screen is on (but may be dimmed);
128+ * the keyboard backlight will be allowed to go off.
129+ * <p>
130+ * If the user presses the power button, then the {@link #SCREEN_DIM_WAKE_LOCK} will be
131+ * implicitly released by the system, causing both the screen and the CPU to be turned off.
132+ * Contrast with {@link #PARTIAL_WAKE_LOCK}.
133+ * </p>
137134 *
138- * <p class="note">
139- * Most applications should strongly consider using
135+ * @deprecated Most applications should use
140136 * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead
141- * of managing their own wake locks. This window flag will be correctly managed
142- * by the platform as the user moves between applications and doesn't require
143- * a special permission.
144- * </p>
137+ * of this type of wake lock, as it will be correctly managed by the platform
138+ * as the user moves between applications and doesn't require a special permission.
145139 */
146- public static final int FULL_WAKE_LOCK = WAKE_BIT_CPU_WEAK | WAKE_BIT_SCREEN_BRIGHT
147- | WAKE_BIT_KEYBOARD_BRIGHT ;
140+ @ Deprecated
141+ public static final int SCREEN_DIM_WAKE_LOCK = 0x00000006 ;
148142
149143 /**
150144 * Wake lock level: Ensures that the screen is on at full brightness;
151145 * the keyboard backlight will be allowed to go off.
146+ * <p>
147+ * If the user presses the power button, then the {@link #SCREEN_BRIGHT_WAKE_LOCK} will be
148+ * implicitly released by the system, causing both the screen and the CPU to be turned off.
149+ * Contrast with {@link #PARTIAL_WAKE_LOCK}.
150+ * </p>
152151 *
153152 * @deprecated Most applications should use
154153 * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead
155154 * of this type of wake lock, as it will be correctly managed by the platform
156155 * as the user moves between applications and doesn't require a special permission.
157156 */
158157 @ Deprecated
159- public static final int SCREEN_BRIGHT_WAKE_LOCK = WAKE_BIT_CPU_WEAK | WAKE_BIT_SCREEN_BRIGHT ;
158+ public static final int SCREEN_BRIGHT_WAKE_LOCK = 0x0000000a ;
160159
161160 /**
162- * Wake lock level: Ensures that the screen is on (but may be dimmed);
163- * the keyboard backlight will be allowed to go off.
161+ * Wake lock level: Ensures that the screen and keyboard backlight are on at
162+ * full brightness.
163+ * <p>
164+ * If the user presses the power button, then the {@link #FULL_WAKE_LOCK} will be
165+ * implicitly released by the system, causing both the screen and the CPU to be turned off.
166+ * Contrast with {@link #PARTIAL_WAKE_LOCK}.
167+ * </p>
168+ *
169+ * @deprecated Most applications should use
170+ * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead
171+ * of this type of wake lock, as it will be correctly managed by the platform
172+ * as the user moves between applications and doesn't require a special permission.
164173 */
165- public static final int SCREEN_DIM_WAKE_LOCK = WAKE_BIT_CPU_WEAK | WAKE_BIT_SCREEN_DIM ;
174+ @ Deprecated
175+ public static final int FULL_WAKE_LOCK = 0x0000001a ;
166176
167177 /**
168178 * Wake lock level: Turns the screen off when the proximity sensor activates.
169179 * <p>
170- * Since not all devices have proximity sensors, use {@link #getSupportedWakeLockFlags() }
180+ * Since not all devices have proximity sensors, use {@link #getSupportedWakeLockFlags}
171181 * to determine whether this wake lock level is supported.
172182 * </p>
173183 *
174184 * {@hide}
175185 */
176- public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = WAKE_BIT_PROXIMITY_SCREEN_OFF ;
186+ public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = 0x00000020 ;
177187
178188 /**
179- * Flag for {@link WakeLock#release release(int)} to defer releasing a
180- * {@link #WAKE_BIT_PROXIMITY_SCREEN_OFF} wake lock until the proximity sensor returns
181- * a negative value.
189+ * Mask for the wake lock level component of a combined wake lock level and flags integer.
182190 *
183- * { @hide}
191+ * @hide
184192 */
185- public static final int WAIT_FOR_PROXIMITY_NEGATIVE = 1 ;
193+ public static final int WAKE_LOCK_LEVEL_MASK = 0x0000ffff ;
186194
187195 /**
188196 * Wake lock flag: Turn the screen on when the wake lock is acquired.
@@ -195,7 +203,7 @@ public final class PowerManager {
195203 * Cannot be used with {@link #PARTIAL_WAKE_LOCK}.
196204 * </p>
197205 */
198- public static final int ACQUIRE_CAUSES_WAKEUP = 1 << 28 ;
206+ public static final int ACQUIRE_CAUSES_WAKEUP = 0x10000000 ;
199207
200208 /**
201209 * Wake lock flag: When this wake lock is released, poke the user activity timer
@@ -207,7 +215,16 @@ public final class PowerManager {
207215 * Cannot be used with {@link #PARTIAL_WAKE_LOCK}.
208216 * </p>
209217 */
210- public static final int ON_AFTER_RELEASE = 1 << 29 ;
218+ public static final int ON_AFTER_RELEASE = 0x20000000 ;
219+
220+ /**
221+ * Flag for {@link WakeLock#release release(int)} to defer releasing a
222+ * {@link #WAKE_BIT_PROXIMITY_SCREEN_OFF} wake lock until the proximity sensor returns
223+ * a negative value.
224+ *
225+ * {@hide}
226+ */
227+ public static final int WAIT_FOR_PROXIMITY_NEGATIVE = 1 ;
211228
212229 /**
213230 * Brightness value to use when battery is low.
@@ -298,20 +315,25 @@ public PowerManager(IPowerManager service, Handler handler) {
298315 * @see #ON_AFTER_RELEASE
299316 */
300317 public WakeLock newWakeLock (int levelAndFlags , String tag ) {
301- switch (levelAndFlags & LOCK_MASK ) {
302- case PARTIAL_WAKE_LOCK :
303- case SCREEN_DIM_WAKE_LOCK :
304- case SCREEN_BRIGHT_WAKE_LOCK :
305- case FULL_WAKE_LOCK :
306- case PROXIMITY_SCREEN_OFF_WAKE_LOCK :
307- break ;
308- default :
309- throw new IllegalArgumentException ("Must specify a wake lock level." );
318+ validateWakeLockParameters (levelAndFlags , tag );
319+ return new WakeLock (levelAndFlags , tag );
320+ }
321+
322+ /** @hide */
323+ public static void validateWakeLockParameters (int levelAndFlags , String tag ) {
324+ switch (levelAndFlags & WAKE_LOCK_LEVEL_MASK ) {
325+ case PARTIAL_WAKE_LOCK :
326+ case SCREEN_DIM_WAKE_LOCK :
327+ case SCREEN_BRIGHT_WAKE_LOCK :
328+ case FULL_WAKE_LOCK :
329+ case PROXIMITY_SCREEN_OFF_WAKE_LOCK :
330+ break ;
331+ default :
332+ throw new IllegalArgumentException ("Must specify a valid wake lock level." );
310333 }
311334 if (tag == null ) {
312335 throw new IllegalArgumentException ("The tag must not be null." );
313336 }
314- return new WakeLock (levelAndFlags , tag );
315337 }
316338
317339 /**
0 commit comments