如何在Android上测试打ze模式

如何在Android上测试打ze模式

本文介绍了如何在Android上测试打ze模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个旧的Android应用程序,该应用程序可运行后台2服务(服务)。

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

更新该应用程序需要在工作期间发送数据和记录日志不是新的DozeMode。在修改当前代码之前,我决定检查一下现在所有的工作方式。为了运行该应用程序,我在日志中看到两个服务都在运行(该服务的基本含义是读取设备的位置,第二个服务将数据发送到服务器)。使用命令关闭屏幕

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

将系统转换为DozeMode:

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

如果我正确理解所有内容,请按照文档说明的所有模式使用IDLE,应关闭Jobsheduler,警报管理器和其他后台组件。但是,这没有发生。从日志来看,该应用程序可以正常运行,并且DozeMode可能我做错了。

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.

告诉我,也许有什么最佳实践可以测试DozeMode和( ),如果在后台(例如,关闭应用程序时)有任何动作,可以使用服务重写为更现代的版本。

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,应用程序丢失在允许的非最佳电池寿命(白名单)列表中

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
现在被迫进入空闲模式
应用程序当前可以运行

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

推荐答案

这里有一些有关空闲模式的有用信息:

deviceidle -是一项新的android服务,它将始终运行并侦听多个系统事件,这些事件可触发它进入/退出空闲状态模式(也称为打ze模式):

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 -当设备处于唤醒状态且正在使用中时,控制器处于活动状态。诸如闲置超时,用户关闭屏幕电源,运动检测等外部事件将使状态机进入闲置状态。
此状态机包含七个状态:

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.

空闲状态-为了将设备置于空闲状态下,可以使用以下adb命令:

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

我还需要一个快速选项来在活动状态和空闲状态之间切换因此我出于以下目的编写了一个批处理脚本 adbIdleModeSwitch.bat ,您可以下载并使用它:

这篇关于如何在Android上测试打ze模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:12