SetAndroidProcessLimit icon indicating copy to clipboard operation
SetAndroidProcessLimit copied to clipboard

Doesn't appear to work on newer versions of Android

Open tech128 opened this issue 9 years ago • 27 comments

Well apparently lollipop breaks this app.

I'm running the latest 5.1.1 and it runs, but when it boots and tries to change the limit, it breaks pretty hard.

I/art ( 2380): Late-enabling -Xcheck:jni I/ActivityManager( 519): Start proc 2380:de.florian.processlimit/u0a25 for broadcast de.florian.processlimit/.BootReceiver D/de.florian.processlimit( 2380): New limit: 4 W/System.err( 2380): java.io.IOException: Unable to open '/system/priv-app/Settings.apk' : No such file or directory W/System.err( 2380): at dalvik.system.DexFile.openDexFileNative(Native Method) W/System.err( 2380): at dalvik.system.DexFile.openDexFile(DexFile.java:295) W/System.err( 2380): at dalvik.system.DexFile.(DexFile.java:80) W/System.err( 2380): at dalvik.system.DexFile.(DexFile.java:59) W/System.err( 2380): at de.florian.processlimit.SetProcessLimitActivity.setProcessLimit(SetProcessLimitActivity.java:57) W/System.err( 2380): at de.florian.processlimit.BootReceiver.onReceive(BootReceiver.java:20) W/System.err( 2380): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2631) W/System.err( 2380): at android.app.ActivityThread.access$1700(ActivityThread.java:154) W/System.err( 2380): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1388) W/System.err( 2380): at android.os.Handler.dispatchMessage(Handler.java:102) W/System.err( 2380): at android.os.Looper.loop(Looper.java:135) W/System.err( 2380): at android.app.ActivityThread.main(ActivityThread.java:5338) W/System.err( 2380): at java.lang.reflect.Method.invoke(Native Method) W/System.err( 2380): at java.lang.reflect.Method.invoke(Method.java:372) W/System.err( 2380): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917) W/System.err( 2380): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704) W/System.err( 2380): Caused by: java.io.IOException: Failed to open oat file from dex location '/system/priv-app/Settings.apk' W/System.err( 2380): ... 16 more W/System.err( 2380): Caused by: java.io.IOException: Failed to open oat file from /system/priv-app/arm/Settings.odex (error Failed to open oat filename for reading: No such file or directory) (no dalvik_cache availible) and relocation failed. W/System.err( 2380): ... 16 more W/System.err( 2380): Caused by: java.io.IOException: W/System.err( 2380): ... 16 more

I'm pretty sure it's because of the hardcoded /system/priv-app/Settings.apk

That file is now in /system/priv-app/Settings/Settings.apk

tech128 avatar Nov 09 '15 21:11 tech128

Because this issue annoyed me so much, I decided to find a non-code way to set the process limit.

It can be done with root access with a single command.

service call activity 51 i32 x

Where x is the number of background processes you want.

Hopefully you can let people know on the main page here.

If the API changes in the future, it's easy to look it up again.

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/app/IActivityManager.java?av=f

Look for the line with SET_PROCESS_LIMIT_TRANSACTION

Then just extrapolate that info to http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/DESIRED_ANDROID_VERSION/android/app/IActivityManager.java?av=f

Replacing DESIRED_ANDROID_VERSION with the version you're interested in.

tech128 avatar Nov 11 '15 01:11 tech128

I added the alternative way to the main page. I don't know why the app doesn't work, there's no hardcoded path to Settings.apk, the system chooses that automatically.

flode avatar Nov 11 '15 10:11 flode

For Tasker users, another app-based mechanism to set this value is via Secure Settings, which does work for me on all of Android 2.3 ... 4.4 as of this writing (I have no 5.x devices to test):

https://play.google.com/store/apps/details?id=com.intangibleobject.securesettings.plugin

The function is Root Actions -> Background App Processes and offers the usual set of default/none/1/2/3/4 options. Secure Settings can be used without Tasker by creating a shortcut, but to run at boot, you need Tasker (or Locale or similar) to use Secure Settings as a plugin, or some other app capable of launching shortcuts at boot to trigger a Secure Settings shortcut action.

