一、性能改进
1.Doze模式的优化
在安卓6.0中,安卓引入了新的省电机制Doze,当时针对的场景只是当手机同时处于灭屏以及静止状态来减少应用对电量的消耗。但是在实际使用中手机灭屏时不仅仅是处于静止状态,还有很多情况下是处于运动状态的,例如步行,坐车,坐飞机等情况,这时Doze就不会生效。比如你出门在外把手机放在裤子口袋,若是Android 6.0的Doze则会认为用户还可能会使用设备而不启动后台省电管理机制。然而Android N在此基础上更近了一步,将Doze分成多个层次.
When a device is on battery power, and the screen has been off for a certain time, the device enters Doze and applies the first subset of restrictions: It shuts off app network access, and defers jobs and syncs. If the device is stationary for a certain time after entering Doze, the system applies the rest of the Doze restrictions toPowerManager.WakeLock
, AlarmManager
alarms, GPS, and Wi-Fi scans. Regardless of whether some or all Doze restrictions are being applied, the system wakes the device for brief maintenance windows, during which applications are allowed network access and can execute any deferred jobs/syncs.
从这段文字可以看出。
Android 对于Doze在原来的基础上变得更加严格。
当一个设备使用电池供电,屏幕关闭一段时间后,就会进入Doze。这一点上跟原来6.0机制一样。进入Doze后,将关掉应用网络访问能力同时延期一些系统工作与同步任务。
当设备进入Doze一段时间并持续保持静止时,进入途中第三阶段的Doze,系统将限制PowerManager.WakeLock
, AlarmManager
alarms, GPS, and Wi-Fi scans这些功能的使用。
(在Android 6.0中,AlarmManager新增了setAndAllowWhileIdle()
and setExactAndAllowWhileIdle()
方法,如果你的app需要在Doze下用AlarmManger设置alarm做点什么,如唤起进程等,可以改用这两个方法,这两个方法设置的Alarms在系统处于Doze也能起作用。)
但是从图中可以看出,每隔一段时间,系统会周期性地唤起一个 brief maintenance 窗口,在唤起窗口的这段时间,应用将被允许联网和执行其他活动。在这个窗口结束之后,设备将再次进入Doze。随着时间的增长,系统唤起maintenance windows的频率将越来越低。
更详细的Doze解释可以查看官方文档Optimizing for Doze and App Standby
2.项目瘦身:后台的优化
ACTION_NEW_PICTURE
and
ACTION_NEW_VIDEO
这三个广播。
ACTION_NEW_PICTURE
and
ACTION_NEW_VIDEO
这两个广播,用户用照相机拍一张照片,这些广播被监听也将导致apps被唤起。
To alleviate these issues, Android N applies the following optimizations:
- Apps targeting Android N do not receive
CONNECTIVITY_ACTION
broadcasts, even if they have manifest entries to request notification of these events. Apps running in the foreground can still listen forCONNECTIVITY_CHANGE
on their main thread if they request notification with aBroadcastReceiver
. - Apps cannot send or receive
ACTION_NEW_PICTURE
orACTION_NEW_VIDEO
broadcasts. This optimization affects all apps, not only those targeting Android N.
二、权限更改
1.弃用了GET_ACCOUNTS权限。
2.文件系统权限变更
MODE_WORLD_READABLE
and/or
MODE_WORLD_WRITEABLE
来修改文件权限,将会抛出SecurityException;