我正在制作一个应用程序,该应用程序将在设备锁定时运行,通过Activity#setShowWhenLocked(true)
. 我不想阻止设备进入低功耗状态。我知道系统使用 来执行此操作Always-On Display
,并且显示器具有相关的电源模式:
/frameworks/base/core/java/android/view/Display.java
286 /**
287 * Display state: The display is dozing in a low power state; it is still
288 * on but is optimized for showing system-provided content while the
289 * device is non-interactive.
290 *
291 * @see #getState
292 * @see android.os.PowerManager#isInteractive
293 */
294 public static final int STATE_DOZE = ViewProtoEnums.DISPLAY_STATE_DOZE; // 3
295
296 /**
297 * Display state: The display is dozing in a suspended low power state; it is still
298 * on but the CPU is not updating it. This may be used in one of two ways: to show
299 * static system-provided content while the device is non-interactive, or to allow
300 * a "Sidekick" compute resource to update the display. For this reason, the
301 * CPU must not control the display in this mode.
302 *
303 * @see #getState
304 * @see android.os.PowerManager#isInteractive
305 */
306 public static final int STATE_DOZE_SUSPEND = ViewProtoEnums.DISPLAY_STATE_DOZE_SUSPEND; // 4
/frameworks/base/core/java/android/os/PowerManagerInternal.java中也有此部分:
51 * Wakefulness: The device is dozing. It is almost asleep but is allowing a special
52 * low-power "doze" dream to run which keeps the display on but lets the application
53 * processor be suspended. It can be awoken by a call to wakeUp() which ends the dream.
54 * The device fully goes to sleep if the dream cannot be started or ends on its own.
55 */
56 public static final int WAKEFULNESS_DOZING = 3;
如果可能的话,我想避免使用 root来执行此操作,但如果所有其他方法都失败了,我可以使用这些命令手动控制打瞌睡,但这听起来很混乱,我不想弄乱任何其他应用程序的打瞌睡交互。
此外,我只特别关注 Android Pie (9.0) 及更高版本。
更新:
我也试过获取一个DOZE_WAKE_LOCK
,但它需要系统权限DEVICE_POWER
。我尝试adb shell pm grant
了对我的应用程序的权限,但它不是可更改的权限类型。