Android O 的Doze模式白名单路径

Doze 模式列表

上述备注规则如下

if(powerWhitelist.isSysWhitelisted(pkg)) {// Summary of app which doesn't have a battery optimization setting
    show:Battery optimization not available
} else {if(powerWhitelist.isWhitelisted(pkg)) {// Summary of app allowed to use a lot of power
    show:Not optimized} else {// Summary of app which doesn't have a battery optimization setting
    show:Optimizing battery use}
}
  • 具体读取路径源码如下

系统路径

package com.android.server;/*** Loads global system configuration info.*/
public class SystemConfig {static final String TAG = "SystemConfig";SystemConfig() {// Read configuration from systemreadPermissions(Environment.buildPath(Environment.getRootDirectory(), "etc", "sysconfig"), ALLOW_ALL);// Read configuration from the old permissions dirreadPermissions(Environment.buildPath(Environment.getRootDirectory(), "etc", "permissions"), ALLOW_ALL);// Allow Vendor to customize system configs around libs, features, permissions and appsint vendorPermissionFlag = ALLOW_LIBS | ALLOW_FEATURES | ALLOW_PERMISSIONS |ALLOW_APP_CONFIGS;readPermissions(Environment.buildPath(Environment.getVendorDirectory(), "etc", "sysconfig"), vendorPermissionFlag);readPermissions(Environment.buildPath(Environment.getVendorDirectory(), "etc", "permissions"), vendorPermissionFlag);// Allow ODM to customize system configs around libs, features and appsint odmPermissionFlag = ALLOW_LIBS | ALLOW_FEATURES | ALLOW_APP_CONFIGS;readPermissions(Environment.buildPath(Environment.getOdmDirectory(), "etc", "sysconfig"), odmPermissionFlag);readPermissions(Environment.buildPath(Environment.getOdmDirectory(), "etc", "permissions"), odmPermissionFlag);// Only allow OEM to customize featuresreadPermissions(Environment.buildPath(Environment.getOemDirectory(), "etc", "sysconfig"), ALLOW_FEATURES);readPermissions(Environment.buildPath(Environment.getOemDirectory(), "etc", "permissions"), ALLOW_FEATURES);}
  • 由于Android O 解耦的思想,上述源码即如下路径

1.RootDirectory 
etc/sysconfig/ 
etc/permissions/

我的机器没有etc/sysconfig/路径
Z50:/etc/permissions # ls
ls
android.software.live_wallpaper.xml  mediatek-packages-teleservice.xml
android.software.webview.xml         platform.xml
com.android.location.provider.xml    pms_sysapp_removable_system_list.txt
com.android.media.remotedisplay.xml  privapp-permissions-google.xml
com.android.mediadrm.signer.xml      privapp-permissions-mediatek.xml
com.google.android.maps.xml          privapp-permissions-platform.xml
com.google.android.media.effects.xml
  • 2.VendorDirectory

vendor/etc/sysconfig/ 
vendor/etc/permissions/

我的机器没有vendor/etc/sysconfig/路径
Z50:/vendor/etc/permissions # ls
ls
android.hardware.audio.low_latency.xml
android.hardware.bluetooth.xml
android.hardware.bluetooth_le.xml
android.hardware.camera.xml
android.hardware.faketouch.xml
android.hardware.location.gps.xml
android.hardware.microphone.xml
android.hardware.sensor.accelerometer.xml
android.hardware.sensor.light.xml
android.hardware.sensor.proximity.xml
android.hardware.telephony.gsm.xml
android.hardware.touchscreen.multitouch.distinct.xml
android.hardware.touchscreen.multitouch.jazzhand.xml
android.hardware.touchscreen.multitouch.xml
android.hardware.touchscreen.xml
android.hardware.usb.accessory.xml
android.hardware.usb.host.xml
android.hardware.wifi.direct.xml
android.hardware.wifi.xml
android.software.live_wallpaper.xml
android.software.midi.xml
handheld_core_hardware.xml
pms_sysapp_removable_vendor_list.txt
  • 3.OdmDirectory

odm/etc/sysconfig/ 
odm/etc/permissions/

很可惜,都没有,这里主要给ODM自己建立对应文件夹进行配置
2|Z50:/ # ls
ls
acct       data             init.preload.rc      nvdata    sdcard
bugreports default.prop     init.rc              oem       storage
cache      dev              init.usb.configfs.rc proc      sys
charger    etc              init.usb.rc          protect_f system
config     fstab.enableswap init.zygote32.rc     protect_s ueventd.rc
custom     init             mnt                  root      vendor
d          init.environ.rc  nvcfg                sbin
  • 3.oemDirectory

oem/etc/sysconfig/ 
oem/etc/permissions/

没有具体文件
Z50:/oem # ls
ls
  • 具体文件

具体源码

