Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,779,301 Members 50,991 Now Online
XDA Developers Android and Mobile Development Forum

[FIX] Bulletproof Background Apps!

Tip us?
 
zeppelinrox
Old
(Last edited by zeppelinrox; 29th December 2011 at 05:18 PM.)
#1  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21170
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
Default [FIX] Bulletproof Background Apps!

UPDATE: Try BulletProofing Apps with my latest V6 SuperCharger Script! Use the following link OR use the link in my signature

I didn't want to risk making the SuperCharge & Bulletproof thread too confusing so I figured it best to make a "sister" thread.

This is a work in progress.

But if this information is helpful, please click the thanks button

HUGE thanks to Feeyo and Bear in NM for helping me figure out a workable solution on locking a background app in memory on boot up.

Feeyo gave me the gist of it but it wouldn't work on boot.
After posting in this thread at Droid Forums, things got rolling - with alot of help from Bear in NM.

Create a Unix script file with no extension (I named it 97oom) with Notepad++ and put it in your i/system/etc/init.d/ folder and put this inside:
Code:
#!/system/bin/sh

sleep 60

PPID=$(pidof com.estrongs.android.safer)
echo "-17" > /proc/$PPID/oom_adj
Permissions: chmod 755 /system/etc/init.d/97oom (same as 10overclock)

You can also do it on the phone itself:
1. Make a copy of 10overclock
2. Renamed it to 97oom (I have a 98governor and a 99complete so...)
3. Deleted the text and put the text you see above
4. Set permissions

Then reboot to test!
You can check to see if it worked with either Auto Memory Manager (AMM) or AutoKiller Memory Optimizer (AKMO).

The bold text in the above code is the process name of the app that you want to protect!
Note: You can get the process name from most process monitors or with AKMO or AMM.

That command "as is" will give ES Security Manager the highest priority of -17.
AKMO shows it as being ignored by the OOM killer
At first it wasn't working on boot because ES Security was not yet loaded in memory.
The "sleep 60 "command fixes that by waiting 60 seconds to execute the command

You can also do this in GScript Lite with this:
Code:
PPID=$(pidof com.estrongs.android.safer)
echo "-17" > /proc/$PPID/oom_adj
This comes in handy for apps that don't load on bootup - just run a GScript for those apps

I suggest you get Busybox Installer and have it install the latest BusyBox (v1.19).
This ensures GScript doesn't spit out ugly stderr: messages.

GScript Tip: 1. Make a file (with any text editor) with the commands
................. 2. Rename it with an .sh extension (example 97oom.sh)
................. 3. Put it in sdcard/gscript folder
................. 4. Run GScript, Menu key, Add script, and click Load file, select a script and Save (leave SU checked)

Even better, you can make shortcut for any GScript.
Long press desktop > Shortcuts > GScript Lite > Select... BOOYA!

As I said, this is a work in progress.
Taming the OOM Killer explains that an app will be ignored by the OOM killer if it has the -17 priority.
The problem is that Android will still shuffle it's priority downwards like it does with any inactive app.
If that happens, then the app reverts to it's usual priority.
This is why ESS will lose it's -17 after a couple of hours. It just sleeps ALL the time.

My thinking that if a more active background app, such as an SMS app or a music app is given the -17, it won't lose it's priority at all.

Feedback with results is more than welcome!
The Following 40 Users Say Thank You to zeppelinrox For This Useful Post: [ Click to Expand ]
 
IanTester
Old
#2  
Member
Thanks Meter 19
Posts: 36
Join Date: Jan 2011
Location: Bathurst
No need to set a variable, just use back-ticks:
Code:
echo -17 > /proc/`pidof com.estrongs.android.safer`/oom_adj
Although that may be a little too complicated for some people to type in. Best to keep it simple I suppose...
The Following 2 Users Say Thank You to IanTester For This Useful Post: [ Click to Expand ]
 
zeppelinrox
Old
#3  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21170
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
That's pretty cool.
I figure most people would copy/paste the whole thing and replace the process name.
So maybe the back ticks wouldn't be a big deal.
The Following 4 Users Say Thank You to zeppelinrox For This Useful Post: [ Click to Expand ]
 
Bear in NM
Old
#4  
Junior Member
Thanks Meter 0
Posts: 9
Join Date: Mar 2010
That is why I try and avoid putting any code I use on forums. Someone who actually knows what they are doing will always come along and whack me ;^)

Seriously, good work Zep.

Craig
 
zeppelinrox
Old
#5  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21170
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
I don't mind.
That's all a part of learning so it's always good that there's somebody around that's "smarter" at something than me.

For example... this script I'm trying to get working for supercharging stock phones...

On custom roms, CM and FroyMod at least, I'd modify /system/etc/rootfs/init.mapphone_umts.rc

I flashed stock telus 2.2 and the path seems to be just /init.mapphone_umts.rc
I don't see rootfs anywhere
But there is a rootfs is mounted

To mount as rw, "mount -o remount,rw /system" doesn't work
In gscript, I'm getting "sed not found" errors too.

grrr...
The Following User Says Thank You to zeppelinrox For This Useful Post: [ Click to Expand ]
 
milestonefail
Old
(Last edited by milestonefail; 2nd April 2011 at 08:53 PM.)
#6  
Senior Member
Thanks Meter 17
Posts: 108
Join Date: Sep 2010
Location: Toronto
how well do you think this would work with handcent? it's a little laggy to load up on my phone, but i want to try it out more. will keeping handcent in memory eat up ram that i need otherwise? and do you think it will be active enough to keep it's -17 after a few hours? thanks

edit: i was trying it out, it disappeard from processes withing a few minutes. oh well, maybe it doesnt need to be running anyway
 
zeppelinrox
Old
#7  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21170
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
Did you check with AMM to see if handcent had the high priority or if it really got killed?
 
milestonefail
Old
#8  
Senior Member
Thanks Meter 17
Posts: 108
Join Date: Sep 2010
Location: Toronto
ya, i checked. it was set to -17, then next time it refreshed it was gone. then i opened handcent, went back, and the process had a different pid, not oom level. oh well
 
zeppelinrox
Old
#9  
zeppelinrox's Avatar
Senior Member - OP
Thanks Meter 21170
Posts: 9,312
Join Date: Dec 2010
Location: IN THE FREAKIN' OP

 
DONATE TO ME
damn
Maybe some apps are too prone to get killed off and the only way to keep them alive is with multitasking friendly minfree values
 
mike-08
Old
#10  
Member
Thanks Meter 2
Posts: 34
Join Date: Mar 2011
Quote:
Originally Posted by zeppelinrox View Post
damn
Maybe some apps are too prone to get killed off and the only way to keep them alive is with multitasking friendly minfree values
Yes, I've seen the same happening with the stock SMS app. I did not receive SMS anymore so I decided to look at it a bit closer (using adb logcat). I started the SMS app, noted down the PID and set the oom_adj value to -17 using adb shell. A few seconds later it was killed. Setting the minfree values back to system default allows me to receive SMS again. Also whatsapp, gtalk and push mail now work reliable. With high minfree values I could see in the logs that, when a message arrived the app is started and immediately killed afterwards. So, I was never notivied that a SMS or whatsapp message had arrived. With default minfree values it seems to work more reliable.
But it all depends on how you use your phone, I guess. I'm using it as my communication central and don't want to miss any message. If you use it more as your mobile gaming or surfing device you might still be better off with high minfree values.

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes