【发布时间】:2019-03-30 02:38:25
【问题描述】:
我正在通过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 来执行此操作,但如果所有其他方法都失败了,我可以manually control doze with root using these commands,但这听起来很乱,我不想搞砸任何其他应用的打瞌睡交互。
另外,我只特别关注 Android Pie (9.0) 及更高版本。
更新:
我也试过获取DOZE_WAKE_LOCK,但是需要系统权限DEVICE_POWER。我尝试adb shell pm grant 我的应用程序的权限,但它不是可更改的权限类型。
【问题讨论】:
-
您的应用需要做什么?播放内容?是否有任何后台服务正在进行或仅与用户界面有关?
-
@YvetteColomb 我想主要显示静态信息(但可能经常需要更改或动画以避免老化)
-
@BLuFeNiX 你找到解决办法了吗?
-
@user3405331 不,很遗憾。不过,我对 Android 9 进行了初步研究,因此 Android 10 可能有一些方法可以实现这一点。
-
@BLuFeNiX 如果我们通过 adb 授予 WRITE_SECURE_SETTINGS 权限,那么我们可以编辑 device_idle_constants 一定有办法解决,但没有适当的文档
标签: android android-source android-9.0-pie android-doze android-doze-and-standby