Looking for Activity to disable "Deep battery optimization"

Post your questions and help other users.

Moderator: Martin

Post Reply
lm089
Posts: 12
Joined: 22 Mar 2019 10:07

Looking for Activity to disable "Deep battery optimization"

Post by lm089 » 06 Apr 2019 22:37

For my oneplus 6 / running on Pie I'm looking for a way to disable "Settings >> battery >> battery optimization >> advanced optimization >> deep optimization", then start an app. Or even better: disable that setting upon starting the app. But first things first.

Been looking at "Set system setting", but have to admit that I'm completely lost with the choice of settings available.
Can this be accomplished somehow?
OnePlus 6 (root, Stock Android Pie / OOS 9.x)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Looking for Activity to disable "Deep battery optimizati

Post by Desmanto » 07 Apr 2019 13:48

Why would you do that? If the app is started, doze/any optimization shouldn't be able to force it to sleep. So disabling it will be redundant. Except, what you mean is if you start the app using Automagic flow shortcut, you want the app stay not battery optimized until you decided to enable the battery optimization again for that app. In that case, I can't find a method to disable/enable the battery optimization for certain app. There is java method, but only to query the status. I think, the only possible way now is to use Control UI, navigate to the battery optimization and disable/enable it accordingly.

Battery optimization is not stored in system setting/database, so it won't help. It seems to be stored in some files in /data/system/, which require root to access it.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

lm089
Posts: 12
Joined: 22 Mar 2019 10:07

Re: Looking for Activity to disable "Deep battery optimizati

Post by lm089 » 08 Apr 2019 07:53

OK, if it can't be done I'll have to stick to doing it manually. Was just an idea
Desmanto wrote:Why would you do that?
For outdoor activities I'm using OruxMaps to record my own tracks. The app never had a problem to keep recording until I got my OnePlus 6 running Pie and I found that "Deep optimization" is indeed helping me get longer battery hours. But with this enabled Orux stops recording approx. 10 minutes after the phone goes into standby mode. Disabling deep optimization Orux keeps working as expected.

Thanks for your ideas; as the phone is rooted I'll have a look into that.
OnePlus 6 (root, Stock Android Pie / OOS 9.x)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Looking for Activity to disable "Deep battery optimizati

Post by Desmanto » 08 Apr 2019 10:31

I have tried to find the file corresponding to the battery optimization. Found it at /data/system/deviceidle.xml

Code: Select all

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<config>
<wl n="com.whatsapp" />
<wl n="com.mixplorer.silver" />
<wl n="com.goodmooddroid.gesturecontrol" />
<wl n="com.android.chrome" />
<wl n="nl.jolanrensen.hotwordPluginFree" />
<wl n="vocalizer_e2.tts" />
</config>
This is the example of the content at mine. I have whitelisted some, including Automagic. But somehow Automagic is not shown here, probably because it is running foreground service.

You can try to find using MiXplorer. Install MiXplorer from xda, grant it root. Go to /data/system, change the sort to Date (newer). Then change the view to Detailed (so you can see modification date). Go to your setting, change OruxMaps to don't optimize. Then go back to MiXplorer, refresh and see what is the file that is the top most one, which has the modification time "Just now".

Yours probably can be different file, as Oneplus has different optimization system. Mine is RN5, RR 7.0.1 Pie 9.0 ROM, which is based on LineageOS.

================
But after a furious search, I have found the terminal command to change it (yay, thanks to your question :D). Use dumpsys deviceidle
Found it here : https://android.stackexchange.com/quest ... -from-doze
As you have root already, you can use it directly from action Execute Root Command

To list all whitelisted app

Code: Select all

dumpsys deviceidle whitelist | grep user
To add OruxMaps to the whitelist

Code: Select all

dumpsys deviceidle whitelist +com.orux.oruxmapsDonate
To remove it from whitelist, just change + to -

Code: Select all

dumpsys deviceidle whitelist -com.orux.oruxmapsDonate
However the UI won't show up properly until next reboot (or system UI reboot). So, if you go to the battery optimization, it still shows as optimized, although dumpsys already show it is whitelisted.

This is for standard AOSP. Oneplus might implement their own method. And if that is the case, unfortunately you have to find it by yourself.

Your flow will contain shortcut to start OruxMaps and add it to whitelist. After finish, use the shortcut again to remove it from whitelist, so your battery can last longer.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

lm089
Posts: 12
Joined: 22 Mar 2019 10:07

Re: Looking for Activity to disable "Deep battery optimizati

Post by lm089 » 08 Apr 2019 16:44

Wow, I'm deeply impressed! Many thanks for the effort.
Will try that over next weekend, then report back. This week will be very busy for me
OnePlus 6 (root, Stock Android Pie / OOS 9.x)