    void readPermissions(File libraryDir, int permissionFlag) {// Read permissions from given directory.if (!libraryDir.exists() || !libraryDir.isDirectory()) {if (permissionFlag == ALLOW_ALL) {Slog.w(TAG, "No directory " + libraryDir + ", skipping");}return;}if (!libraryDir.canRead()) {Slog.w(TAG, "Directory " + libraryDir + " cannot be read");return;}// Iterate over the files in the directory and scan .xml filesFile platformFile = null;for (File f : libraryDir.listFiles()) {// We'll read platform.xml last// 这个文件最后会读的if (f.getPath().endsWith("etc/permissions/platform.xml")) {platformFile = f;continue;}if (!f.getPath().endsWith(".xml")) {Slog.i(TAG, "Non-xml file " + f + " in " + libraryDir + " directory, ignoring");continue;}if (!f.canRead()) {Slog.w(TAG, "Permissions library file " + f + " cannot be read");continue;}readPermissionsFromXml(f, permissionFlag);}// Read platform permissions last so it will take precedence// 我就是最后if (platformFile != null) {readPermissionsFromXml(platformFile, permissionFlag);}}
  • 接下来很明显就是读取各种XML了
private void readPermissionsFromXml(File permFile, int permissionFlag) {
我们重点关注下面的即可
...} else if ("allow-in-power-save-except-idle".equals(name) && allowAll) {String pkgname = parser.getAttributeValue(null, "package");if (pkgname == null) {Slog.w(TAG, "<allow-in-power-save-except-idle> without package in "+ permFile + " at " + parser.getPositionDescription());} else {mAllowInPowerSaveExceptIdle.add(pkgname);}XmlUtils.skipCurrentTag(parser);continue;} else if ("allow-in-power-save".equals(name) && allowAll) {String pkgname = parser.getAttributeValue(null, "package");if (pkgname == null) {Slog.w(TAG, "<allow-in-power-save> without package in " + permFile + " at "+ parser.getPositionDescription());} else {mAllowInPowerSave.add(pkgname);}XmlUtils.skipCurrentTag(parser);continue;
...
  • 取出白名单

手机路径 /etc/permissions/platform.xml

对应源代码路径如下

    <!-- These are the standard packages that are white-listed to always have internetaccess while in power save mode, even if they aren't in the foreground. --><allow-in-power-save package="com.android.providers.downloads" /><!-- This is a core platform component that needs to freely run in the background --><allow-in-power-save package="com.android.cellbroadcastreceiver" /><allow-in-power-save package="com.android.shell" />
  • 系统源码路径 frameworks\base\data\etc\platform.xml
当然内容是一样的啦<!-- These are the standard packages that are white-listed to always have internetaccess while in power save mode, even if they aren't in the foreground. --><allow-in-power-save package="com.android.providers.downloads" /><!-- This is a core platform component that needs to freely run in the background --><allow-in-power-save package="com.android.cellbroadcastreceiver" /><allow-in-power-save package="com.android.shell" />
  • 手机路径 /vendor/etc/permissions/抱歉这里没有

系统源码路径 vendor\mediatek\proprietary\frameworks\base\data\etc\抱歉这里也没有,需要自行配置

系统源码路径 \vendor\partner_gms\etc\sysconfig\google.xml

这里是亲爱的Gms包设置Line 23:     <allow-in-power-save package="com.google.android.gms" />Line 28:     <allow-in-power-save-except-idle package="com.google.android.apps.work.oobconfig" />Line 41:     <allow-in-power-save-except-idle package="com.android.vending" />Line 44:     <allow-in-power-save package="com.google.android.volta" />Line 48:     <allow-in-power-save package="com.google.android.ims" />
  • 软件接口设置
    // Doze 模式新增白名单public void addApp(String pkg) {try {mDeviceIdleService.addPowerSaveWhitelistApp(pkg);mWhitelistedApps.add(pkg);} catch (RemoteException e) {Log.w(TAG, "Unable to reach IDeviceIdleController", e);}}// Doze 模式移除白名单public void removeApp(String pkg) {try {mDeviceIdleService.removePowerSaveWhitelistApp(pkg);mWhitelistedApps.remove(pkg);} catch (RemoteException e) {Log.w(TAG, "Unable to reach IDeviceIdleController", e);}}
  • 具体工具类如下
/** Copyright (C) 2015 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/
package com.android.lava.powersave.util;import android.os.IDeviceIdleController;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.ArraySet;
import android.util.Log;/*** Handles getting/changing the whitelist for the exceptions to battery saving features.*/
public class PowerWhitelistBackend {private static final String TAG = "WhitelistBackend";private static final String DEVICE_IDLE_SERVICE = "deviceidle";private static final PowerWhitelistBackend INSTANCE = new PowerWhitelistBackend();private final IDeviceIdleController mDeviceIdleService;private final ArraySet<String> mWhitelistedApps = new ArraySet<>();private final ArraySet<String> mSysWhitelistedApps = new ArraySet<>();public PowerWhitelistBackend() {mDeviceIdleService = IDeviceIdleController.Stub.asInterface(ServiceManager.getService(DEVICE_IDLE_SERVICE));refreshList();}public int getWhitelistSize() {return mWhitelistedApps.size();}public boolean isSysWhitelisted(String pkg) {return mSysWhitelistedApps.contains(pkg);}public boolean isWhitelisted(String pkg) {return mWhitelistedApps.contains(pkg);}public void addApp(String pkg) {try {mDeviceIdleService.addPowerSaveWhitelistApp(pkg);mWhitelistedApps.add(pkg);} catch (RemoteException e) {Log.w(TAG, "Unable to reach IDeviceIdleController", e);}}public void removeApp(String pkg) {try {mDeviceIdleService.removePowerSaveWhitelistApp(pkg);mWhitelistedApps.remove(pkg);} catch (RemoteException e) {Log.w(TAG, "Unable to reach IDeviceIdleController", e);}}private void refreshList() {mSysWhitelistedApps.clear();mWhitelistedApps.clear();try {String[] whitelistedApps = mDeviceIdleService.getFullPowerWhitelist();for (String app : whitelistedApps) {mWhitelistedApps.add(app);}String[] sysWhitelistedApps = mDeviceIdleService.getSystemPowerWhitelist();for (String app : sysWhitelistedApps) {mSysWhitelistedApps.add(app);}} catch (RemoteException e) {Log.w(TAG, "Unable to reach IDeviceIdleController", e);}}public static PowerWhitelistBackend getInstance() {return INSTANCE;}}
  • 软件接口的配置也会体现这这个路径下

data/system/deviceidle.xml

Z50:/data/system # cat deviceidle.xml
cat deviceidle.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<config>
<wl n="com.google.android.apps.maps" />
<wl n="com.google.android.gsf" />
</config>
  • 具体相关源码
 public final AtomicFile mConfigFile;public DeviceIdleController(Context context) {super(context);mConfigFile = new AtomicFile(new File(getSystemDir(), "deviceidle.xml"));mHandler = new MyHandler(BackgroundThread.getHandler().getLooper());}
  • 总结

Doze模式的白名单我们可以预设置还可以进行软件接口调用。 
1.主要预设置在 
frameworks\base\data\etc\platform.xml 
随着Android O 的代码控制雄心,以后路径可能需要厂商自己定义 
vendor\mediatek\proprietary\frameworks\base\data\etc\platform.xml

2.不要忘记GMS包里面也可以配置的 
\vendor\partner_gms\etc\sysconfig\google.xml

3.接口调用同样Google提供给我们了,使用起来同样简单粗暴,查看设置结果 data/system/deviceidle.xml

Android 8.0学习(16)---8.0 的Doze模式白名单路径相关推荐

  1. Android O 的Doze模式白名单路径

    Doze 模式列表 上述备注规则如下 if(powerWhitelist.isSysWhitelisted(pkg)) {// Summary of app which doesn't have a ...

  2. Android之monkey Test,Monkey测试中的黑名单和白名单,Monkey测试中的黑名单和白名单

    一.Monkey简介 Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行 ...

  3. 【Android 电量优化】电量优化特性 ( Doze 低电耗模式 | Standby 应用待机模式 | 白名单设置 | 白名单添加系统设置界面 | 指定应用的白名单添加界面 | 测试应用 )

    文章目录 一.Doze 低耗电模式简介 二.Standby 应用待机模式简介 三.Doze 和 Standby 模式测试 四.白名单添加 ( 方式一 ) 五.白名单添加 ( 方式二 ) Android ...

  4. Android每周一个学习计划——RxJava2 0的学习使用

    序言:蜗壳已经退役一年多了,但是还是抵不住蜗壳在NBA界的影响力,最近NBA流行向"蜗壳挑战",事情起源于蜗壳给IT和北境之王设定了新赛季的挑战,然后众多球星也纷纷向蜗壳讨要挑战. ...

  5. TensorFlow2.0学习笔记2-tf2.0两种方式搭建神经网络

    目录 一,TensorFlow2.0搭建神经网络八股 1)import  [引入相关模块] 2)train,test  [告知喂入网络的训练集测试集以及相应的标签] 3)model=tf.keras. ...

