views:

181

answers:

2

Is it possible to programmatically restart the phone from a application (service) running on top of the Dalvik VM?

If the SDK does not provide this functionality, then how about using the NDK and calling some functions provided by the kernel? I know this option is not preferred (not stable enough libs), but if it's the only option, I'll have to consider that as well.

+2  A: 

Hopefully not. :-)

If it were possible to restart the phone at will, a malicious app could quietly do it at random intervals and make your life unhappy.

The NDK does not provide you with any additional abilities here, because Android relies on process boundaries and Linux access rights for security, rather than a Java-language sandbox.

Why do you want to do this? Maybe there's some other way to accomplish what you're after.

fadden
Thanks for the reply. I pretty much need to reboot the phone, or that's the exact requirement. The app I'm working for is intented for testing applications on the phone. Reboot is meant to be executed after testing is finished in order to release all the resources. Another possibility would be to kill a specific Dalvik VM, but I don't know whether that is enough as a release process and is it any easier to implement than the complete reboot.
J Andy
Processes can kill *themselves* quite easily. If you control the relevant applications, they just need to accept a "die" message and call System.exit(). Killing other processes is only possible if the have the same user ID, which they only will if they were build and signed by the same developer.
fadden
Thanks. Do you mean to send these "die" messages as Intents or some other high-level means, or by sending signals as available from the kernel? What do you mean by user ID? The 'ps' command on the shell gives the user who started the process. Is there a higher level user ID?
J Andy
+1  A: 

I found the correct system calls in Linux that would do the trick and after hours of fiddling around with the NDK/JNI paths, I finally managed to call the function. The result was that I need super-user permission for that. I kind of guessed that this would be the case.

Is there anyway to overcome this problem? Other than rooting the phone, which I'm still trying to avoid.

It's still possible to reboot the phone with adb. I guess that communicates with ddmd or some other daemon, so could it be possible to somehow use the same functionality?

J Andy