Mediaserver battery drain issue can mainly be seen on Android custom ROMs. Even on some official ROMs (mainly on lower-mid range devices with octa-core or quad-core processors clocked at higher frequencies) we have seen this issue. Though in some cases vendors patched it by rolling out updates but still on some official ROMs the issue is there. Here we intentionally have created the issue on a CyanogenMod 11 powered device and fixed it with some easy steps
What is Mediaserver?
Mediaserver scans all the available media files (photos, videos, songs etc) and index them, so that instead of performing full scanning again and again all applications can access the files faster while required. So basically Mediserver is designed to reduce disk I/O for providing faster response (or output). But the Mediaserver battery drain issue is a real pain as this bug drains all of your battery juice and your fully charged smartphone could die even in less than 2 hours and your phone will be overheated badly. So if you are facing overheating, battery drainage issue go and check the “Battery Usage” (Settings->Battery) and if you observe Mediaserver is consuming most of the battery juice, then probably the media scanner tends to be buggy. You may follow the steps below to resolve the issue.
For this test we used a lower-mid range (with good CPU specs) device YU Yureka which comes with CyanogenMod 11 out of the box. This device has 64 bit Qualcomm Snapdragon 615 Octa Core processor clocked at 1.5 GHz and a 2500 mAh battery. Simultaneous utilization of all 8 cores in maximum frequency can easily drain the 2500 mAh battery in 1.5-2 hours. We tested the device for 2 days and did not observe any battery or overheating issue. Now we inserted an used Micro SDHC-I class 10 32 GB card (which was taken out from a Sony Xperia Z3 and we did not format it). As we did not format the SD card it was full of folders and files created by the applications which were installed on Xperia Z3. Besides we copied a folder of 12 GB, which contains thousands of text files, documents, .xls, .pdf, .html files with small images/icons/logos (.jpg, .ico, .png, .gif etc of few bytes each) before inserting the SD card to CyanogenMod 11 powered Yu Yureka. Out of 32 Gb the SD card was about 20 GB full. After inserting the SD card, suddenly after few seconds we observed the unusual behaviors of this phone.
The part of the phone where the processor is placed started to get very hot. It was very much uncomfortable to hold the phone against the head. After checking “Battery Usage” we observed Mediaserver is now taking more than 50% of total battery usage (we cleared previous battery data) and the battery level reached to 57% from 83% in one hour, though most of the time the phone was not used (only background processes were running). We took out the SD card and inserted another 32 GB SD card (same specs) which also had about 20 GB of data. It contained about 20 HD videos, about 500 songs and some pics. This time this SD card did not have large counts of small images/ico/loge file and folders and files created by the applications installed on another device. When we inserted the second SD card we did not observe any issue though this SD card also had same amount of data, but the difference was in number of files (thousands of unorganized files compare to few hundred well organized files).
Because of absence of any optimized resource plan this CyanogenMod 11 powered device went aggressive (approximately utilized 80 to 85% of MAX frequency of all CPU cores) in scanning and indexing those large number of files, which resulted in overheating of the phone and average of about 24% battery drainage in every hour.
We have also inserted that same used SD card, without formatting it to a Galaxy Note 4. But we did not observed this issue. As the ROM running on Note 4 is well optimized by Samsung, so instead of aggressive utilization of all processor cores to scan and index media, Note 4 uses some optimized algorithm to index these media, without overheating or draining excessive battery.
Steps to avoid/fix Mediaserver battery drain issue
1. The first thing you need to do is deleting unnecessary files from your storage. If your SD card contains plenty of small (in bytes or in few KBs) files (images or icons), that can be the reason of excessive media scanning. When you save a webpage as .html all small images and icons get downloaded and it increases count of media files. You can download or store html files with out downloading images/icons or may use applications like Pocket or any other offline reading apps to avoid it.
2. If you are still facing the issue. You need ADB and Root access to your device to perform below steps.
You may Download Android Studio.
Once ADB gets installed. Open Shell and get Superuser permissions:
Now check if Mediaserver is among the top activities or not.
top | grep mediaserver
You will get output like below:
# top | grep mediaserver
2318 0 21% S 7 27180K 9283K bg media /system/bin/mediaserver
So it can be seen that mediaserver background process is eating up 21% of CPU, which need to be fixed.
Now, run the below command. If you see that the media scanning service is halted at a file or directory for a long time, then probably that file/folder is damaged and you may need to remove/delete those to solve media scanning issue. It will definitely improve mediaserver process.
lsof | grep media_rw
# lsof | grep media_rw
sdcard 3245 media_rw exe ??? ??? ??? ??? /system/bin/sdcard
sdcard 3245 media_rw 0 ??? ??? ??? ??? /dev/null
sdcard 3245 media_rw 1 ??? ??? ??? ??? /dev/null
sdcard 3245 media_rw 2 ??? ??? ??? ??? /dev/fuse
sdcard 3245 media_rw 3 ??? ??? ??? ??? /mnt/media_rw/sdcard1
sdcard 3245 media_rw 4 ??? ??? ??? ??? /mnt/media_rw/sdcard1/anik
3. If even after following above two steps, the Mediaserver process is still using most of your battery juice, you may try another SD card with less storage capacity.
4. There is a good app in Google Play store,
Mediaserver Killer. You may use this app to instantly kill the Mediaserver process or can set intervals to kill this process after every n minutes. But if you kill this process repeatedly all media files will not appear properly in your Gallery, Music or Video library.