[Tutorial] Battery drain & lag after OS update


MAMAC

Members
Jan 24, 2017
165
40
Hello, many people complain about battery drain & lags after OS update. This method maybe can help u.

Lest first explane why and what this method do. Tutorial is taken from chinese xiaomi fans.

Probably each of you was faced with high battery consumption in the first 3-4 days after updating or flashing the device, the android system is the first in the list of consumption and has 30-40% of use! This guide will help to remove this problem.
It should be after flashing or installing updates on older versions of Android starting from 6 and below.

You have encountered such a system dialog as "Optimizing app xx from xx"

In Android 7.0, did they hide this from the user's eyes or delete it? Does this mean that the optimization has been removed? No, this is not such. This option was not lost, but simply postponed, and the postponement of this task causes the battery to run out. Do you think that optimization is happening in the background? The answer is not correct. It only starts under special conditions. Lack of this optimization will drain the battery. Optimization is not performed because we do not know how to fulfill the conditions necessary for its launch. The consequence of this is the accelerated discharge of the phone.

You can often watch how the Android system consumes energy more than other applications. This is the result of not allowing the system to optimize.
If in Android 6 and earlier optimization was forced, then starting with Android 7 and higher. A new option was added to skip this step and optimize applications on the fly (JIT, Just-In-Time) while using applications.
At the same time, the initial optimization has not been deleted and only starts if the following conditions are met:
  • the phone is connected to the charger,
  • fully charged,
  • turned on (the phone itself, not the screen),
  • is not used,
  • inactive (like after at least 30 minutes).

If these conditions are met, optimization begins.


Why do we need this optimization?

Because application developers cannot do this for each set of hardware and each device is already. It compiles applications into the most efficient code for its processor. So just use your device and let it take care of the cache itself or help your device make full optimization with simpl command.
Quick note
People who dirty flash a lot. You might randomly experience longer app launch times after flashing a ROM and the only apparent way to fix it was to do a clean flash. I experienced this a few times and decided to investigate and saw that it had something to do with how dex2oat works after you dirty flash (it refuses to optimise properly?).

You can manually run dex2oat on everything after it booted into the system, and after it has finished the process (could take super long depending on how many apps you have), everything went back to its speedy state.

(And it seems improve idle drain (big battery usage by system), because we're forcing doing task that only can run if some condition only, but also sometimes can unexpectedly happens while phone was idle, o it's causing huge idle drain usage)
Be that as it may, you have the option to force the optimization to run.

For users with root:
open a terminal emulator and execute (along with quotation marks, as this is part of the command):

su -c "cmd package bg-dexopt-job"

or

su

next

"cmd package bg-dexopt-job"

If you don’t have root, use ADB. Connect the phone to the device, make sure it is available (enable USB debugging and USB debugging secure settings). Open CMD ADB platform-tools and write command one by one:

adb devices

Run the following command

adb shell cmd package bg-dexopt-job

or

adb shell "cmd package bg-dexopt-job"

If you have 10 android you will see Success, if from 7 to 9 a new line for entering the command will simply appear!
32438


The process can take from 20 minutes to 3 hours (on my MI 9t this operation take 40 minutes).
Disconnecting the device during optimization will interrupt the process, but will not harm the device. It is absolutely safe.
Users without root may find the error message
"user 2000 nor current process has Android.permission.Update_Device_Stats"

It’s not worth worrying, you can ignore it and run the command again.
 

MAMAC

Members
Jan 24, 2017
165
40
Additional tips for possible speeding up your phone.

I get some speed on a phone after ota upgrade. U can try too maybe it will help.

1.) https://xiaomi.eu/community/threads/tutorial-battery-drain-lag-after-os-update.58011/
2.) download Titanium Backup
3.) open it , press menu, press "Overview of app storage use", Sort by Cache, flush cache from all large one (like play store, play service, themes)
4.) Download trimmer Play Store, trim all
5.)run Xiaomi Security app, scan whole device, fix what he want to be fixed, bypass what u usual use.
6.) Change your theme
7.)back to Titanium Backup, press menu, press clean up the davlink cache, clean up the system logs (if it have it)
8.) reboot device

Edit: video after optimisation. Before optimisation i didnt record but it was horrible.

 

Stickit

Members
Jan 16, 2021
50
20
Is this still valid for Android 11? I'm getting an error "package not found" on my pyxis with Miui 12.5.
 
Dec 3, 2020
844
182
@MAMAC, this applies for android 11 too, right?
Also, do I just leave it running while I use other apps? In termux it doesn't seem to do anything...
Can I shut down the screen?
Edit: it worked! (Took about 5 mins.)
 

Attachments

  • Screenshot_2021-03-21-10-42-48-870_com.termux.jpg
    Screenshot_2021-03-21-10-42-48-870_com.termux.jpg
    320.9 KB · Views: 695
  • Screenshot_2021-03-21-10-44-00-726_com.termux.jpg
    Screenshot_2021-03-21-10-44-00-726_com.termux.jpg
    529.1 KB · Views: 656
Last edited:

NineZ

Members
Apr 26, 2018
9
15
My Mi 9 on miui 12.5 no root(21.3.18) follow this tips just use around 10 min
Big Thank for your tips like this very much.

sorry if look wired word am not good Eng XD
 

night_whisper

Members
Sep 10, 2011
21
25
I tried this on new weekly and really dont know if this made my phone really snappy and battery friendly or new weekly on my mi 10t pro.
For shure i will do this after every update. thank you amigo!
 

AJSRO

Members
Dec 6, 2020
29
25
Hi!

I've read your optimization guide and it looks so interesting to test but I have a question. Does this guide apply only for MIUI ROM or can I try it on AOSP ROMs as well?
 

MAMAC

Members
Jan 24, 2017
165
40
@MAMAC, this applies for android 11 too, right?
Also, do I just leave it running while I use other apps? In termux it doesn't seem to do anything...
Can I shut down the screen?
Edit: it worked! (Took about 5 mins.)
Sry i way away for days :) yah just keep it like u did anyway :)
 

504 Gatewey

Members
Feb 10, 2020
66
20
terminal emulator it is created for earlier versions of the Android terminal emulator. What other program can be used to make optimization?
 

tue0506

Members
Jun 28, 2018
35
20
Hi!

I've read your optimization guide and it looks so interesting to test but I have a question. Does this guide apply only for MIUI ROM or can I try it on AOSP ROMs as well?
Of course you can use it for any Android ROMs from Android 7.0 to 12.0
 
  • Like
Reactions: AJSRO

Stelvio79

Members
Jan 2, 2021
28
15
It work perfect on my Mi9T pro at 21.3.18 with Android 11.
I just used this version of command:
adb shell "cmd package bg-dexopt-job"
It work perfect on my Mi9T pro at 21.3.18 with Android 11.
I just used this version of command:
adb shell "cmd package bg-dexopt-job"
I did everything as described adb devices ok it finds it after the second command but nothing happens and if I try again it tells me offline emulator. I do not know what to do
 

danilomazzaro

Members
Oct 7, 2019
65
30
I did everything as described adb devices ok it finds it after the second command but nothing happens and if I try again it tells me offline emulator. I do not know what to do
After this command:
adb shell "cmd package bg-dexopt-job"
Your adb prompt will looks like in idle, but in a second plan, your device will start to rebuild the cache. After a 15 min with you device connected, the adb will show "success".

It looks nothing are happening, but the process is happening in second plan with no confirmation message.