2009-12-23

[Android] WhoSlowsBootTime - evil BOOT_COMPLETED services

My htc magic is really getting slow on boot. Inspired by this article, I've published an application, WhoSlowsBootTime, on the Android Market that can show you boost-time services installed on your phone. It's really a simple and free application.

If you are interested in its source code, go check it out at my GitHub repository.



In my Magic, there are probably 20-30 boot-time services it has to run. No wonder the slow boot.

Furthermore, I was thinking if it might be possible to disable/enable boot-time services as what we used to do in Windows or Linux. So, I added code to try.
In AndroidManifest.xml, 



and in Java,
pm.setComponentEnabledSetting(
    new ComponentName(appInfo.packageName, appInfo.name),
                      PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                      PackageManager.DONT_KILL_APP);
But, the application threw an SecurityException immediately after the line above.
E/AndroidRuntime( 3188): java.lang.SecurityException: Permission Denial: attempt to change component state from pid=3188, uid=10026, package uid=10023
It makes sense totally. If an application can change other application's state, what will happen? A big security hole.

One thing I leaned from trying this is that I noticed some applications use BOOT_COMPLETED as a way to auto-start themselves after boot completed. This means if you want your application to run automatically after boot, register a boot-time BroadcastReceiver and start your main activity in onReceiver().