Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Doze Mode on Android?

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

like image 700
abbath0767 Avatar asked Mar 27 '17 13:03

abbath0767


People also ask

How do I turn off Samsung doze mode?

Tap the more button on the action bar at the top right, and choose Optimize battery usage. 5. On the Optimize Battery Usage screen, switch to the All apps list from the drop-down to see all of the apps on your device. Turn off to exclude Nine from the Doze feature.

What is doze mode?

Doze. Doze extends battery life by deferring app background CPU and network activity when a device is unused for long periods. Idle devices in Doze periodically enter a maintenance window, during which apps can complete pending work (syncs, jobs, etc.).


1 Answers

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

like image 188
AivarsDa Avatar answered Sep 24 '22 01:09

AivarsDa