Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No Longer want ActivityManager - Not a service issue

I am working on a open source application (droidwall fork) and i am stuck with one of the issue were the iptables rules were not applied properly when the system reboots. it works perfectly on most of the android versions. 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 somethings 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.

like image 823
ukanth Avatar asked Dec 26 '12 16:12

ukanth


2 Answers

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

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

More about empty processes from android doc:

A process that doesn't hold any active application components. The only reason to keep this kind of process alive is for caching purposes, to improve startup time the next time a component needs to run in it. The system often kills these processes in order to balance overall system resources between process caches and the underlying kernel caches.

So, not sure the log you have is directly related to your issue with iptables rules.

like image 85
ben75 Avatar answered Sep 30 '22 14:09

ben75


After the method onReceived() finished, the system assumes that you're done with the BroadcastReceiver and set the hosted process as lowest priority. And we know that the toaster Handler's handleMessage() method is called asynchronously which is called after the onReceived() method finished, and there is no guarantee that the process is still there to perform the callback method

On most Android versions, the number of processes that running at system start-up is not so many and your process (with lowest priority) has a chance to stay alive until the callback method handleMessaged() is called, but with ROMS (CM 10.1), there might be so many processes running that that moment, system has to kill lower priority processes to free up resources so that higher priority processes can run properly and your process is one good candidate to be killed.

I suggest you start a service to do those asynchronous tasks, that makes your process has higher priority (service-process priority by default or you can use startForeground() method to get the foreground-process priority)

like image 41
Binh Tran Avatar answered Sep 30 '22 14:09

Binh Tran