There’s an update step that shows “Optimizing apps” during installing a system update normally. It takes a while.
- What does it do?
- Is this step skipped when flashing a full OTA via adb sideload?
- Is there any difference in regards to the effect of “Optimizing apps” between the regular system update process and full OTA flashing?
Android apps are still heavily based on Java. But doing Java stuff at runtime has proven to be fairly slow still.
So modern Android does something called Ahead of Time compiling (AOT) where it compiles the Java bytecode to native code at installation.
After an OTA, those are all invalidated because system libraries may have changed, so it needs to redo that. That’s what it’s doing.
If you adb shell into the device while it’s doing that, you’ll see it’s running dex2aot on all your apps.
Yes it’ll do it if you flash it directly too. For the update process purposes, there’s very little difference between regular OTAs and flashes in recovery. You just don’t see it on first boot because you’re busy doing the initial setup screens and system apps are usually precompiled and baked into the ROM anyway. No third-party apps installed, no optimization to do.
They could probably just do it in the background silently, but it does give an indication to the user that heavy stuff is going on in the background and thus explains why the device is running a bit slower, a bit hotter and using more battery than normal. A lot of things a regular user could be concerned about immediately after an update, so you’re better off letting the user know stuff is happening and that it’ll settle down.
So the implication is that during the normal system update process, the AOT compilation happens prior to rebooting whereas during OTA sideloading it happens post rebooting? This kinda makes sense because the OTA sideloading process is much faster. It also implies that post OTA sideloading, the device might show poorer battery life for a bit, yes?
It does it post reboot in both cases.
I don’t know why OTAs are so slow to install. Maybe it’s slow to conserve battery or not affect phone performance too much? No idea.
It does the same thing in the end.
That’s a great explanation! Thanks!