博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Power Management
阅读量:7127 次
发布时间:2019-06-28

本文共 7758 字,大约阅读时间需要 25 分钟。

Power Management

Battery life is a perennial user concern. To extend battery life, Android continually adds new features and optimizations to help the platform optimize the off-charger behavior of applications and devices.

The Android 6.0 release includes the following improvements to battery life:

  • . The platform can now place unused applications in App Standby mode, temporarily restricting network access and deferring syncs and jobs for those applications.
  • . The platform now enters a state of deep sleep (periodically resuming normal operations) if users have not actively used their device (screen off and stationary) for extended periods of time. As this feature requires the platform to detect the stationary state, it is available only on devices that implement the significant motion detection APIs in the Sensor HAL. Doze dramatically improves battery life.
  • . System apps and cloud messaging services preloaded on a device are typically exempted by default. App developers can intent their applications into this setting. Users can also exempt applications from App Standby and Doze via Settings > Battery > Battery optimization > All apps and then selecting the app to turn off (or back on) optimization.

The following sections describe these improvements.

App Standby


App Standby extends battery life by deferring background network activity and jobs for applications the user is not actively using.

App Standby lifecycle

The platform detects inactive applications and places them in App Standby until the user begins actively engaging with the application.

Detection During App Standby Exit

The platform detects an application is inactive when the device is not charging and the user has not launched the application directly or indirectly for a specific amount of clock time as well as a specific amount of screen-on time. (Indirect launches occur when a foreground app accesses a service in a second app.)

The platform prevents applications from accessing the network more than once a day, deferring application syncs and other jobs.

The platform exits the app from App Standby when:

  • Application becomes active.
  • Device is plugged in and charging.

Active applications are unaffected by App Standby. An application is active when it has:

  • A process currently in the foreground (either as an activity or foreground service, or in use by another activity or foreground service), such as notification listener, accessibility services, live wallpaper, etc.
  • A notification viewed by the user, such as in the lock screen or notification tray.
  • Explicitly been launched by the user.

An application is inactive if none of the above activities has occurred for a period of time.

Testing App Standby

You can manually test App Standby using the following ADB commands:

$ adb shell dumpsys battery unplug $ adb shell am set-idle packageName true $ adb shell am set-idle packageName false $ adb shell am get-idle packageName

Doze


Doze extends battery life by deferring application 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 activities (syncs, jobs, etc.). Doze then resumes sleep for a longer period of time, followed by another maintenance window. The platform continues the Doze sleep/maintenance sequence, increasing the length of idle each time, until a maximum of a few hours of sleep time is reached. At all times, a device in Doze remains aware of motion and immediately leaves Doze if motion is detected.

System services (such as telephony) may be preloaded and exempted from Doze by default. Users can also exempt specific applications from Doze in the Settings menu. By default, Doze is disabled in the Android Open Source Project (AOSP). For details on enabling Doze, see .

Doze requirements

Doze support requires the following:

  • Device implements the in the Sensor HAL. Devices that do not implement these APIs cannot support Doze.
  • Device has a cloud messaging service, such as This enables the device to know when to wake from Doze.

Doze lifecycle

The Doze lifecycle begins when the platform detects the device is idle and ends when the device exits Doze mode.

Detection During Doze Exit

The platform detects a device is idle when:

  • Device is stationary (using significant motion detector).
  • Device screen is off for some amount of time.

Doze mode does not engage when the device is plugged into a power charger.

The platform attempts to keep the system in a sleep state, periodically resuming normal operations during a maintenance window then returning the device to sleep for longer repeating periods. During the sleep state, the following restrictions are active:

  • Apps not allowed network access.
  • App wakelocks ignored.
  • Alarms deferred. Excludes alarm clock alarms and alarms set using setAndAllowWhileIdle() (limited to 1 per 15 minutes per app while in Doze). This exemption is intended for apps (such as Calendar) that must show event reminder notifications.
  • Wi-Fi scans not performed.
  • SyncAdapter syncs and JobScheduler jobs deferred until the next maintenance window.
  • Apps receiving SMS and MMS messages are put on a temporary whitelist so they can complete their processing.

The platform exits the device from Doze when it detects:

  • User interaction with device.
  • Device movement.
  • Device screen turns on.
  • Imminent AlarmClock alarm.

Notifications do not cause the device to exit from Doze.

Interaction with App Standby

  • Time spent in Doze does not count towards App Standby.
  • While the device is in Doze, idle applications are allowed to perform normal operations at least once a day.

Integrating Doze

To enable Doze for a device, perform the following tasks:

  1. Confirm the device supports . If the device does not support this sensor, it cannot support Doze.
  2. Confirm the device has a cloud messaging service installed.
  3. In the device overlay config file overlay/frameworks/base/core/res/res/values/config.xml, set config_enableAutoPowerModes to true:
    bool name="config_enableAutoPowerModes">true
    In AOSP, this parameter is set to false (Doze disabled) by default.
  4. Confirm that preloaded apps and services:
    • Use the new . For details, see .

      OR

    • Are exempted from Doze and App Standby. For details, see .
  5. Confirm the necessary services are exempted from Doze.

Testing and optimizing applications

Test all applications (especially preloaded applications) in Doze mode. For details, refer to .

Note: MMS/SMS/Telephony services function independently of Doze and will always wake client apps even while the device remains in Doze mode.

Exempting applications


You can exempt applications from being subject to Doze or App Standby.

Warning: Do not exempt apps to avoid testing and optimizing. Unnecessary exemptions undermine the benefits of Doze and App Standby and can compromise the user experience, so we strongly suggest minimizing such exemptions as they allow applications to defeat beneficial controls the platform has over power use. If users become unhappy about the power consumption of these apps, it can lead to frustration, bad experiences (and negative user reviews for the app), and customer support questions. For these reasons, we strongly recommend that you do not exempt third-party applications and instead exempt only cloud messaging services or apps with similar functions.

Apps exempted by default are listed in a single view within the Settings > Battery menu. This list is used for exempting the app from both Doze and App Standby modes. To provide transparency to the user, the Settings menu MUST show all exempted applications.

Users can manually exempt apps using the Settings menu. However, users cannot unexempt any application or service that is exempted by default in the system image.

转载地址:http://qghel.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
我的友情链接
查看>>
转载-Linux新人必读,Linux发行版选择和软件安装的一些原则性问题
查看>>
Linux从入门到精通之监控软件Cacti
查看>>
徹底解決 Windows Server 2012 R2 惱人的輸入法問題
查看>>
linux 手动整理内存
查看>>
Android 向右滑动销毁(finish)Activity, 随着手势的滑动而滑动的效果
查看>>
Vue.js 自定义指令
查看>>
打开Nginx的rewrite日志
查看>>
[李景山php]每天laravel-20161121|StatusCommand.php
查看>>
通过Rancher部署并扩容Kubernetes集群基础篇二
查看>>
zabbix监控WEB页面及告警 实战
查看>>
编译器特性ARC
查看>>
实现自定义LookupComboBox
查看>>
Java复习笔记
查看>>
tomcat cpu负荷
查看>>
LVM 文件系统
查看>>
asp中的escape和unescape
查看>>
centos操作系统上实现网卡端口绑定-chenjhh@dc
查看>>
Logstash 最佳实践
查看>>