Monday, November 12, 2012

"Bulletproofing" Apps: Preventing Android from Killing Processes (root)

I have been playing with my Android phone lots lately. I installed Cyanogenmod 10 (CM10) on my Galaxy SII and I feel like I've got a brand-new phone - all of my upgrade envy about the latest and greatest devices has evaporated (for now!).
I've also installed an app called Llama. Llama watches cell phone towers that I'm nearby, and performs actions based on where I am. You can program in any rules you'd like. I've got Llama set up to do the following:
  • Enable wifi when I'm at home, a buddy's house, or my parents' house;
  • Disable wifi when I leave any of those locations;
  • Turn my ringer to extra-loud when I arrive at work (useful on a construction site!);
  • Mute my phone between 9pm and 4:45am, ONLY when the phone is plugged in (ie, when I have it charging on my nightstand while sleeping).
There are a bunch of apps that can do the same thing, I just happen to like Llama.
One annoyance that I've encountered with Llama is that the Android operating system is really good at finding inactive processes and killing them. In other words, if it sees an app running in the background, and that app hasn't done anything in a while, it kills the app to free up the phone's memory to do other things. Often times this means that Llama dies at inopportune times. This results in my wifi staying on (battery drain) or my sounds staying muted (I miss calls!).
I finally found an awesome fix though - you can prevent Android from killing certain apps. For it to work, you need your phone to be rooted.
The fix can be found in this megathread on xda-developers, which is obscenely large and filled with an intimidating amount of rich text formatting. Don't worry, the fix pretty easy:
  1. Download the latest V6 Supercharger script from this xda-developers post and save it somewhere on your phone. The author has uploaded it as a .pdf (to get around upload size limits) so remove the .pdf extension after downloading (it is an .sh file).
  2. Make sure Busybox is installed on your phone. If your phone is rooted, Busybox is probably installed.
  3. Install Script Manager. This app can run the V6 script.
  4. Run Script Manager, enable the "browse as root" option in the settings.
  5. Open the V6 Supercharger script (that you downloaded in Step 1) in Script Manager, and be sure to run "as root" (the skull and crossbones icon turns green when you've done this right)
  6. Follow all the prompts and select the options you want. To learn more about the options, though... start reading that xda-developers thread.
To "bulletproof" an app and keep it in memory:

  • Select the "Bulletproof Apps" option in the V6 Supercharger script and follow the prompts.
"But... script!? I don't understand! Sounds hard" - you. No, it's easy. Let me calm your fears. When you run the V6 Supercharger script with Script Manager, here's what happens: You see text scrolling by DOS-style as the script runs, explaining what it's doing as it goes. Every once in a while it gives you a few options. You pick an option, hit enter, and the script keeps running. If you don't understand something, you can always choose "no". The script also saves your original settings so you can always revert back if something unexpected happens.
The first post in that big megathread has a ton of information on all the options, but you need to click the show/hide buttons to see it all.
It took me a LONG time to wrap my head around this fix and get it figured out. This is one of the perks of Android: you can hack it to get it running JUST the way you want it. :)


  1. Good post. I am going to save the URL and will definitely visit again.
    Pbx Phone System

  2. thanks for your guide, it helped me solving a long lasting problem.
    But just an additional remark: you need a busybox version with start-stop-daemon shop support like the one linked here:

  3. You can use "Pimp My Rom" to lock app in memory