0

My goal is to kill a (background) process from a native function called from the java code in my application. What I've got so far is a native function with this code:

popen("am kill com.example.application", "r");

it doesn't do anything, and if I try to get the output with the pipe the application crashes. I've also set the KILL_BACKGROUND_PROCESS permission in the manifest.

What could be the problem?

caccolona
  • 37
  • 1
  • 8
  • Your permission doesn't help here because you're starting an external process with your code. See http://stackoverflow.com/questions/3105673/android-how-to-kill-an-application-with-all-its-activities for a proper solution – velis Feb 19 '14 at 14:37
  • @velis is there any way to do it from the native code? With su permissions? – caccolona Feb 19 '14 at 14:39
  • The link I posted contains native code solutions (android.os.Process.killProcess(android.os.Process.myPid());) – velis Feb 19 '14 at 14:44
  • 1
    Fundamentally, the NDK does not give you any special permissions, as JNI code runs as the same unix user as the calling Java code. Practically speaking, NDK code is *less* privileged, as it has much more difficulty in interacting with Binder IPC type system services - and that is how Android provides all but a few basics. You should either use the Java api for the limited purposes still allowed to 3rd party apps, or accept that your goal is not compatible with the Android security model. – Chris Stratton Feb 19 '14 at 16:22
  • @ChrisStratton I've finally managed to get root permissions for my native code but running 'am kill com.package.aaa' doesn't do anything. I've also tried with 'am force-stop package' but nothing happens. – caccolona Feb 20 '14 at 12:55
  • Either you are not running am as root, or that command is not intended to do what you want. This is not functionality which us supposed to be used outside of a testing setting. At this point you've apparently changed the question without providing details of what you are now doing, so it is unanswerable other than by speculation. – Chris Stratton Feb 20 '14 at 14:02

0 Answers0