Swatinem Blog Resume

Finding and fixing runaway Android Battery Usage

— 5 min


My phone was draining unreasonable amounts of battery lately. Shelling into the phone via adb shell after enabling USB debugging, and doing a simple top revealed that, of all things, com.sonymobile.launcher, aka the Home Screen / Launcher was constantly running at 200% CPU (saturating 2 cores), and using up to 10% of memory.

I switched to a different Launcher which so far looks to have fixed the battery drain, though I should observe it for a longer time to be certain.

# The whole story

I got myself a new Android phone fairly recently. A Sony Xperia 10 IV. A phone with a headphone jack, finger print reader, and most importantly for me by now: No fucking useless notch / face camera cutout. And a screen with only a minimally curved corners, and no screen to the edge. Because I want to hold it firmly in my hands without triggering any touch actions.

Anyway, so far I was very happy with it, a new phone with a brand new battery. The usage was also reasonable, it used to drain about ~20% per day with my average usage pattern. Which means I needed to charge it about every 3 days if I go from 20% to 80%, neither draining too deep, nor topping it completely off.

After an update about a month ago however, I had troubles with battery usage. The phone would get into some kind of broken state where it would drain up to 4x the usual amount. I had to charge it almost daily. It was also pretty random. I could go half a day with normal battery drain, just to have it drain half the battery when being completely idle over night. Sometimes restarting it would put battery usage back to normal. Sometimes going on airplane mode would. But other times these things just didn’t make a difference.

I was completely clueless. The battery usage page in the Android system settings pointed to some unreasonable battery draw from the mobile network. I went through a couple of online help pages suggesting to turn of always-online mobile network when you are connected to WIFI, or to disable power hungry 5G completely. Still nothing.

Well then, I’m a software engineer I thought. How about I debug this thing like an Android developer would. There is a page in the Android developer docs that explains how to setup and use batterystats and Battery Historian. I tried that, and after the phone drained 16% of battery in about 6 hours of being mostly idle, I collected a snapshot and looked at the result. Battery Historian reported an idle power draw af 2.3%/hr, and a whooping 8.6%/hr when active.

And then there it was. For a total wall time of about 6 hours, the phone had over 7 hours of CPU time, almost 4 of that in system time. There was something going wrong there indeed. The CPU and the kernel only uptime was constantly active during that time. Kernel Wakelocks was also accounting for 4.5 hrs of that time. I thought, what the hell is the kernel doing there? The kernel wakesources showed rgb_ctrl_wq as having a total duration of 4 hrs as well. What does that even mean?

Going through the apps by CPU usage then showed the com.sonymobile.launcher, aka home screen as using 6.5 hrs of user time, and 3 hours of system time. As a reminder, the whole experiment was running for a little less than 6 hours. So was the home screen really using up all that CPU, and burning through the battery doing so?

Then it hit me: Android is in theory a linux just like every other linux? And I remembered from some time ago that it has top installed. So I used adb shell to connect, and top indeed showed com.sonymobile.launcher constantly using up 200% of CPU, aka two full cores. Not only that, but also 9% of the memory, almost 500M out of the 5.5G usable on the phone. Well, no wonder the system is constantly killing my backgrounded apps I don’t want to be killed.

I really should have thought of that earlier. A good old htop (or Windows Task Manager) is the first thing to look at if things are not performing as expected. The tools built into the Android System Settings are useless.

I cannot completely blame the launcher in itself though. I did have a bunch of widgets on the home screen. Any of those might have been misbehaving. For example I had a home screen widget for VLC which I use as media player. And for some unknown problem, the system was revoking its permissions to read media files. Twice in a row. For no reason! Its quite possible that because of this permissions problem, the VLC widget was causing the home screen to spin. Or maybe some other widgets, who knows?

Either way, this does cast a very bad light on Sony, and Phone manufacturers in general. It is a widely believed myth that phone vendors are intentionally slowing down their phones to incentivize people to buy new ones. Or is it reality after all? I mean, there have been documented cases where this indeed happened.

A vendor-supplied system app burning through the battery shortly after I did a system update. After I have never experienced this behavior before for the half year I own this device. It sure is an awfully bad coincidence, and casts a very bad light on the vendor.

Since then I switched to an alternative home screen. I definitely need to run the phone for longer with it to verify the long term behavior, but so far it looks like the battery drain problem has been fixed.