华为EMUI 9.0.0.187(C00E57R1P15) 无该功能
华为EMUI 9.1.0.321(C00E320R1P1) 之后有sensor管控
一、华为 Sensor 省电策略
1. Sensor 类别只配置非唤醒类Sensor
2. 手机静止情况,应用不可见时达到1分钟,则禁止应用使用Sensor
3. 应用被识别计步场景时,使用SENSOR_DELAY_UI或SENSOR_DELAY_NORMAL采样,则允许不可见时使用Sensor
4. 应用被识别计步场景时,使用SENSOR_DELAY_GAME或SENSOR_DELAY_FASTEST采样,则禁止不可见时使用Sensor
5. 一旦处于可见状态,立刻恢复Sensor的正常使用
二、华为 Sensor 省电现象
自己写一个Sensor Demo PhoneData.apk进行调研,主要功能点:
1. 持 PARTIAL_WAKE_LOCK
2. 不停监听Sensor数据变化
机器 | PhoneData.apk 使用 non wake-up sensor 采集数据 |
华为 | 1.亮屏+应用可见,有数据; 2. 亮屏+应用不可见+1分钟内,无数据; 3. 灭屏+应用不可见+1分钟内,无数据; 4. 亮屏+应用不可见+不停摇一摇+SENSOR_DELAY_FASTEST,无数据 5. 灭屏+应用不可见+不停摇一摇+SENSOR_DELAY_FASTEST,无数据 6. 亮屏+应用不可见+不停摇一摇+SENSOR_DELAY_GAME,无数据 7. 灭屏+应用不可见+不停摇一摇+SENSOR_DELAY_GAME,无数据 8. 亮屏+应用不可见+不停摇一摇+SENSOR_DELAY_UI ,有数据 9. 灭屏+应用不可见+不停摇一摇+SENSOR_DELAY_UI ,有数据 10. 亮屏+应用不可见+不停摇一摇+SENSOR_DELAY_NORMAL,有数据,一旦检测为计步应用,即使静止也有数据 11. 灭屏+应用不可见+不停摇一摇+SENSOR_DELAY_NORMAL,有数据,,一旦检测为计步应用,即使静止也有数据 |
TOne | 1.亮屏+应用可见,有数据 2.亮屏+后台+至少10分钟以上,有数据 3.灭屏+后台+至少10分钟以上,有数据 |
上述发现如下:
华为 | 只有非唤醒类Sensor | 不可见+静止 禁止使用Sensor | 采样率为SENSOR_DELAY_UI或SENSOR_DELAY_NORMAL,且被识别为计步,则允许使用Sensor,否则禁止 |
TOne | 唤醒类Sensor 非唤醒类Sensor | 没有限制 | 没有限制 |
三、Sensor 省电的详细分析
1、 Sensor 列表区别
1.1 华为
SensorType: 1, Name: accelerometer-lsm6dsm, Description: {Sensor name="accelerometer-lsm6dsm", vendor="st", version=1, type=1, maxRange=78.4532, resolution=9.576806E-6, power=0.23, minDelay=2000}
只有非唤醒类Sensor,代码中使用SensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER, true/*表示唤醒类*/),会没有任何数据输出
1.2 TOne
SensorType: 1, Name: lsm6ds3c Accelerometer Wakeup, Description: {Sensor name="lsm6ds3c Accelerometer Wakeup", vendor="STMicro", version=140549, type=1, maxRange=78.4532, resolution=0.0023928226, power=0.15, minDelay=2404}
SensorType: 1, Name: lsm6ds3c Accelerometer Non-wakeup, Description: {Sensor name="lsm6ds3c Accelerometer Non-wakeup", vendor="STMicro", version=140549, type=1, maxRange=78.4532, resolution=0.0023928226, power=0.15, minDelay=2404}
2、华为-不可见+静止,则禁止使用Sensor
// 非重要通知识别
2019-08-14 13:30:25.376 2134-2458/? I/hibernation: com.xiaomi.hm.health skips not important notification
// 拦截com.xiaomi.hm.health使用Sensor
2019-08-14 13:30:25.376 2134-2458/? I/APwPowerPolicy: ignore sensor about not never opt app: com.xiaomi.hm.health
// 冻结 com.xiaomi.hm.health
2019-08-14 13:30:25.398 2134-2458/? I/hibernation: Freeze com.xiaomi.hm.health OK !
2019-08-14 13:30:25.404 2134-2458/? I/hibernation: close sockets >> com.xiaomi.hm.health, uids : [10311]
// 统计 com.xiaomi.hm.health,sensor: 0.09mAh, time: 527s
2019-08-14 13:30:25.855 2134-2247/? I/APwFeedback3: delta rank, uid: 10311, name: com.xiaomi.hm.health, current: 5mA, total: 0.17mAh. [cpu: 0.08mAh, time: 4s], [sensor: 0.09mAh, time: 527s]
// 识别无声音、无计步行为
2019-08-14 13:30:25.868 2134-2247/? I/AppActAnalyzer: Pedometer pkg: com.xiaomi.hm.health, big current: 5, recent no sound, count step
3、SENSOR_DELAY_GAME或SENSOR_DELAY_FASTEST,即使计步,也禁止使用Sensor
5 /**
56 * Typical sensor delay (sample period) in microseconds.
57 */
58 // Fastest sampling, system will bound it to minDelay
59 static constexpr int32_t SENSOR_DELAY_FASTEST = 0;
60 // Typical sample period for game, 50Hz; 即1秒中打印50次,Sensor数据变化
61 static constexpr int32_t SENSOR_DELAY_GAME = 20000;
62 // Typical sample period for UI, 15Hz ; 即1秒中打印15次,Sensor数据变化
63 static constexpr int32_t SENSOR_DELAY_UI = 66667;
64 // Default sensor sample period,即1秒中打印5次,Sensor数据变化
65 static constexpr int32_t SENSOR_DELAY_NORMAL = 200000;
相关日志如下:
// sensor: 0.06mAh, time: 344s
2019-08-14 13:46:27.092 2134-2247/? I/APwFeedback5: delta rank, uid: 10309, name: com.fadi.phonedata, current: 7mA, total: 0.24mAh. [cpu: 0.18mAh, time: 9s], [sensor: 0.06mAh, time: 344s]
//被识别为高耗电应用:常驻通知属性,华为日志太少,实测app确实无法监听Sensor数据了
2019-08-14 13:46:27.105 2134-2247/? I/AppHighCurrentAnalyzer: has persist notification, add 5 threashold, pkg: com.fadi.phonedata
4、应用可见时恢复使用Sensor
// 可见时恢复
2019-08-14 13:58:55.094 2134-2458/? I/ash_trans: com.fadi.phonedata { hibernation duration=86168 Uptime=86168 } transition to: running reason:visible
2019-08-14 13:58:55.098 2134-2247/? I/AppsUsage: scnOff:false FgAPP:com.fadi.phonedata BgAPP:com.huawei.android.launcher
2019-08-14 13:58:55.114 2134-2458/? I/PGServer: report state:6 event type:2 pid:0 uid:10309 pkg:com.fadi.phonedata to pid: 1252
2019-08-14 13:58:55.114 2134-2458/? I/hibernation: Unfreeze com.fadi.phonedata OK !
2019-08-14 13:58:55.115 1252-2796/? I/PGManagerService: proxyBroadcast:[com.fadi.phonedata] proxy:false
2019-08-14 13:58:55.167 2134-2458/? I/hibernation: unproxy com.fadi.phonedata broadcast OK !
2019-08-14 13:58:55.169 2134-2458/? I/hibernation: Unpending com.fadi.phonedata alarm OK !
2019-08-14 13:58:55.197 2134-2458/? I/hibernation: unproxy gps:com.fadi.phonedata,uid:10309,result:true
2019-08-14 13:58:55.198 2134-2458/? I/hibernation: above launcher front pkgs: [com.fadi.phonedata]