(Tasker's profile context for boot-complete is Event -> System -> System Boot. The task it executes should contain an action Plugins -> Secure Settings using the above Secure Settings function.)

tvierling avatar Nov 11 '15 14:11 tvierling

@flode hi there.. I have 5.1.1_r1 and I tried to use the alternative (manual) way: service call activity 51 i32 x what I don't understand is I have to use 50 or 51.. You also said in fact that we should check SET_PROCESS_LIMIT_TRANSACTION line, and that's what I did, but it reports 50 NOT 51.. I also checked it for the 4.4 and it already was 50.. Did I miss something?

BTW I launched two commands using both 50 both 51 from my terminal and it works great!

brainvision avatar Nov 21 '16 18:11 brainvision

service call activity 51 i32 x @tech128 Many thanks for the command, it works great specially in an init.d script. Tested on a Lt26i (aka Xperia S), Android 4.1.2 with init.d support.

ghost avatar Jun 02 '17 15:06 ghost

The service call activity 51 i32 x option is looking very promising here on a Sony Bravia Android TV that at the time of writing runs Android TV 7.0

My TV is not rooted (I'm not even sure if anyone has found a way to root a Sony Android TV yet) however service call activity 51 i32 x does appear to be working as expected when executed in an adb shell.

I'm hopeful that I can now find a way to run this in a shell script on boot. Many thanks for this project and special thanks to @tech128 for finding and mentioning this option.

bebo-dot-dev avatar Feb 17 '18 10:02 bebo-dot-dev

Hi everyone! Unfortunately, "service call activity 51 i32 4" not working on Android Pie, so can anybody help me to make it working? I can't find necessary strings in android pie source code to understand how to modify the command, grepcode.com is down and I can't figure out how to find necessary strings in a new AOSP repository. I'll be very happy if anybody helps me with it, cause I want to enter this value to custom rom of my phone to make one work much smoother, clearly 2gb of RAM is not enough to run Android Pie smooth.

ProgierEugene avatar Feb 06 '19 12:02 ProgierEugene

Is it working for Android 8 ? Can anyone can confirm ? service call activity 51 i32 x

Novosti1 avatar Oct 19 '19 01:10 Novosti1

If the API changes in the future, it's easy to look it up again.

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/app/IActivityManager.java?av=f

Look for the line with SET_PROCESS_LIMIT_TRANSACTION

Then just extrapolate that info to http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/DESIRED_ANDROID_VERSION/android/app/IActivityManager.java?av=f

### LINKS NOT WORKING, anyone help ?

Novosti1 avatar Oct 20 '19 22:10 Novosti1

I can confirm it doesn't work on Android 9. Also tried those links to and they appear dead.

ghost avatar Oct 27 '19 10:10 ghost

I tried different numbers and found that right number for Oreo is 42 (service call activity 42 i32 x) and for pie is 47 (service call activity 42 i32 x). I usually use 15-18 apps values, it's optimal for both multitasking and interface smoothness

ProgierEugene avatar Oct 27 '19 12:10 ProgierEugene

Thank you @ProgierEugene, I don't know how you worked this out but service call activity 42 i32 x works for me on my Oreo Android TV. Much appreciated thank you.

bebo-dot-dev avatar Oct 27 '19 21:10 bebo-dot-dev

For Android Q is: service call activity 40 i32 x

Mitezuss avatar Sep 15 '20 09:09 Mitezuss

service call activity 51 i32 x - Android 7 ( good with 6 also ) service call activity 42 i32 x - Android 8 service call activity 47 i32 x - Android 9 ( not confirmed )

Novosti1 avatar Feb 23 '21 17:02 Novosti1

Any idea what's the code for A11? Thanks.

atonement87 avatar May 12 '21 06:05 atonement87

Any idea what's the code for A11? Thanks.

service call activity 44 i32 x

z826540272 avatar Jul 17 '21 11:07 z826540272

Because this issue annoyed me so much, I decided to find a non-code way to set the process limit.

It can be done with root access with a single command.

service call activity 51 i32 x

Where x is the number of background processes you want.

Hopefully you can let people know on the main page here.

If the API changes in the future, it's easy to look it up again.

http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/app/IActivityManager.java?av=f

Look for the line with SET_PROCESS_LIMIT_TRANSACTION

Then just extrapolate that info to http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/DESIRED_ANDROID_VERSION/android/app/IActivityManager.java?av=f

Replacing DESIRED_ANDROID_VERSION with the version you're interested in.

But now these links broken, Where can i found "x" number in newer android? Thanks

oldman20 avatar Jun 17 '22 07:06 oldman20

im on android Pie!

oldman20 avatar Jun 17 '22 07:06 oldman20

im on android Pie!

service call activity 47 i32 X

X = process

Mitezuss avatar Aug 04 '22 02:08 Mitezuss

For A11 it's actually 43. I've updated a script to catch the command number for future Android releases: https://stackoverflow.com/a/75424165/16725644

nor-ric avatar Feb 12 '23 00:02 nor-ric

For A11 it's actually 43. I've updated a script to catch the command number for future Android releases: https://stackoverflow.com/a/75424165/16725644

nice to see this process still active in 2023

oldman20 avatar Feb 17 '23 04:02 oldman20

great stuff here. Accidentally struggled over a problem with a background process limit and wanted to increase it more then the max in developer options.. Thanks all for figuring out the id's and @flode for the initial bring-up.

for those interested I made an Automate flow for that. Currently supports Android 6 - 11 and if someone would tell me the values for Android 12 and 13 I can easily extend it :)

Have fun: https://llamalab.com/automate/community/flows/44550 (Flow name: "Set max background processes")

steadfasterX avatar Feb 24 '23 12:02 steadfasterX

Hi all,

I'm on Lineage 20/Android 13 and thks to this I managed to determine that the proper code on this level is 44 (@steadfasterX) and thus was able to run the shell command described above using adb.

However, contrary to what I was expecting, the change to the max number of bg processes is NOT persisted (i.e. : on reboot it's back to "standard"): what am I missing? Is this normal?

Thanks in advance for your help!

jfaure9 avatar Jan 01 '24 19:01 jfaure9

Thats expected behavior and the reason why I linked the automate flow which can do that on every boot automatically

steadfasterX avatar Jan 01 '24 20:01 steadfasterX

Thats expected behavior and the reason why I linked the automate flow which can do that on every boot automatically

Oh... My bad. I misunderstood the README and thought the command line method was bypassing the "reset on boot" behavior. Thanks for the automate flow!

jfaure9 avatar Jan 01 '24 21:01 jfaure9