  6. Exchange13/16启用垃圾邮件功能及白名单设置

    1. 以管理员权限运行exchange的powershell 2 .启用反垃圾邮件功能 X\:ExchangeInstallPath\Scripts\Install-AntiSpamAgents.ps ...

  7. oauth2.0 php简化模式,OAuth2.0学习(1-5)授权方式2-简化模式(implicit grant type)

    授权方式2-简化模式(implicit grant type) 简化模式(implicit grant type)不通过第三方应用程序的服务器,直接在浏览器中向认证服务器申请令牌,跳过了"授 ...

  8. Android Doze模式和app Standby模式

    对低电耗模式(app Standby)和应用待机模式(Doze)进行针对性优化 从 Android 6.0(API 级别 23)开始,Android 引入了两个省电功能,可通过管理应用在设备未连接至电 ...

  9. Android的Doze模式

    也是偶然之间听到这个词的 Doze模式 Doze模式 Doze 翻译为打盹, 那么Android的Doze模式呢 , 就是让手机进入了类似打盹的一个状态 , 在这个半梦半醒的状态下 , 手机的后台.服 ...

最新文章

  1. RocketMQ生产者流程篇
  2. ext中给文本框赋值的方法_大多数人不知道的Python合并字典的七种方法
  3. DELL N系列交换机/N3048交换机SSH配置
  4. php 某一天时间凌晨,PHP获得今天 天凌晨时间戳的例子
  5. hdu 4640(状压dp)
  6. 在CentOS6.x下安装Compiz——桌面立方体,特效种种
  7. (转)RabbitMQ学习之安装
  8. CLRInjection - 通用托管注入(超级灰色按钮克星升级版)
  9. 庄子(公元前369年-公元前286年)
  10. php百度编辑器demo,百度编辑器 Laravel Ueditor | 码农软件 - 码农网
  11. 百篇已过,又是一个新篇章,谈谈感受吧
  12. android使用google gcm接收push消息需要注意的地方
  13. cmd下获取指定进程名的pid号,并通过taskkill结束该进程
  14. 如何用计算机名称获取计算机ip
  15. SQL Server2019配置管理器无法连接到 WMI 提供程序
  16. excel 求去掉最高分最低分后的平均值
  17. Mac系统鼠标在移动时,指针变的很大,是什么鬼?
  18. 让我们一起奔跑,去追求卓越而不是平庸一生!
  19. 21考研 为啥看了那么多经验贴,还是搞不定考研?
  20. A4格式pdf转B5打印解决

热门文章

  1. mpeg4视频中,I帧、p帧、B帧的判定
  2. struts和struts2-面试题
  3. apache 设置缓存
  4. 深入浅出话VC++(2)——MFC的本质
  5. Oracle意外赢官司,程序员或过苦日子
  6. 安装 RabbitMQ
  7. centos 搭建web平台
  8. Linux shell - 按时间和文件大小排序显示文件(ll)
  9. artdialog4.1.7 中父页面给子页面传值
  10. Compilation Error 解决方案汇集