No more ActivityManager required - no service issue

I am working on open source (droidwall plugin) and I am stuck in one of the problems: iptables rules did not apply properly when the system reboots. It works great on most versions of Android. But on some specific ROMS (CM 10.1) it gives the following logcat

12-26 08:39:27.116 I/ActivityManager(582): No longer want dev.ukanth.ufirewall (pid 2297): empty #17 

My code works something like below

 private Handler mHandler = new Handler(Looper.getMainLooper()); @Override public void onReceive(final Context context, final Intent intent) { if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { if (Api.isEnabled(context.getApplicationContext())) { final Handler toaster = new Handler() { public void handleMessage(Message msg) { if (msg.arg1 != 0) Toast.makeText(context, msg.arg1, Toast.LENGTH_SHORT).show(); } }; mHandler.post( // Start a new thread to enable the firewall - this prevents ANR new Runnable() { @Override public void run() { if (!Api.applySavedIptablesRules(context.getApplicationContext(), false)) { // Error enabling firewall on boot final Message msg = new Message(); msg.arg1 = R.string.toast_error_enabling; toaster.sendMessage(msg); Api.setEnabled(context.getApplicationContext(), false, false); } } }); // Start a new thread to enable the firewall - this prevents ANR } /*Intent i = new Intent(context, StartupService.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startService(i);*/ } 

You can find my Api.java class here .

+7
source share
3 answers

12-26 08: 39: 27.116 I / ActivityManager (582): dev.ukanth.ufirewall (pid 2297) no longer required: empty # 17

This log means that you have reached the maximum allowed empty processes. (16 is the maximum value in your case)

More on empty processes from android doc:

A process that does not contain active application components. The only reason this process continues is caching to improve startup time the next time the component starts. The system often kills these processes in order to balance common system resources between process caches and kernel caches.

So, not sure what you have directly related to your iptables rules problem.

+8
source

After completing the onReceived() method, the system assumes that you are finished using BroadcastReceiver and set the hosting process as the lowest priority. And we know that the handleMessage() toaster method is called asynchronously, which is called after the onReceived() method completes, and there is no guarantee that the process still exists to execute the callback method

In most versions of Android, the number of processes launched at system startup is not so many, and your process (with the lowest priority) has a chance to stay alive until the handleMessaged() callback method is called, but with ROMS (CM 10.1 ), at this moment there can be so many processes, the system must kill processes with a lower priority in order to free up resources, so that processes with a higher priority can work correctly, and your process is one good candidate for killing.

I suggest that you start the service to perform these asynchronous tasks, which makes your process a higher priority (the default service process priority or you can use the startForeground() method to get the foreground process priority)

+6
source

Perhaps you can use mHandler.post with some delay to check your case like 20 seconds?

0
source

All Articles