Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with Huawei's and Xiaomi's "battery optimizations"

I have an app that listens for notifications via NotificationListenerService. My app survives both the Doze mode and app stand by on almost any phone (if properly set-up e.g. exception or a foreground service).

Then come the Huawei and Xiaomi with their own modifications of Android to "improve battery life". These can mess with background running apps so badly that after a week or two the app must be reinstalled. Even clearing data will not "unfreeze" the app. Even exceptions to their own "optimizations" does not reliably fix this. Only completely disabling all their optimizations e.g. enabling "high performance mode" might fix this. But users do not want to disable these options.

How do you deal with these cases? And how can we stop manufacturers to stop messing with core Android? Not to mention the funny ANRs & crashes in Zygote :(

like image 337
shelll Avatar asked Nov 06 '17 21:11

shelll


1 Answers

Then come the Huawei and Xiaomi with their own modifications of Android to "improve battery life".

Yes Xiaomi, Huawei and a few other manufacturers have their own layer of "Battery Saver" or "Security" that kills or restricts background running apps in order to improve security/battery backup, unless user white-lists your app in the relevant device settings.

What i found out about Xiaomi is that they white-list well known apps like Facebook, Whatsapp, etc. But you cannot request Xiaomi to white-list your app.

These can mess with background running apps so badly that after a week or two the app must be reinstalled. Even clearing data will not "unfreeze" the app.

These manufacturer apps simply terminate your app process. So your app should behave in such a way that termination at any moment should not create inconsistent state.

Also, you can always show a popup to user after installation asking him/her to go and white-list your app in battery saver. In Xiaomi, the user will need to select 'Do not restrict background activity' and also enable 'Auto Start' for your app. As far as i know, there is no other solution.

Let me know if you find one ;)

Xiaomi app auto start settings screen Xiaomi app battery saver settings screen

like image 148
Prasad Pawar Avatar answered Oct 01 '22 23:10

Prasad Pawar