问题描述
好日子,
情况:
我正在开发Android应用程序,用作体育追踪器/导航应用程序 - 因此它需要与GPS永久连接,也是永久清醒的设备。录音每秒完成。
多年来一直工作的解决方案是感谢 wakelocks
让设备保持清醒状态。
Android 6.0以上的打盹模式使情况复杂化,但并非如此。
在华为设备上可能有所不同类型的优化。
以下是log的一部分:
10-10 10 :33:18.462 1014-384 D / PFW.HwPFWAppWakeLockPolicy:getUidWakeLock uid:10097 wakelock> = 10分钟
10-10 10:33:18.543 1014-384 D / PFW.HwPFWAppWakeLockPolicy:强制停止异常唤醒锁定app uid :10097
10-10 10:33:18.558 1014-384 I / ActivityManager:强制停止menion.android.locus appid = 10097 user = 0:来自pid 1014
因此, 30分钟以上,系统只是简单地决定应用程序使用太多 wakelocks
,并用所有服务,历史记录完全终止它,只需 kill
。
有这种行为和任何建议的任何经验,如何更简单的任务(当屏幕关闭时永久记录GPS位置)更好?
$ b
正如我在开始时所写的,除了新的华为以外的其他所有设备,这样的系统多年来都运行正常。
编辑:华为电池管理器中的一个用户(已删除?),白名单应用的注释(标记为受保护的应用)对此问题没有影响。
com.huawei.systemmanager
)会终止屏幕关闭后仍在运行的所有应用程序,除非它们位于受保护的应用程序列表中。 com.hu awei.powergenie
)会杀死所有持有唤醒锁的应用。听起来像是你的应用程序正在被PowerGenie杀死。您可以通过利用PowerGenie的唤醒锁标记的硬编码白名单来避免这种情况。例如,如果您的唤醒锁的标签是LocationManagerService,它将被PowerGenie忽略,因为系统服务使用相同标签持有唤醒锁,并且PowerGenie已将其列入白名单。
Good day,situation:
I'm developing Android application that serve as sport tracker/navigation app - so it require permanent connection to GPS and also permanent awake device. Recording is done every second.
Current solution working for years is thanks to wakelocks
that keep device awake.
Doze mode in Android 6.0+ complicate situation, but it is not this case.
On Huawei device is probably different type of optimization.
Here is part of log:
10-10 10:33:18.462 1014-384 D/PFW.HwPFWAppWakeLockPolicy: getUidWakeLock uid: 10097 wakelock >= 10 mins10-10 10:33:18.543 1014-384 D/PFW.HwPFWAppWakeLockPolicy: force stop abnormal wakelock app uid: 1009710-10 10:33:18.558 1014-384 I/ActivityManager: Force stopping menion.android.locus appid=10097 user=0: from pid 1014
So after approx. 30+ minutes, system simply decide that app use too much wakelocks
and terminate it completely with all services, history, simply kill
.
Any experience with this behavior and any suggestion, how to this simple task (permanent recording of GPS location when screen is off) better?
As I wrote at start, on all other devices except new Huawei, such system works correctly for many years.
EDIT: note after comment of one user (deleted?), "whitelist" app in Huawei battery manager (mark as "protected application") has no effect on this problem.
There are two Huawei system apps that may kill user apps to save battery:
- SystemManager (
com.huawei.systemmanager
) kills any apps that are still running after the screen is turned off, unless they're in the "Protected Apps" list. - PowerGenie (
com.huawei.powergenie
) kills any apps that hold wake locks for a long time.
It sounds like your app is being killed by PowerGenie. You can avoid this by taking advantage of PowerGenie's hardcoded whitelist of wake lock tags. For example, if your wake lock's tag is "LocationManagerService" it will be ignored by PowerGenie, because a system service holds a wake lock with the same tag and PowerGenie has whitelisted it.
这篇关于华为EMUI 4.0+电池优化(wakelocks)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!