How to test Doze Mode on Android?

限于喜欢 提交于 2019-12-30 06:37:25

问题


There is an old Android app which work background 2 service (Service).

It took to update the app with the possibility of sending data and logging while working is not a new DozeMode. Before you amend the current code I decided to check how everything will work now. To run the application, in the logs I see that both services are running (the basic meaning of the service to read the position of the device, the second service sends the data to the server). Turn off the screen with the command

adb shell dumpsys deviceidle step

translate the system to DozeMode:

Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: ACTIVE
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: IDLE_PENDING
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: SENSING
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: LOCATING
Nikita:app NG$ adb shell dumpsys deviceidle step
Stepped to: IDLE

If I understand everything correctly - IDLE just the same mode in which according to the documentation all services, jobsheduler's, alarm managers, and other background components should be turned off. But this is not happening. Judging by the logs, the app works as intended and DozeMode either I'm doing something wrong.

Tell me, maybe are there any best practics for testing DozeMode and (late) rewriting with Services to a more modern, if there ways any action in the background (i.e. when you closed the app).

Android 6, BlackView BV6000S, Application is missing in the list permitted for non-optimal battery life (whitelist)

UPD: Nikita:app NG$ adb shell dumpsys deviceidle force-idle Now forced in to idle mode app works currently


回答1:


Here is some useful information on Idle Mode:

deviceidle - Is a new android service, that will always run and listen for the several system events, which can trigger it in/out of the idle mode (also known as a Doze mode):

1.Screen on/off
2.Charging status
3.Significant motion detect

DeviceIdleController - When the device is awake and in-use, the controller is in the ACTIVE state. External events like inactivity time-out, user powering off the screen, motion detection ... will drive the state machine into INACTIVE. This state machine contains seven states:

1.ACTIVE - Device is in use, or connected to a charge source.
2.INACTIVE - Device has recently come out of the active state, meaning that user turned off the display or unplugged it.
3.IDLE_PENDING - Hold on, we are about to enter idle mode.
4.SENSING
5.LOCATING
6.IDLE - Device is idle.
7.IDLE_MAINTENANCE - Window is open for applications to do processing. Then will back to IDLE.

Idle State - In order to put the device into an Idle state you can use the following adb commands:

>adb shell dumpsys battery unplug
>adb shell dumpsys deviceidle force-idle

Active State - In order to put the device back into the Active state you may simulate the following key event:

> adb shell input keyevent KEYCODE_WAKEUP

I also needed a quick option to toggle between Active and Idle states so I wrote a batch script adbIdleModeSwitch.bat for these purposes, you may download and use it: https://drive.google.com/file/d/0B81qFnPX_eUUYTMxOTd1UG94NVk/view



来源:https://stackoverflow.com/questions/43048010/how-to-test-doze-mode-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!