我正在做一个应用程序,将运行时,设备锁定,通过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;如果可能的话,我希望避免使用根来完成这个任务,但是如果其他所有操作都失败了,我可以使用使用以下命令手动控制根用户打瞌睡,但这听起来很麻烦,我不想破坏其他应用程序的打瞌睡交互。
另外,我只特别关注Android (9.0)和以后的版本。
更新:
我也尝试过获得一个DOZE_WAKE_LOCK,但它需要系统权限DEVICE_POWER。我试图adb shell pm grant对我的应用程序的权限,但它不是一个可变的权限类型。
发布于 2018-10-31 09:37:23
您可以通过屏幕保护程序DreamService来完成这一任务。你不能通过活动来做这件事。活动阻止设备进入睡眠模式。
梦想是在充电设备空闲或停靠在办公桌码头时启动的交互式屏幕保护程序。梦想为应用程序提供了另一种表达自己的方式,为展览/精益体验量身定做。
发布于 2018-11-29 15:19:44
你想要的是android穿戴的环境模式,它允许活动在设备睡觉时显示可绘制的线条(通常是带有黑色背景的白线)。据我所知,电话设备的代码没有这个特性,因为您的活动必须扩展一个名为WearableActivity的类,并由名为Ambient的系统应用程序管理。您找到的wake锁DOZE_WAKE_LOCK在这个Ambient应用程序中使用。
https://stackoverflow.com/questions/52990019
复制相似问题