The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os; |
| 18 | |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 21 | import android.content.Context; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.util.Log; |
| 23 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 25 | * This class gives you control of the power state of the device. |
| 26 | * |
| 27 | * <p> |
| 28 | * <b>Device battery life will be significantly affected by the use of this API.</b> |
| 29 | * Do not acquire {@link WakeLock}s unless you really need them, use the minimum levels |
| 30 | * possible, and be sure to release them as soon as possible. |
| 31 | * </p><p> |
| 32 | * You can obtain an instance of this class by calling |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | * {@link android.content.Context#getSystemService(java.lang.String) Context.getSystemService()}. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 34 | * </p><p> |
| 35 | * The primary API you'll use is {@link #newWakeLock(int, String) newWakeLock()}. |
| 36 | * This will create a {@link PowerManager.WakeLock} object. You can then use methods |
| 37 | * on the wake lock object to control the power state of the device. |
| 38 | * </p><p> |
| 39 | * In practice it's quite simple: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | * {@samplecode |
| 41 | * PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); |
| 42 | * PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag"); |
| 43 | * wl.acquire(); |
| 44 | * ..screen will stay on during this section.. |
| 45 | * wl.release(); |
| 46 | * } |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 47 | * </p><p> |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 48 | * The following wake lock levels are defined, with varying effects on system power. |
| 49 | * <i>These levels are mutually exclusive - you may only specify one of them.</i> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 50 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 51 | * <table> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | * <tr><th>Flag Value</th> |
| 53 | * <th>CPU</th> <th>Screen</th> <th>Keyboard</th></tr> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 55 | * <tr><td>{@link #PARTIAL_WAKE_LOCK}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | * <td>On*</td> <td>Off</td> <td>Off</td> |
| 57 | * </tr> |
| 58 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 59 | * <tr><td>{@link #SCREEN_DIM_WAKE_LOCK}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | * <td>On</td> <td>Dim</td> <td>Off</td> |
| 61 | * </tr> |
| 62 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 63 | * <tr><td>{@link #SCREEN_BRIGHT_WAKE_LOCK}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | * <td>On</td> <td>Bright</td> <td>Off</td> |
| 65 | * </tr> |
| 66 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 67 | * <tr><td>{@link #FULL_WAKE_LOCK}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | * <td>On</td> <td>Bright</td> <td>Bright</td> |
| 69 | * </tr> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | * </table> |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 71 | * </p><p> |
| 72 | * *<i>If you hold a partial wake lock, the CPU will continue to run, regardless of any |
| 73 | * display timeouts or the state of the screen and even after the user presses the power button. |
| 74 | * In all other wake locks, the CPU will run, but the user can still put the device to sleep |
| 75 | * using the power button.</i> |
| 76 | * </p><p> |
| 77 | * In addition, you can add two more flags, which affect behavior of the screen only. |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 78 | * <i>These flags have no effect when combined with a {@link #PARTIAL_WAKE_LOCK}.</i></p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 80 | * <table> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | * <tr><th>Flag Value</th> <th>Description</th></tr> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 83 | * <tr><td>{@link #ACQUIRE_CAUSES_WAKEUP}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | * <td>Normal wake locks don't actually turn on the illumination. Instead, they cause |
| 85 | * the illumination to remain on once it turns on (e.g. from user activity). This flag |
| 86 | * will force the screen and/or keyboard to turn on immediately, when the WakeLock is |
| 87 | * acquired. A typical use would be for notifications which are important for the user to |
| 88 | * see immediately.</td> |
| 89 | * </tr> |
| 90 | * |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 91 | * <tr><td>{@link #ON_AFTER_RELEASE}</td> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | * <td>If this flag is set, the user activity timer will be reset when the WakeLock is |
| 93 | * released, causing the illumination to remain on a bit longer. This can be used to |
| 94 | * reduce flicker if you are cycling between wake lock conditions.</td> |
| 95 | * </tr> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | * </table> |
Dirk Dougherty | 7b9a288 | 2012-10-28 12:07:08 -0700 | [diff] [blame] | 97 | * <p> |
Kenny Root | d710fb5 | 2011-03-15 17:39:45 -0700 | [diff] [blame] | 98 | * Any application using a WakeLock must request the {@code android.permission.WAKE_LOCK} |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 99 | * permission in an {@code <uses-permission>} element of the application's manifest. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 100 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | */ |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 102 | public final class PowerManager { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | private static final String TAG = "PowerManager"; |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 104 | |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 105 | /* NOTE: Wake lock levels were previously defined as a bit field, except that only a few |
| 106 | * combinations were actually supported so the bit field was removed. This explains |
| 107 | * why the numbering scheme is so odd. If adding a new wake lock level, any unused |
| 108 | * value can be used. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | |
| 111 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 112 | * Wake lock level: Ensures that the CPU is running; the screen and keyboard |
| 113 | * backlight will be allowed to go off. |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 114 | * <p> |
| 115 | * If the user presses the power button, then the screen will be turned off |
| 116 | * but the CPU will be kept on until all partial wake locks have been released. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 117 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | */ |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 119 | public static final int PARTIAL_WAKE_LOCK = 0x00000001; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | |
| 121 | /** |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 122 | * Wake lock level: Ensures that the screen is on (but may be dimmed); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 123 | * the keyboard backlight will be allowed to go off. |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 124 | * <p> |
| 125 | * If the user presses the power button, then the {@link #SCREEN_DIM_WAKE_LOCK} will be |
| 126 | * implicitly released by the system, causing both the screen and the CPU to be turned off. |
| 127 | * Contrast with {@link #PARTIAL_WAKE_LOCK}. |
| 128 | * </p> |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 129 | * |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 130 | * @deprecated Most applications should use |
| 131 | * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead |
| 132 | * of this type of wake lock, as it will be correctly managed by the platform |
| 133 | * as the user moves between applications and doesn't require a special permission. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | */ |
Dianne Hackborn | 9567a66 | 2011-04-19 18:44:03 -0700 | [diff] [blame] | 135 | @Deprecated |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 136 | public static final int SCREEN_DIM_WAKE_LOCK = 0x00000006; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | |
| 138 | /** |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 139 | * Wake lock level: Ensures that the screen is on at full brightness; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | * the keyboard backlight will be allowed to go off. |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 141 | * <p> |
| 142 | * If the user presses the power button, then the {@link #SCREEN_BRIGHT_WAKE_LOCK} will be |
| 143 | * implicitly released by the system, causing both the screen and the CPU to be turned off. |
| 144 | * Contrast with {@link #PARTIAL_WAKE_LOCK}. |
| 145 | * </p> |
| 146 | * |
| 147 | * @deprecated Most applications should use |
| 148 | * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead |
| 149 | * of this type of wake lock, as it will be correctly managed by the platform |
| 150 | * as the user moves between applications and doesn't require a special permission. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | */ |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 152 | @Deprecated |
| 153 | public static final int SCREEN_BRIGHT_WAKE_LOCK = 0x0000000a; |
| 154 | |
| 155 | /** |
| 156 | * Wake lock level: Ensures that the screen and keyboard backlight are on at |
| 157 | * full brightness. |
| 158 | * <p> |
| 159 | * If the user presses the power button, then the {@link #FULL_WAKE_LOCK} will be |
| 160 | * implicitly released by the system, causing both the screen and the CPU to be turned off. |
| 161 | * Contrast with {@link #PARTIAL_WAKE_LOCK}. |
| 162 | * </p> |
| 163 | * |
| 164 | * @deprecated Most applications should use |
| 165 | * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead |
| 166 | * of this type of wake lock, as it will be correctly managed by the platform |
| 167 | * as the user moves between applications and doesn't require a special permission. |
| 168 | */ |
| 169 | @Deprecated |
| 170 | public static final int FULL_WAKE_LOCK = 0x0000001a; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | |
| 172 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 173 | * Wake lock level: Turns the screen off when the proximity sensor activates. |
| 174 | * <p> |
Jeff Brown | 93cbbb2 | 2012-10-04 13:18:36 -0700 | [diff] [blame] | 175 | * If the proximity sensor detects that an object is nearby, the screen turns off |
| 176 | * immediately. Shortly after the object moves away, the screen turns on again. |
| 177 | * </p><p> |
| 178 | * A proximity wake lock does not prevent the device from falling asleep |
| 179 | * unlike {@link #FULL_WAKE_LOCK}, {@link #SCREEN_BRIGHT_WAKE_LOCK} and |
| 180 | * {@link #SCREEN_DIM_WAKE_LOCK}. If there is no user activity and no other |
| 181 | * wake locks are held, then the device will fall asleep (and lock) as usual. |
| 182 | * However, the device will not fall asleep while the screen has been turned off |
| 183 | * by the proximity sensor because it effectively counts as ongoing user activity. |
| 184 | * </p><p> |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 185 | * Since not all devices have proximity sensors, use {@link #isWakeLockLevelSupported} |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 186 | * to determine whether this wake lock level is supported. |
Craig Mautner | 6edb6db | 2012-11-20 18:21:12 -0800 | [diff] [blame] | 187 | * </p><p> |
| 188 | * Cannot be used with {@link #ACQUIRE_CAUSES_WAKEUP}. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 189 | * </p> |
Mike Lockwood | bc706a0 | 2009-07-27 13:50:57 -0700 | [diff] [blame] | 190 | */ |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 191 | public static final int PROXIMITY_SCREEN_OFF_WAKE_LOCK = 0x00000020; |
Mike Lockwood | bc706a0 | 2009-07-27 13:50:57 -0700 | [diff] [blame] | 192 | |
| 193 | /** |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 194 | * Wake lock level: Put the screen in a low power state and allow the CPU to suspend |
| 195 | * if no other wake locks are held. |
| 196 | * <p> |
| 197 | * This is used by the dream manager to implement doze mode. It currently |
| 198 | * has no effect unless the power manager is in the dozing state. |
Jeff Brown | 72671fb | 2014-08-21 21:41:09 -0700 | [diff] [blame] | 199 | * </p><p> |
| 200 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 201 | * </p> |
| 202 | * |
| 203 | * {@hide} |
| 204 | */ |
| 205 | public static final int DOZE_WAKE_LOCK = 0x00000040; |
| 206 | |
| 207 | /** |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 208 | * Wake lock level: Keep the device awake enough to allow drawing to occur. |
| 209 | * <p> |
| 210 | * This is used by the window manager to allow applications to draw while the |
| 211 | * system is dozing. It currently has no effect unless the power manager is in |
| 212 | * the dozing state. |
| 213 | * </p><p> |
| 214 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 215 | * </p> |
| 216 | * |
| 217 | * {@hide} |
| 218 | */ |
| 219 | public static final int DRAW_WAKE_LOCK = 0x00000080; |
| 220 | |
| 221 | /** |
Ruchi Kandoi | 0abc001 | 2016-01-12 14:39:24 -0800 | [diff] [blame] | 222 | * Wake lock level: Enables Sustained Performance Mode. |
| 223 | * <p> |
| 224 | * This is used by Gaming and VR applications to ensure the device provides |
| 225 | * will provide consistent performance over a large amount of time. |
| 226 | * </p> |
Ruchi Kandoi | 302710d | 2016-02-25 16:22:54 -0800 | [diff] [blame] | 227 | * |
| 228 | * {@hide} |
Ruchi Kandoi | 0abc001 | 2016-01-12 14:39:24 -0800 | [diff] [blame] | 229 | */ |
| 230 | public static final int SUSTAINED_PERFORMANCE_WAKE_LOCK = 0x00000100; |
| 231 | |
| 232 | /** |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 233 | * Mask for the wake lock level component of a combined wake lock level and flags integer. |
Mike Lockwood | 0e39ea8 | 2009-11-18 15:37:10 -0500 | [diff] [blame] | 234 | * |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 235 | * @hide |
Mike Lockwood | 0e39ea8 | 2009-11-18 15:37:10 -0500 | [diff] [blame] | 236 | */ |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 237 | public static final int WAKE_LOCK_LEVEL_MASK = 0x0000ffff; |
Mike Lockwood | 0e39ea8 | 2009-11-18 15:37:10 -0500 | [diff] [blame] | 238 | |
| 239 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 240 | * Wake lock flag: Turn the screen on when the wake lock is acquired. |
| 241 | * <p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | * Normally wake locks don't actually wake the device, they just cause |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 243 | * the screen to remain on once it's already on. Think of the video player |
| 244 | * application as the normal behavior. Notifications that pop up and want |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | * the device to be on are the exception; use this flag to be like them. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 246 | * </p><p> |
| 247 | * Cannot be used with {@link #PARTIAL_WAKE_LOCK}. |
| 248 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | */ |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 250 | public static final int ACQUIRE_CAUSES_WAKEUP = 0x10000000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | |
| 252 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 253 | * Wake lock flag: When this wake lock is released, poke the user activity timer |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | * so the screen stays on for a little longer. |
| 255 | * <p> |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 256 | * Will not turn the screen on if it is not already on. |
| 257 | * See {@link #ACQUIRE_CAUSES_WAKEUP} if you want that. |
| 258 | * </p><p> |
| 259 | * Cannot be used with {@link #PARTIAL_WAKE_LOCK}. |
| 260 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | */ |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 262 | public static final int ON_AFTER_RELEASE = 0x20000000; |
| 263 | |
| 264 | /** |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 265 | * Wake lock flag: This wake lock is not important for logging events. If a later |
| 266 | * wake lock is acquired that is important, it will be considered the one to log. |
| 267 | * @hide |
| 268 | */ |
| 269 | public static final int UNIMPORTANT_FOR_LOGGING = 0x40000000; |
| 270 | |
| 271 | /** |
Jeff Brown | a71f03c | 2014-08-21 18:01:51 -0700 | [diff] [blame] | 272 | * Flag for {@link WakeLock#release WakeLock.release(int)}: Defer releasing a |
| 273 | * {@link #PROXIMITY_SCREEN_OFF_WAKE_LOCK} wake lock until the proximity sensor |
| 274 | * indicates that an object is not in close proximity. |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 275 | */ |
Michael Wright | 1208e27 | 2014-09-08 19:57:50 -0700 | [diff] [blame] | 276 | public static final int RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY = 1; |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 279 | * Brightness value for fully on. |
| 280 | * @hide |
| 281 | */ |
| 282 | public static final int BRIGHTNESS_ON = 255; |
| 283 | |
| 284 | /** |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 285 | * Brightness value for fully off. |
| 286 | * @hide |
| 287 | */ |
| 288 | public static final int BRIGHTNESS_OFF = 0; |
| 289 | |
Jeff Brown | 970d413 | 2014-07-19 11:33:47 -0700 | [diff] [blame] | 290 | /** |
| 291 | * Brightness value for default policy handling by the system. |
| 292 | * @hide |
| 293 | */ |
| 294 | public static final int BRIGHTNESS_DEFAULT = -1; |
| 295 | |
Jeff Brown | b696de5 | 2012-07-27 15:38:50 -0700 | [diff] [blame] | 296 | // Note: Be sure to update android.os.BatteryStats and PowerManager.h |
| 297 | // if adding or modifying user activity event constants. |
| 298 | |
| 299 | /** |
| 300 | * User activity event type: Unspecified event type. |
| 301 | * @hide |
| 302 | */ |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 303 | @SystemApi |
Jeff Brown | b696de5 | 2012-07-27 15:38:50 -0700 | [diff] [blame] | 304 | public static final int USER_ACTIVITY_EVENT_OTHER = 0; |
| 305 | |
| 306 | /** |
| 307 | * User activity event type: Button or key pressed or released. |
| 308 | * @hide |
| 309 | */ |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 310 | @SystemApi |
Jeff Brown | b696de5 | 2012-07-27 15:38:50 -0700 | [diff] [blame] | 311 | public static final int USER_ACTIVITY_EVENT_BUTTON = 1; |
| 312 | |
| 313 | /** |
| 314 | * User activity event type: Touch down, move or up. |
| 315 | * @hide |
| 316 | */ |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 317 | @SystemApi |
Jeff Brown | b696de5 | 2012-07-27 15:38:50 -0700 | [diff] [blame] | 318 | public static final int USER_ACTIVITY_EVENT_TOUCH = 2; |
| 319 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 320 | /** |
Phil Weaver | da80d67 | 2016-03-15 16:25:46 -0700 | [diff] [blame] | 321 | * User activity event type: Accessibility taking action on behalf of user. |
| 322 | * @hide |
| 323 | */ |
| 324 | @SystemApi |
| 325 | public static final int USER_ACTIVITY_EVENT_ACCESSIBILITY = 3; |
| 326 | |
| 327 | /** |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 328 | * User activity flag: If already dimmed, extend the dim timeout |
| 329 | * but do not brighten. This flag is useful for keeping the screen on |
| 330 | * a little longer without causing a visible change such as when |
| 331 | * the power key is pressed. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 332 | * @hide |
| 333 | */ |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 334 | @SystemApi |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 335 | public static final int USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS = 1 << 0; |
| 336 | |
| 337 | /** |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 338 | * User activity flag: Note the user activity as usual but do not |
| 339 | * reset the user activity timeout. This flag is useful for applying |
| 340 | * user activity power hints when interacting with the device indirectly |
| 341 | * on a secondary screen while allowing the primary screen to go to sleep. |
| 342 | * @hide |
| 343 | */ |
| 344 | @SystemApi |
| 345 | public static final int USER_ACTIVITY_FLAG_INDIRECT = 1 << 1; |
| 346 | |
| 347 | /** |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 348 | * Go to sleep reason code: Going to sleep due by application request. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 349 | * @hide |
| 350 | */ |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 351 | public static final int GO_TO_SLEEP_REASON_APPLICATION = 0; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 352 | |
| 353 | /** |
| 354 | * Go to sleep reason code: Going to sleep due by request of the |
| 355 | * device administration policy. |
| 356 | * @hide |
| 357 | */ |
| 358 | public static final int GO_TO_SLEEP_REASON_DEVICE_ADMIN = 1; |
| 359 | |
| 360 | /** |
| 361 | * Go to sleep reason code: Going to sleep due to a screen timeout. |
| 362 | * @hide |
| 363 | */ |
| 364 | public static final int GO_TO_SLEEP_REASON_TIMEOUT = 2; |
| 365 | |
Doug Zongker | 3b0218b | 2014-01-14 12:29:06 -0800 | [diff] [blame] | 366 | /** |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 367 | * Go to sleep reason code: Going to sleep due to the lid switch being closed. |
| 368 | * @hide |
| 369 | */ |
| 370 | public static final int GO_TO_SLEEP_REASON_LID_SWITCH = 3; |
| 371 | |
| 372 | /** |
| 373 | * Go to sleep reason code: Going to sleep due to the power button being pressed. |
| 374 | * @hide |
| 375 | */ |
| 376 | public static final int GO_TO_SLEEP_REASON_POWER_BUTTON = 4; |
| 377 | |
| 378 | /** |
| 379 | * Go to sleep reason code: Going to sleep due to HDMI. |
| 380 | * @hide |
| 381 | */ |
| 382 | public static final int GO_TO_SLEEP_REASON_HDMI = 5; |
| 383 | |
| 384 | /** |
Filip Gruszczynski | 9779e12 | 2015-03-13 17:39:31 -0700 | [diff] [blame] | 385 | * Go to sleep reason code: Going to sleep due to the sleep button being pressed. |
| 386 | * @hide |
| 387 | */ |
| 388 | public static final int GO_TO_SLEEP_REASON_SLEEP_BUTTON = 6; |
| 389 | |
| 390 | /** |
Jeff Brown | 72671fb | 2014-08-21 21:41:09 -0700 | [diff] [blame] | 391 | * Go to sleep flag: Skip dozing state and directly go to full sleep. |
| 392 | * @hide |
| 393 | */ |
| 394 | public static final int GO_TO_SLEEP_FLAG_NO_DOZE = 1 << 0; |
| 395 | |
| 396 | /** |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 397 | * The value to pass as the 'reason' argument to reboot() to reboot into |
| 398 | * recovery mode for tasks other than applying system updates, such as |
| 399 | * doing factory resets. |
Doug Zongker | 3b0218b | 2014-01-14 12:29:06 -0800 | [diff] [blame] | 400 | * <p> |
| 401 | * Requires the {@link android.Manifest.permission#RECOVERY} |
| 402 | * permission (in addition to |
| 403 | * {@link android.Manifest.permission#REBOOT}). |
| 404 | * </p> |
Doug Zongker | 183415e | 2014-08-12 10:18:40 -0700 | [diff] [blame] | 405 | * @hide |
Doug Zongker | 3b0218b | 2014-01-14 12:29:06 -0800 | [diff] [blame] | 406 | */ |
| 407 | public static final String REBOOT_RECOVERY = "recovery"; |
Yusuke Sato | 705ffd1 | 2015-07-21 15:52:11 -0700 | [diff] [blame] | 408 | |
| 409 | /** |
Tao Bao | e8a403d | 2015-12-31 07:44:55 -0800 | [diff] [blame] | 410 | * The value to pass as the 'reason' argument to reboot() to reboot into |
| 411 | * recovery mode for applying system updates. |
| 412 | * <p> |
| 413 | * Requires the {@link android.Manifest.permission#RECOVERY} |
| 414 | * permission (in addition to |
| 415 | * {@link android.Manifest.permission#REBOOT}). |
| 416 | * </p> |
| 417 | * @hide |
| 418 | */ |
| 419 | public static final String REBOOT_RECOVERY_UPDATE = "recovery-update"; |
| 420 | |
| 421 | /** |
Mahaver Chopra | 1ce53bc | 2015-12-14 13:35:14 +0000 | [diff] [blame] | 422 | * The value to pass as the 'reason' argument to reboot() when device owner requests a reboot on |
| 423 | * the device. |
| 424 | * @hide |
| 425 | */ |
| 426 | public static final String REBOOT_REQUESTED_BY_DEVICE_OWNER = "deviceowner"; |
| 427 | |
| 428 | /** |
Tony Mantler | b8009fd | 2016-03-14 15:55:35 -0700 | [diff] [blame] | 429 | * The 'reason' value used when rebooting in safe mode |
| 430 | * @hide |
| 431 | */ |
| 432 | public static final String REBOOT_SAFE_MODE = "safemode"; |
| 433 | |
| 434 | /** |
Yusuke Sato | 705ffd1 | 2015-07-21 15:52:11 -0700 | [diff] [blame] | 435 | * The value to pass as the 'reason' argument to android_reboot(). |
| 436 | * @hide |
| 437 | */ |
| 438 | public static final String SHUTDOWN_USER_REQUESTED = "userrequested"; |
| 439 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 440 | final Context mContext; |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 441 | final IPowerManager mService; |
| 442 | final Handler mHandler; |
| 443 | |
Dianne Hackborn | 1958e5e | 2015-06-12 18:11:41 -0700 | [diff] [blame] | 444 | IDeviceIdleController mIDeviceIdleController; |
| 445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 446 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 447 | * {@hide} |
| 448 | */ |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 449 | public PowerManager(Context context, IPowerManager service, Handler handler) { |
| 450 | mContext = context; |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 451 | mService = service; |
| 452 | mHandler = handler; |
| 453 | } |
| 454 | |
| 455 | /** |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 456 | * Gets the minimum supported screen brightness setting. |
| 457 | * The screen may be allowed to become dimmer than this value but |
| 458 | * this is the minimum value that can be set by the user. |
| 459 | * @hide |
| 460 | */ |
| 461 | public int getMinimumScreenBrightnessSetting() { |
| 462 | return mContext.getResources().getInteger( |
Jeff Brown | f9bba13 | 2012-08-21 22:04:02 -0700 | [diff] [blame] | 463 | com.android.internal.R.integer.config_screenBrightnessSettingMinimum); |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Gets the maximum supported screen brightness setting. |
| 468 | * The screen may be allowed to become dimmer than this value but |
| 469 | * this is the maximum value that can be set by the user. |
| 470 | * @hide |
| 471 | */ |
| 472 | public int getMaximumScreenBrightnessSetting() { |
Jeff Brown | f9bba13 | 2012-08-21 22:04:02 -0700 | [diff] [blame] | 473 | return mContext.getResources().getInteger( |
| 474 | com.android.internal.R.integer.config_screenBrightnessSettingMaximum); |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Gets the default screen brightness setting. |
| 479 | * @hide |
| 480 | */ |
| 481 | public int getDefaultScreenBrightnessSetting() { |
Jeff Brown | f9bba13 | 2012-08-21 22:04:02 -0700 | [diff] [blame] | 482 | return mContext.getResources().getInteger( |
| 483 | com.android.internal.R.integer.config_screenBrightnessSettingDefault); |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /** |
Jeff Brown | db21284 | 2012-10-01 14:33:09 -0700 | [diff] [blame] | 487 | * Returns true if the twilight service should be used to adjust screen brightness |
| 488 | * policy. This setting is experimental and disabled by default. |
| 489 | * @hide |
| 490 | */ |
| 491 | public static boolean useTwilightAdjustmentFeature() { |
| 492 | return SystemProperties.getBoolean("persist.power.usetwilightadj", false); |
| 493 | } |
| 494 | |
| 495 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 496 | * Creates a new wake lock with the specified level and flags. |
Kenny Root | d710fb5 | 2011-03-15 17:39:45 -0700 | [diff] [blame] | 497 | * <p> |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 498 | * The {@code levelAndFlags} parameter specifies a wake lock level and optional flags |
| 499 | * combined using the logical OR operator. |
| 500 | * </p><p> |
| 501 | * The wake lock levels are: {@link #PARTIAL_WAKE_LOCK}, |
| 502 | * {@link #FULL_WAKE_LOCK}, {@link #SCREEN_DIM_WAKE_LOCK} |
| 503 | * and {@link #SCREEN_BRIGHT_WAKE_LOCK}. Exactly one wake lock level must be |
| 504 | * specified as part of the {@code levelAndFlags} parameter. |
| 505 | * </p><p> |
| 506 | * The wake lock flags are: {@link #ACQUIRE_CAUSES_WAKEUP} |
| 507 | * and {@link #ON_AFTER_RELEASE}. Multiple flags can be combined as part of the |
| 508 | * {@code levelAndFlags} parameters. |
| 509 | * </p><p> |
| 510 | * Call {@link WakeLock#acquire() acquire()} on the object to acquire the |
| 511 | * wake lock, and {@link WakeLock#release release()} when you are done. |
| 512 | * </p><p> |
| 513 | * {@samplecode |
| 514 | * PowerManager pm = (PowerManager)mContext.getSystemService( |
| 515 | * Context.POWER_SERVICE); |
| 516 | * PowerManager.WakeLock wl = pm.newWakeLock( |
| 517 | * PowerManager.SCREEN_DIM_WAKE_LOCK |
| 518 | * | PowerManager.ON_AFTER_RELEASE, |
| 519 | * TAG); |
| 520 | * wl.acquire(); |
| 521 | * // ... do work... |
| 522 | * wl.release(); |
| 523 | * } |
| 524 | * </p><p> |
| 525 | * Although a wake lock can be created without special permissions, |
| 526 | * the {@link android.Manifest.permission#WAKE_LOCK} permission is |
| 527 | * required to actually acquire or release the wake lock that is returned. |
| 528 | * </p><p class="note"> |
| 529 | * If using this to keep the screen on, you should strongly consider using |
| 530 | * {@link android.view.WindowManager.LayoutParams#FLAG_KEEP_SCREEN_ON} instead. |
| 531 | * This window flag will be correctly managed by the platform |
| 532 | * as the user moves between applications and doesn't require a special permission. |
| 533 | * </p> |
| 534 | * |
| 535 | * @param levelAndFlags Combination of wake lock level and flag values defining |
| 536 | * the requested behavior of the WakeLock. |
| 537 | * @param tag Your class name (or other tag) for debugging purposes. |
| 538 | * |
| 539 | * @see WakeLock#acquire() |
| 540 | * @see WakeLock#release() |
| 541 | * @see #PARTIAL_WAKE_LOCK |
| 542 | * @see #FULL_WAKE_LOCK |
| 543 | * @see #SCREEN_DIM_WAKE_LOCK |
| 544 | * @see #SCREEN_BRIGHT_WAKE_LOCK |
Jeff Brown | a71f03c | 2014-08-21 18:01:51 -0700 | [diff] [blame] | 545 | * @see #PROXIMITY_SCREEN_OFF_WAKE_LOCK |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 546 | * @see #ACQUIRE_CAUSES_WAKEUP |
| 547 | * @see #ON_AFTER_RELEASE |
| 548 | */ |
| 549 | public WakeLock newWakeLock(int levelAndFlags, String tag) { |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 550 | validateWakeLockParameters(levelAndFlags, tag); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 551 | return new WakeLock(levelAndFlags, tag, mContext.getOpPackageName()); |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /** @hide */ |
| 555 | public static void validateWakeLockParameters(int levelAndFlags, String tag) { |
| 556 | switch (levelAndFlags & WAKE_LOCK_LEVEL_MASK) { |
| 557 | case PARTIAL_WAKE_LOCK: |
| 558 | case SCREEN_DIM_WAKE_LOCK: |
| 559 | case SCREEN_BRIGHT_WAKE_LOCK: |
| 560 | case FULL_WAKE_LOCK: |
| 561 | case PROXIMITY_SCREEN_OFF_WAKE_LOCK: |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 562 | case DOZE_WAKE_LOCK: |
Jeff Brown | c2932a1 | 2014-11-20 18:04:05 -0800 | [diff] [blame] | 563 | case DRAW_WAKE_LOCK: |
Ruchi Kandoi | 0abc001 | 2016-01-12 14:39:24 -0800 | [diff] [blame] | 564 | case SUSTAINED_PERFORMANCE_WAKE_LOCK: |
Jeff Brown | 155fc70 | 2012-07-27 12:12:15 -0700 | [diff] [blame] | 565 | break; |
| 566 | default: |
| 567 | throw new IllegalArgumentException("Must specify a valid wake lock level."); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 568 | } |
| 569 | if (tag == null) { |
| 570 | throw new IllegalArgumentException("The tag must not be null."); |
| 571 | } |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Notifies the power manager that user activity happened. |
| 576 | * <p> |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 577 | * Resets the auto-off timer and brightens the screen if the device |
| 578 | * is not asleep. This is what happens normally when a key or the touch |
| 579 | * screen is pressed or when some other user activity occurs. |
| 580 | * This method does not wake up the device if it has been put to sleep. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 581 | * </p><p> |
| 582 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 583 | * </p> |
| 584 | * |
| 585 | * @param when The time of the user activity, in the {@link SystemClock#uptimeMillis()} |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 586 | * time base. This timestamp is used to correctly order the user activity request with |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 587 | * other power management functions. It should be set |
| 588 | * to the timestamp of the input event that caused the user activity. |
| 589 | * @param noChangeLights If true, does not cause the keyboard backlight to turn on |
| 590 | * because of this event. This is set when the power key is pressed. |
| 591 | * We want the device to stay on while the button is down, but we're about |
| 592 | * to turn off the screen so we don't want the keyboard backlight to turn on again. |
| 593 | * Otherwise the lights flash on and then off and it looks weird. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 594 | * |
| 595 | * @see #wakeUp |
| 596 | * @see #goToSleep |
Jeff Brown | 7d82751 | 2014-08-21 21:56:02 -0700 | [diff] [blame] | 597 | * |
| 598 | * @removed Requires signature or system permission. |
| 599 | * @deprecated Use {@link #userActivity(long, int, int)}. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 600 | */ |
Jeff Brown | 7d82751 | 2014-08-21 21:56:02 -0700 | [diff] [blame] | 601 | @Deprecated |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 602 | public void userActivity(long when, boolean noChangeLights) { |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 603 | userActivity(when, USER_ACTIVITY_EVENT_OTHER, |
| 604 | noChangeLights ? USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS : 0); |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * Notifies the power manager that user activity happened. |
| 609 | * <p> |
| 610 | * Resets the auto-off timer and brightens the screen if the device |
| 611 | * is not asleep. This is what happens normally when a key or the touch |
| 612 | * screen is pressed or when some other user activity occurs. |
| 613 | * This method does not wake up the device if it has been put to sleep. |
| 614 | * </p><p> |
| 615 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} or |
| 616 | * {@link android.Manifest.permission#USER_ACTIVITY} permission. |
| 617 | * </p> |
| 618 | * |
| 619 | * @param when The time of the user activity, in the {@link SystemClock#uptimeMillis()} |
| 620 | * time base. This timestamp is used to correctly order the user activity request with |
| 621 | * other power management functions. It should be set |
| 622 | * to the timestamp of the input event that caused the user activity. |
| 623 | * @param event The user activity event. |
| 624 | * @param flags Optional user activity flags. |
| 625 | * |
| 626 | * @see #wakeUp |
| 627 | * @see #goToSleep |
| 628 | * |
| 629 | * @hide Requires signature or system permission. |
| 630 | */ |
| 631 | @SystemApi |
| 632 | public void userActivity(long when, int event, int flags) { |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 633 | try { |
Jeff Brown | 0a57112 | 2014-08-21 21:50:43 -0700 | [diff] [blame] | 634 | mService.userActivity(when, event, flags); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 635 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 636 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 637 | } |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Forces the device to go to sleep. |
| 642 | * <p> |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 643 | * Overrides all the wake locks that are held. |
| 644 | * This is what happens when the power key is pressed to turn off the screen. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 645 | * </p><p> |
| 646 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 647 | * </p> |
| 648 | * |
| 649 | * @param time The time when the request to go to sleep was issued, in the |
| 650 | * {@link SystemClock#uptimeMillis()} time base. This timestamp is used to correctly |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 651 | * order the go to sleep request with other power management functions. It should be set |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 652 | * to the timestamp of the input event that caused the request to go to sleep. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 653 | * |
| 654 | * @see #userActivity |
| 655 | * @see #wakeUp |
Jeff Brown | 7d82751 | 2014-08-21 21:56:02 -0700 | [diff] [blame] | 656 | * |
| 657 | * @removed Requires signature permission. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 658 | */ |
| 659 | public void goToSleep(long time) { |
Jeff Brown | c12035c | 2014-08-13 18:52:25 -0700 | [diff] [blame] | 660 | goToSleep(time, GO_TO_SLEEP_REASON_APPLICATION, 0); |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /** |
Jeff Brown | 7d82751 | 2014-08-21 21:56:02 -0700 | [diff] [blame] | 664 | * Forces the device to go to sleep. |
| 665 | * <p> |
| 666 | * Overrides all the wake locks that are held. |
| 667 | * This is what happens when the power key is pressed to turn off the screen. |
| 668 | * </p><p> |
| 669 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 670 | * </p> |
| 671 | * |
| 672 | * @param time The time when the request to go to sleep was issued, in the |
| 673 | * {@link SystemClock#uptimeMillis()} time base. This timestamp is used to correctly |
| 674 | * order the go to sleep request with other power management functions. It should be set |
| 675 | * to the timestamp of the input event that caused the request to go to sleep. |
| 676 | * @param reason The reason the device is going to sleep. |
| 677 | * @param flags Optional flags to apply when going to sleep. |
| 678 | * |
| 679 | * @see #userActivity |
| 680 | * @see #wakeUp |
| 681 | * |
| 682 | * @hide Requires signature permission. |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 683 | */ |
| 684 | public void goToSleep(long time, int reason, int flags) { |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 685 | try { |
Jeff Brown | 6d8fd27 | 2014-05-20 21:24:38 -0700 | [diff] [blame] | 686 | mService.goToSleep(time, reason, flags); |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 687 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 688 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
| 692 | /** |
| 693 | * Forces the device to wake up from sleep. |
| 694 | * <p> |
| 695 | * If the device is currently asleep, wakes it up, otherwise does nothing. |
| 696 | * This is what happens when the power key is pressed to turn on the screen. |
| 697 | * </p><p> |
| 698 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 699 | * </p> |
| 700 | * |
| 701 | * @param time The time when the request to wake up was issued, in the |
| 702 | * {@link SystemClock#uptimeMillis()} time base. This timestamp is used to correctly |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 703 | * order the wake up request with other power management functions. It should be set |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 704 | * to the timestamp of the input event that caused the request to wake up. |
| 705 | * |
| 706 | * @see #userActivity |
| 707 | * @see #goToSleep |
Jeff Brown | 7d82751 | 2014-08-21 21:56:02 -0700 | [diff] [blame] | 708 | * |
| 709 | * @removed Requires signature permission. |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 710 | */ |
| 711 | public void wakeUp(long time) { |
| 712 | try { |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 713 | mService.wakeUp(time, "wakeUp", mContext.getOpPackageName()); |
| 714 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 715 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | |
| 719 | /** |
| 720 | * @hide |
| 721 | */ |
| 722 | public void wakeUp(long time, String reason) { |
| 723 | try { |
| 724 | mService.wakeUp(time, reason, mContext.getOpPackageName()); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 725 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 726 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
| 730 | /** |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 731 | * Forces the device to start napping. |
| 732 | * <p> |
| 733 | * If the device is currently awake, starts dreaming, otherwise does nothing. |
| 734 | * When the dream ends or if the dream cannot be started, the device will |
| 735 | * either wake up or go to sleep depending on whether there has been recent |
| 736 | * user activity. |
| 737 | * </p><p> |
| 738 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 739 | * </p> |
| 740 | * |
| 741 | * @param time The time when the request to nap was issued, in the |
| 742 | * {@link SystemClock#uptimeMillis()} time base. This timestamp is used to correctly |
| 743 | * order the nap request with other power management functions. It should be set |
| 744 | * to the timestamp of the input event that caused the request to nap. |
| 745 | * |
| 746 | * @see #wakeUp |
| 747 | * @see #goToSleep |
| 748 | * |
Jeff Brown | 7d82751 | 2014-08-21 21:56:02 -0700 | [diff] [blame] | 749 | * @hide Requires signature permission. |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 750 | */ |
| 751 | public void nap(long time) { |
| 752 | try { |
| 753 | mService.nap(time); |
| 754 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 755 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 62c82e4 | 2012-09-26 01:30:41 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | /** |
Jeff Brown | e333e67 | 2014-10-28 13:48:55 -0700 | [diff] [blame] | 760 | * Boosts the brightness of the screen to maximum for a predetermined |
| 761 | * period of time. This is used to make the screen more readable in bright |
| 762 | * daylight for a short duration. |
| 763 | * <p> |
| 764 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 765 | * </p> |
| 766 | * |
| 767 | * @param time The time when the request to boost was issued, in the |
| 768 | * {@link SystemClock#uptimeMillis()} time base. This timestamp is used to correctly |
| 769 | * order the boost request with other power management functions. It should be set |
| 770 | * to the timestamp of the input event that caused the request to boost. |
| 771 | * |
| 772 | * @hide Requires signature permission. |
| 773 | */ |
| 774 | public void boostScreenBrightness(long time) { |
| 775 | try { |
| 776 | mService.boostScreenBrightness(time); |
| 777 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 778 | throw e.rethrowFromSystemServer(); |
Jeff Brown | e333e67 | 2014-10-28 13:48:55 -0700 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | |
| 782 | /** |
Bryce Lee | 84d6c0f | 2015-03-17 10:43:08 -0700 | [diff] [blame] | 783 | * Returns whether the screen brightness is currently boosted to maximum, caused by a call |
| 784 | * to {@link #boostScreenBrightness(long)}. |
| 785 | * @return {@code True} if the screen brightness is currently boosted. {@code False} otherwise. |
| 786 | * |
| 787 | * @hide |
| 788 | */ |
| 789 | @SystemApi |
| 790 | public boolean isScreenBrightnessBoosted() { |
| 791 | try { |
| 792 | return mService.isScreenBrightnessBoosted(); |
| 793 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 794 | throw e.rethrowFromSystemServer(); |
Bryce Lee | 84d6c0f | 2015-03-17 10:43:08 -0700 | [diff] [blame] | 795 | } |
| 796 | } |
| 797 | |
| 798 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 799 | * Sets the brightness of the backlights (screen, keyboard, button). |
| 800 | * <p> |
| 801 | * Requires the {@link android.Manifest.permission#DEVICE_POWER} permission. |
| 802 | * </p> |
| 803 | * |
| 804 | * @param brightness The brightness value from 0 to 255. |
| 805 | * |
Jeff Brown | 7d82751 | 2014-08-21 21:56:02 -0700 | [diff] [blame] | 806 | * @hide Requires signature permission. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 807 | */ |
| 808 | public void setBacklightBrightness(int brightness) { |
| 809 | try { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 810 | mService.setTemporaryScreenBrightnessSettingOverride(brightness); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 811 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 812 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | |
| 816 | /** |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 817 | * Returns true if the specified wake lock level is supported. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 818 | * |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 819 | * @param level The wake lock level to check. |
| 820 | * @return True if the specified wake lock level is supported. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 821 | */ |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 822 | public boolean isWakeLockLevelSupported(int level) { |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 823 | try { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 824 | return mService.isWakeLockLevelSupported(level); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 825 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 826 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
| 830 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 831 | * Returns true if the device is in an interactive state. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 832 | * <p> |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 833 | * For historical reasons, the name of this method refers to the power state of |
| 834 | * the screen but it actually describes the overall interactive state of |
| 835 | * the device. This method has been replaced by {@link #isInteractive}. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 836 | * </p><p> |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 837 | * The value returned by this method only indicates whether the device is |
| 838 | * in an interactive state which may have nothing to do with the screen being |
| 839 | * on or off. To determine the actual state of the screen, |
| 840 | * use {@link android.view.Display#getState}. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 841 | * </p> |
| 842 | * |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 843 | * @return True if the device is in an interactive state. |
| 844 | * |
| 845 | * @deprecated Use {@link #isInteractive} instead. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 846 | */ |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 847 | @Deprecated |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 848 | public boolean isScreenOn() { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 849 | return isInteractive(); |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Returns true if the device is in an interactive state. |
| 854 | * <p> |
| 855 | * When this method returns true, the device is awake and ready to interact |
| 856 | * with the user (although this is not a guarantee that the user is actively |
| 857 | * interacting with the device just this moment). The main screen is usually |
| 858 | * turned on while in this state. Certain features, such as the proximity |
| 859 | * sensor, may temporarily turn off the screen while still leaving the device in an |
| 860 | * interactive state. Note in particular that the device is still considered |
| 861 | * to be interactive while dreaming (since dreams can be interactive) but not |
| 862 | * when it is dozing or asleep. |
| 863 | * </p><p> |
| 864 | * When this method returns false, the device is dozing or asleep and must |
| 865 | * be awoken before it will become ready to interact with the user again. The |
| 866 | * main screen is usually turned off while in this state. Certain features, |
| 867 | * such as "ambient mode" may cause the main screen to remain on (albeit in a |
| 868 | * low power state) to display system-provided content while the device dozes. |
| 869 | * </p><p> |
| 870 | * The system will send a {@link android.content.Intent#ACTION_SCREEN_ON screen on} |
| 871 | * or {@link android.content.Intent#ACTION_SCREEN_OFF screen off} broadcast |
| 872 | * whenever the interactive state of the device changes. For historical reasons, |
| 873 | * the names of these broadcasts refer to the power state of the screen |
| 874 | * but they are actually sent in response to changes in the overall interactive |
| 875 | * state of the device, as described by this method. |
| 876 | * </p><p> |
| 877 | * Services may use the non-interactive state as a hint to conserve power |
| 878 | * since the user is not present. |
| 879 | * </p> |
| 880 | * |
| 881 | * @return True if the device is in an interactive state. |
| 882 | * |
| 883 | * @see android.content.Intent#ACTION_SCREEN_ON |
| 884 | * @see android.content.Intent#ACTION_SCREEN_OFF |
| 885 | */ |
| 886 | public boolean isInteractive() { |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 887 | try { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 888 | return mService.isInteractive(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 889 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 890 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
| 894 | /** |
| 895 | * Reboot the device. Will not return if the reboot is successful. |
| 896 | * <p> |
| 897 | * Requires the {@link android.Manifest.permission#REBOOT} permission. |
| 898 | * </p> |
| 899 | * |
| 900 | * @param reason code to pass to the kernel (e.g., "recovery") to |
| 901 | * request special boot modes, or null. |
| 902 | */ |
| 903 | public void reboot(String reason) { |
| 904 | try { |
Dianne Hackborn | c428aae | 2012-10-03 16:38:22 -0700 | [diff] [blame] | 905 | mService.reboot(false, reason, true); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 906 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 907 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | |
| 911 | /** |
Tony Mantler | b8009fd | 2016-03-14 15:55:35 -0700 | [diff] [blame] | 912 | * Reboot the device. Will not return if the reboot is successful. |
| 913 | * <p> |
| 914 | * Requires the {@link android.Manifest.permission#REBOOT} permission. |
| 915 | * </p> |
| 916 | * @hide |
| 917 | */ |
| 918 | public void rebootSafeMode() { |
| 919 | try { |
| 920 | mService.rebootSafeMode(false, true); |
| 921 | } catch (RemoteException e) { |
| 922 | throw e.rethrowFromSystemServer(); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | /** |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 927 | * Returns true if the device is currently in power save mode. When in this mode, |
| 928 | * applications should reduce their functionality in order to conserve battery as |
| 929 | * much as possible. You can monitor for changes to this state with |
| 930 | * {@link #ACTION_POWER_SAVE_MODE_CHANGED}. |
| 931 | * |
| 932 | * @return Returns true if currently in low power mode, else false. |
| 933 | */ |
| 934 | public boolean isPowerSaveMode() { |
| 935 | try { |
| 936 | return mService.isPowerSaveMode(); |
| 937 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 938 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 939 | } |
| 940 | } |
| 941 | |
| 942 | /** |
John Spurlock | 8d4e6cb | 2014-09-14 11:10:22 -0400 | [diff] [blame] | 943 | * Set the current power save mode. |
| 944 | * |
| 945 | * @return True if the set was allowed. |
| 946 | * |
| 947 | * @see #isPowerSaveMode() |
| 948 | * |
| 949 | * @hide |
| 950 | */ |
| 951 | public boolean setPowerSaveMode(boolean mode) { |
| 952 | try { |
| 953 | return mService.setPowerSaveMode(mode); |
| 954 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 955 | throw e.rethrowFromSystemServer(); |
John Spurlock | 8d4e6cb | 2014-09-14 11:10:22 -0400 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
| 959 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 960 | * Returns true if the device is currently in idle mode. This happens when a device |
| 961 | * has been sitting unused and unmoving for a sufficiently long period of time, so that |
| 962 | * it decides to go into a lower power-use state. This may involve things like turning |
| 963 | * off network access to apps. You can monitor for changes to this state with |
| 964 | * {@link #ACTION_DEVICE_IDLE_MODE_CHANGED}. |
| 965 | * |
Dianne Hackborn | ece0f4f | 2015-06-11 13:29:01 -0700 | [diff] [blame] | 966 | * @return Returns true if currently in active device idle mode, else false. This is |
| 967 | * when idle mode restrictions are being actively applied; it will return false if the |
| 968 | * device is in a long-term idle mode but currently running a maintenance window where |
| 969 | * restrictions have been lifted. |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 970 | */ |
| 971 | public boolean isDeviceIdleMode() { |
| 972 | try { |
| 973 | return mService.isDeviceIdleMode(); |
| 974 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 975 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | |
| 979 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 980 | * Returns true if the device is currently in light idle mode. This happens when a device |
| 981 | * has had its screen off for a short time, switching it into a batching mode where we |
| 982 | * execute jobs, syncs, networking on a batching schedule. You can monitor for changes to |
| 983 | * this state with {@link #ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED}. |
| 984 | * |
| 985 | * @return Returns true if currently in active light device idle mode, else false. This is |
| 986 | * when light idle mode restrictions are being actively applied; it will return false if the |
| 987 | * device is in a long-term idle mode but currently running a maintenance window where |
| 988 | * restrictions have been lifted. |
| 989 | * @hide |
| 990 | */ |
| 991 | public boolean isLightDeviceIdleMode() { |
| 992 | try { |
| 993 | return mService.isLightDeviceIdleMode(); |
| 994 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 995 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 996 | } |
| 997 | } |
| 998 | |
| 999 | /** |
Dianne Hackborn | 1958e5e | 2015-06-12 18:11:41 -0700 | [diff] [blame] | 1000 | * Return whether the given application package name is on the device's power whitelist. |
| 1001 | * Apps can be placed on the whitelist through the settings UI invoked by |
| 1002 | * {@link android.provider.Settings#ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS}. |
| 1003 | */ |
| 1004 | public boolean isIgnoringBatteryOptimizations(String packageName) { |
| 1005 | synchronized (this) { |
| 1006 | if (mIDeviceIdleController == null) { |
| 1007 | mIDeviceIdleController = IDeviceIdleController.Stub.asInterface( |
| 1008 | ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER)); |
| 1009 | } |
| 1010 | } |
| 1011 | try { |
| 1012 | return mIDeviceIdleController.isPowerSaveWhitelistApp(packageName); |
| 1013 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1014 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 1958e5e | 2015-06-12 18:11:41 -0700 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | /** |
Filip Gruszczynski | d05af86 | 2015-02-04 09:48:47 -0800 | [diff] [blame] | 1019 | * Turn off the device. |
| 1020 | * |
| 1021 | * @param confirm If true, shows a shutdown confirmation dialog. |
Yusuke Sato | 705ffd1 | 2015-07-21 15:52:11 -0700 | [diff] [blame] | 1022 | * @param reason code to pass to android_reboot() (e.g. "userrequested"), or null. |
Filip Gruszczynski | d05af86 | 2015-02-04 09:48:47 -0800 | [diff] [blame] | 1023 | * @param wait If true, this call waits for the shutdown to complete and does not return. |
| 1024 | * |
| 1025 | * @hide |
| 1026 | */ |
Yusuke Sato | 705ffd1 | 2015-07-21 15:52:11 -0700 | [diff] [blame] | 1027 | public void shutdown(boolean confirm, String reason, boolean wait) { |
Filip Gruszczynski | d05af86 | 2015-02-04 09:48:47 -0800 | [diff] [blame] | 1028 | try { |
Yusuke Sato | 705ffd1 | 2015-07-21 15:52:11 -0700 | [diff] [blame] | 1029 | mService.shutdown(confirm, reason, wait); |
Filip Gruszczynski | d05af86 | 2015-02-04 09:48:47 -0800 | [diff] [blame] | 1030 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1031 | throw e.rethrowFromSystemServer(); |
Filip Gruszczynski | d05af86 | 2015-02-04 09:48:47 -0800 | [diff] [blame] | 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | /** |
Dianne Hackborn | eb94fa7 | 2014-06-03 17:48:12 -0700 | [diff] [blame] | 1036 | * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes. |
| 1037 | * This broadcast is only sent to registered receivers. |
| 1038 | */ |
| 1039 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1040 | public static final String ACTION_POWER_SAVE_MODE_CHANGED |
| 1041 | = "android.os.action.POWER_SAVE_MODE_CHANGED"; |
| 1042 | |
| 1043 | /** |
Jason Monk | afae4bd | 2015-12-15 14:20:06 -0500 | [diff] [blame] | 1044 | * Intent that is broadcast when the state of {@link #isPowerSaveMode()} changes. |
| 1045 | * @hide |
| 1046 | */ |
| 1047 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1048 | public static final String ACTION_POWER_SAVE_MODE_CHANGED_INTERNAL |
| 1049 | = "android.os.action.POWER_SAVE_MODE_CHANGED_INTERNAL"; |
| 1050 | |
| 1051 | /** |
Dianne Hackborn | 88e98df | 2015-03-23 13:29:14 -0700 | [diff] [blame] | 1052 | * Intent that is broadcast when the state of {@link #isDeviceIdleMode()} changes. |
| 1053 | * This broadcast is only sent to registered receivers. |
| 1054 | */ |
| 1055 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1056 | public static final String ACTION_DEVICE_IDLE_MODE_CHANGED |
| 1057 | = "android.os.action.DEVICE_IDLE_MODE_CHANGED"; |
| 1058 | |
| 1059 | /** |
Dianne Hackborn | 08c47a5 | 2015-10-15 12:38:14 -0700 | [diff] [blame] | 1060 | * Intent that is broadcast when the state of {@link #isLightDeviceIdleMode()} changes. |
| 1061 | * This broadcast is only sent to registered receivers. |
| 1062 | * @hide |
| 1063 | */ |
| 1064 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1065 | public static final String ACTION_LIGHT_DEVICE_IDLE_MODE_CHANGED |
| 1066 | = "android.os.action.LIGHT_DEVICE_IDLE_MODE_CHANGED"; |
| 1067 | |
| 1068 | /** |
Dianne Hackborn | 0b4daca | 2015-04-27 09:47:32 -0700 | [diff] [blame] | 1069 | * @hide Intent that is broadcast when the set of power save whitelist apps has changed. |
| 1070 | * This broadcast is only sent to registered receivers. |
| 1071 | */ |
| 1072 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1073 | public static final String ACTION_POWER_SAVE_WHITELIST_CHANGED |
| 1074 | = "android.os.action.POWER_SAVE_WHITELIST_CHANGED"; |
| 1075 | |
| 1076 | /** |
Amith Yamasani | af575b9 | 2015-05-29 15:35:26 -0700 | [diff] [blame] | 1077 | * @hide Intent that is broadcast when the set of temporarily whitelisted apps has changed. |
| 1078 | * This broadcast is only sent to registered receivers. |
| 1079 | */ |
| 1080 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1081 | public static final String ACTION_POWER_SAVE_TEMP_WHITELIST_CHANGED |
| 1082 | = "android.os.action.POWER_SAVE_TEMP_WHITELIST_CHANGED"; |
| 1083 | |
| 1084 | /** |
John Spurlock | 1bb480a | 2014-08-02 17:12:43 -0400 | [diff] [blame] | 1085 | * Intent that is broadcast when the state of {@link #isPowerSaveMode()} is about to change. |
| 1086 | * This broadcast is only sent to registered receivers. |
| 1087 | * |
| 1088 | * @hide |
| 1089 | */ |
| 1090 | @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) |
| 1091 | public static final String ACTION_POWER_SAVE_MODE_CHANGING |
| 1092 | = "android.os.action.POWER_SAVE_MODE_CHANGING"; |
| 1093 | |
| 1094 | /** @hide */ |
| 1095 | public static final String EXTRA_POWER_SAVE_MODE = "mode"; |
| 1096 | |
| 1097 | /** |
Bryce Lee | 84d6c0f | 2015-03-17 10:43:08 -0700 | [diff] [blame] | 1098 | * Intent that is broadcast when the state of {@link #isScreenBrightnessBoosted()} has changed. |
| 1099 | * This broadcast is only sent to registered receivers. |
| 1100 | * |
| 1101 | * @hide |
| 1102 | **/ |
| 1103 | @SystemApi |
| 1104 | public static final String ACTION_SCREEN_BRIGHTNESS_BOOST_CHANGED |
| 1105 | = "android.os.action.SCREEN_BRIGHTNESS_BOOST_CHANGED"; |
| 1106 | |
| 1107 | /** |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1108 | * A wake lock is a mechanism to indicate that your application needs |
| 1109 | * to have the device stay on. |
Kenny Root | d710fb5 | 2011-03-15 17:39:45 -0700 | [diff] [blame] | 1110 | * <p> |
| 1111 | * Any application using a WakeLock must request the {@code android.permission.WAKE_LOCK} |
Neil Fuller | 71fbb81 | 2015-11-30 09:51:33 +0000 | [diff] [blame] | 1112 | * permission in an {@code <uses-permission>} element of the application's manifest. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1113 | * Obtain a wake lock by calling {@link PowerManager#newWakeLock(int, String)}. |
| 1114 | * </p><p> |
| 1115 | * Call {@link #acquire()} to acquire the wake lock and force the device to stay |
| 1116 | * on at the level that was requested when the wake lock was created. |
| 1117 | * </p><p> |
| 1118 | * Call {@link #release()} when you are done and don't need the lock anymore. |
| 1119 | * It is very important to do this as soon as possible to avoid running down the |
| 1120 | * device's battery excessively. |
| 1121 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1122 | */ |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1123 | public final class WakeLock { |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1124 | private int mFlags; |
| 1125 | private String mTag; |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1126 | private final String mPackageName; |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1127 | private final IBinder mToken; |
| 1128 | private int mCount; |
| 1129 | private boolean mRefCounted = true; |
| 1130 | private boolean mHeld; |
| 1131 | private WorkSource mWorkSource; |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1132 | private String mHistoryTag; |
Jeff Brown | 3edf527 | 2014-08-14 19:25:14 -0700 | [diff] [blame] | 1133 | private final String mTraceName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1135 | private final Runnable mReleaser = new Runnable() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1136 | public void run() { |
| 1137 | release(); |
| 1138 | } |
| 1139 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1140 | |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1141 | WakeLock(int flags, String tag, String packageName) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | mFlags = flags; |
| 1143 | mTag = tag; |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 1144 | mPackageName = packageName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1145 | mToken = new Binder(); |
Jeff Brown | 3edf527 | 2014-08-14 19:25:14 -0700 | [diff] [blame] | 1146 | mTraceName = "WakeLock (" + mTag + ")"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | } |
| 1148 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1149 | @Override |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1150 | protected void finalize() throws Throwable { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | synchronized (mToken) { |
| 1152 | if (mHeld) { |
Dan Egnor | 60d8762 | 2009-12-16 16:32:58 -0800 | [diff] [blame] | 1153 | Log.wtf(TAG, "WakeLock finalized while still held: " + mTag); |
Jeff Brown | 3edf527 | 2014-08-14 19:25:14 -0700 | [diff] [blame] | 1154 | Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, mTraceName, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | try { |
Mike Lockwood | 0e39ea8 | 2009-11-18 15:37:10 -0500 | [diff] [blame] | 1156 | mService.releaseWakeLock(mToken, 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1158 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | } |
| 1161 | } |
| 1162 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1163 | |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1164 | /** |
| 1165 | * Sets whether this WakeLock is reference counted. |
| 1166 | * <p> |
| 1167 | * Wake locks are reference counted by default. If a wake lock is |
| 1168 | * reference counted, then each call to {@link #acquire()} must be |
| 1169 | * balanced by an equal number of calls to {@link #release()}. If a wake |
| 1170 | * lock is not reference counted, then one call to {@link #release()} is |
| 1171 | * sufficient to undo the effect of all previous calls to {@link #acquire()}. |
| 1172 | * </p> |
| 1173 | * |
| 1174 | * @param value True to make the wake lock reference counted, false to |
| 1175 | * make the wake lock non-reference counted. |
| 1176 | */ |
| 1177 | public void setReferenceCounted(boolean value) { |
| 1178 | synchronized (mToken) { |
| 1179 | mRefCounted = value; |
| 1180 | } |
Mike Lockwood | f5bd092 | 2010-03-22 17:10:15 -0400 | [diff] [blame] | 1181 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1182 | |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1183 | /** |
| 1184 | * Acquires the wake lock. |
| 1185 | * <p> |
| 1186 | * Ensures that the device is on at the level requested when |
| 1187 | * the wake lock was created. |
| 1188 | * </p> |
| 1189 | */ |
| 1190 | public void acquire() { |
| 1191 | synchronized (mToken) { |
| 1192 | acquireLocked(); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | /** |
| 1197 | * Acquires the wake lock with a timeout. |
| 1198 | * <p> |
| 1199 | * Ensures that the device is on at the level requested when |
| 1200 | * the wake lock was created. The lock will be released after the given timeout |
| 1201 | * expires. |
| 1202 | * </p> |
| 1203 | * |
| 1204 | * @param timeout The timeout after which to release the wake lock, in milliseconds. |
| 1205 | */ |
| 1206 | public void acquire(long timeout) { |
| 1207 | synchronized (mToken) { |
| 1208 | acquireLocked(); |
| 1209 | mHandler.postDelayed(mReleaser, timeout); |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | private void acquireLocked() { |
| 1214 | if (!mRefCounted || mCount++ == 0) { |
Jeff Brown | ff1baef | 2012-07-19 15:01:17 -0700 | [diff] [blame] | 1215 | // Do this even if the wake lock is already thought to be held (mHeld == true) |
| 1216 | // because non-reference counted wake locks are not always properly released. |
| 1217 | // For example, the keyguard's wake lock might be forcibly released by the |
| 1218 | // power manager without the keyguard knowing. A subsequent call to acquire |
| 1219 | // should immediately acquire the wake lock once again despite never having |
| 1220 | // been explicitly released by the keyguard. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1221 | mHandler.removeCallbacks(mReleaser); |
Jeff Brown | 3edf527 | 2014-08-14 19:25:14 -0700 | [diff] [blame] | 1222 | Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, mTraceName, 0); |
Jeff Brown | ff1baef | 2012-07-19 15:01:17 -0700 | [diff] [blame] | 1223 | try { |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1224 | mService.acquireWakeLock(mToken, mFlags, mTag, mPackageName, mWorkSource, |
| 1225 | mHistoryTag); |
Jeff Brown | ff1baef | 2012-07-19 15:01:17 -0700 | [diff] [blame] | 1226 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1227 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1228 | } |
Jeff Brown | ff1baef | 2012-07-19 15:01:17 -0700 | [diff] [blame] | 1229 | mHeld = true; |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * Releases the wake lock. |
| 1235 | * <p> |
| 1236 | * This method releases your claim to the CPU or screen being on. |
| 1237 | * The screen may turn off shortly after you release the wake lock, or it may |
| 1238 | * not if there are other wake locks still held. |
| 1239 | * </p> |
| 1240 | */ |
| 1241 | public void release() { |
| 1242 | release(0); |
| 1243 | } |
| 1244 | |
| 1245 | /** |
| 1246 | * Releases the wake lock with flags to modify the release behavior. |
| 1247 | * <p> |
| 1248 | * This method releases your claim to the CPU or screen being on. |
| 1249 | * The screen may turn off shortly after you release the wake lock, or it may |
| 1250 | * not if there are other wake locks still held. |
| 1251 | * </p> |
| 1252 | * |
| 1253 | * @param flags Combination of flag values to modify the release behavior. |
Michael Wright | 1208e27 | 2014-09-08 19:57:50 -0700 | [diff] [blame] | 1254 | * Currently only {@link #RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY} is supported. |
| 1255 | * Passing 0 is equivalent to calling {@link #release()}. |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1256 | */ |
| 1257 | public void release(int flags) { |
| 1258 | synchronized (mToken) { |
| 1259 | if (!mRefCounted || --mCount == 0) { |
| 1260 | mHandler.removeCallbacks(mReleaser); |
| 1261 | if (mHeld) { |
Jeff Brown | 3edf527 | 2014-08-14 19:25:14 -0700 | [diff] [blame] | 1262 | Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, mTraceName, 0); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1263 | try { |
| 1264 | mService.releaseWakeLock(mToken, flags); |
| 1265 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1266 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1267 | } |
| 1268 | mHeld = false; |
| 1269 | } |
| 1270 | } |
| 1271 | if (mCount < 0) { |
| 1272 | throw new RuntimeException("WakeLock under-locked " + mTag); |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * Returns true if the wake lock has been acquired but not yet released. |
| 1279 | * |
| 1280 | * @return True if the wake lock is held. |
| 1281 | */ |
| 1282 | public boolean isHeld() { |
| 1283 | synchronized (mToken) { |
| 1284 | return mHeld; |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | /** |
| 1289 | * Sets the work source associated with the wake lock. |
| 1290 | * <p> |
| 1291 | * The work source is used to determine on behalf of which application |
| 1292 | * the wake lock is being held. This is useful in the case where a |
| 1293 | * service is performing work on behalf of an application so that the |
| 1294 | * cost of that work can be accounted to the application. |
| 1295 | * </p> |
| 1296 | * |
| 1297 | * @param ws The work source, or null if none. |
| 1298 | */ |
| 1299 | public void setWorkSource(WorkSource ws) { |
| 1300 | synchronized (mToken) { |
| 1301 | if (ws != null && ws.size() == 0) { |
| 1302 | ws = null; |
| 1303 | } |
| 1304 | |
| 1305 | final boolean changed; |
| 1306 | if (ws == null) { |
| 1307 | changed = mWorkSource != null; |
| 1308 | mWorkSource = null; |
| 1309 | } else if (mWorkSource == null) { |
| 1310 | changed = true; |
| 1311 | mWorkSource = new WorkSource(ws); |
| 1312 | } else { |
| 1313 | changed = mWorkSource.diff(ws); |
| 1314 | if (changed) { |
| 1315 | mWorkSource.set(ws); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | if (changed && mHeld) { |
| 1320 | try { |
Dianne Hackborn | 4590e52 | 2014-03-24 13:36:46 -0700 | [diff] [blame] | 1321 | mService.updateWakeLockWorkSource(mToken, mWorkSource, mHistoryTag); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1322 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 1323 | throw e.rethrowFromSystemServer(); |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1329 | /** @hide */ |
| 1330 | public void setTag(String tag) { |
| 1331 | mTag = tag; |
| 1332 | } |
| 1333 | |
| 1334 | /** @hide */ |
Dianne Hackborn | a1f1a3c | 2014-02-24 18:12:28 -0800 | [diff] [blame] | 1335 | public void setHistoryTag(String tag) { |
| 1336 | mHistoryTag = tag; |
| 1337 | } |
| 1338 | |
| 1339 | /** @hide */ |
Dianne Hackborn | 3d658bf | 2014-02-05 13:38:56 -0800 | [diff] [blame] | 1340 | public void setUnimportantForLogging(boolean state) { |
| 1341 | if (state) mFlags |= UNIMPORTANT_FOR_LOGGING; |
| 1342 | else mFlags &= ~UNIMPORTANT_FOR_LOGGING; |
| 1343 | } |
| 1344 | |
Jeff Brown | 1244cda | 2012-06-19 16:44:46 -0700 | [diff] [blame] | 1345 | @Override |
| 1346 | public String toString() { |
| 1347 | synchronized (mToken) { |
| 1348 | return "WakeLock{" |
| 1349 | + Integer.toHexString(System.identityHashCode(this)) |
| 1350 | + " held=" + mHeld + ", refCount=" + mCount + "}"; |
| 1351 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | } |
| 1353 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1354 | } |