Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
655 views
in Technique[技术] by (71.8m points)

android - Battery optimizations (wakelocks) on Huawei EMUI 4.0+

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 mins 10-10 10:33:18.543 1014-384 D/PFW.HwPFWAppWakeLockPolicy: force stop abnormal wakelock app uid: 10097 10-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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...