lm089
Posts: 12
Joined: 22 Mar 2019 10:07

Re: Looking for Activity to disable "Deep battery optimizati

Post by lm089 » 09 Apr 2019 07:28

Couldn't halp it, simply had to test it last night.
Desmanto wrote: But after a furious search, I have found the terminal command to change it (yay, thanks to your question :D). Use dumpsys deviceidle
Found it here : https://android.stackexchange.com/quest ... -from-doze
As you have root already, you can use it directly from action Execute Root Command

To list all whitelisted app

Code: Select all

dumpsys deviceidle whitelist | grep user
To add OruxMaps to the whitelist

Code: Select all

dumpsys deviceidle whitelist +com.orux.oruxmapsDonate
To remove it from whitelist, just change + to -

Code: Select all

dumpsys deviceidle whitelist -com.orux.oruxmapsDonate
However the UI won't show up properly until next reboot (or system UI reboot). So, if you go to the battery optimization, it still shows as optimized, although dumpsys already show it is whitelisted.

This is for standard AOSP. Oneplus might implement their own method. And if that is the case, unfortunately you have to find it by yourself.

Your flow will contain shortcut to start OruxMaps and add it to whitelist. After finish, use the shortcut again to remove it from whitelist, so your battery can last longer.
Looked at "deviceidle.xml" and performed a dumpsys. Both showed me that Oruxmaps already is whitelisted on my device. So apparently my OP6 has yet another, more aggressive optimization mode which probably doesn't exist in other Pie ROMs (or does it?): in the standard battery optimization page there's an option called something like "Enhanced Optimization" ("Erweiterte Optimierung" in German). Here I have 2 additional options called "Deep Optimization" and "Optimization for Sleep / Standby Mode" ("Optimierung für Ruhe-/Standby-Modus"). If I enable "Deep Optimization" then obviously whitelisting a user app is not sufficient.
Desmanto wrote:You can try to find using MiXplorer. Install MiXplorer from xda, grant it root. Go to /data/system, change the sort to Date (newer). Then change the view to Detailed (so you can see modification date). Go to your setting, change OruxMaps to don't optimize. Then go back to MiXplorer, refresh and see what is the file that is the top most one, which has the modification time "Just now".
I'll have a look at MiXplorer; probably it can help me find out more about that extra aggressive setting.

Thanks anyways
OnePlus 6 (root, Stock Android Pie / OOS 9.x)

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Looking for Activity to disable "Deep battery optimizati

Post by Desmanto » 10 Apr 2019 06:27

MIUI also has the similar function call MIUI Optimization. And the first thing I do when I get any Xiaomi Phones is to disable this. It has done more harm than good. And I have tested, disabling the optimization doesn't increase battery drain, either Screen on Time or standby drain. I can still get similar or even better SOT/Idle than my friends who enable this.

I recommend to just disable them and only use built-in Android battery optimization. Any custom optimization from any vendor typically do more harm. Look at oneplus here : https://dontkillmyapp.com/oneplus But Built-in android optimization has real effect for some apps, especially the ones which are not optimized. OruxMap maybe one of those, you can try to leave it whitelisted all the time vs toggling the whitelist using Automagic. But if the app is well optimized just like Automagic or MiXplorer, even leaving it running foreground the whole time, it only add a very small additional drain.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

lm089
Posts: 12
Joined: 22 Mar 2019 10:07

Re: Looking for Activity to disable "Deep battery optimizati

Post by lm089 » 10 Apr 2019 08:44

Desmanto wrote:MIUI also has the similar function call MIUI Optimization. And the first thing I do when I get any Xiaomi Phones is to disable this. It has done more harm than good. And I have tested, disabling the optimization doesn't increase battery drain, either Screen on Time or standby drain. I can still get similar or even better SOT/Idle than my friends who enable this.

I recommend to just disable them and only use built-in Android battery optimization. Any custom optimization from any vendor typically do more harm. Look at oneplus here : https://dontkillmyapp.com/oneplus But Built-in android optimization has real effect for some apps, especially the ones which are not optimized. OruxMap maybe one of those, you can try to leave it whitelisted all the time vs toggling the whitelist using Automagic. But if the app is well optimized just like Automagic or MiXplorer, even leaving it running foreground the whole time, it only add a very small additional drain.
Once again, many thanks for your extremely helpful response! In fact I bought my OnePlus only recently, one of the reasons for this decision was that those devices usually are described as being very close to stock android. :o
Indeed I had already seen that the whitelisting of oruxmaps had been reset after rebooting the device; as I rarely reboot it, and in addition Oruxmaps is warning me upon startup if it's not whitelisted I didn't care too much.
But this may also help automagic running more reliably
OnePlus 6 (root, Stock Android Pie / OOS 9.x)

Post Reply