开发者

What are the steps to get root access in android emulator for rebooting through code?

开发者 https://www.devze.com 2023-03-08 18:25 出处:网络
How do I get root access in order to reboot the emulator? How do I kill all开发者_StackOverflow unwanted processes along with the child process?You have already root access to your emulator. To kill a

How do I get root access in order to reboot the emulator? How do I kill all开发者_StackOverflow unwanted processes along with the child process?


You have already root access to your emulator. To kill a process and all childs just use the device view in eclipse, select the emulator theere and chose which process you want to kill.

I have no idea on how to restart from code if you are looking for that. Rebooting the device should be easy: just close it and than boot it up again.

(I have the feeling I don't really get what you want...)


Most su binaries for Android depend on SuperUser.apk (available for free through the market). The su binary uses this apk to ask the user if it's ok to do whatever is being requested (and the user can opt to remember the answer). If you're using such a su, you need to also have that apk.

Once the pieces are in place, your application can spawn a process with the right arguments... something like argv[0]="/path/to/su", argv[1]="-c", argv[2]="(whatever command you want to run)", argv[3...n]=arguments to your command.


To kill a process in the command line, simply issue the following command line on the shell:

kill-9 YOUR_PID

If you know the name of the process, but not the pid, use

kill -9 $(pidof NAME_OF_PROCESS)

You can also use it on your code:

Runtime.getRuntime().exec("kill-9 YOUR_PID");

Check the man page for more details: http://unixhelp.ed.ac.uk/CGI/man-cgi?kill


ps-after rebooting i also wanted to kill all unwanted process except my specific app and its child process alone to run in emulator.

If that is really what you want to do - repurpose an android build as a generic embedded linux, then the way to go about it is to regenerate a ramdisk image (which android packs onto the kernel) containing an init.rc which launches your application rather than the android native services and (java-esque dalvik) android runtime. Rebuilding the ramdisk requires a unix-like OS and that arcane cpio command line which you can find in web search. I'd be tempted to leave the startup of ADB in there so you can debug the various things which will go wrong.

For testing purposes simply typing "stop" from the adb shell will shut down the android runtime and give you a UI-less virtual pocket linux box. There will still be some native services running but they may be more help than harm. Ultimately you may need to set OOM killer values on the things you add, though without the runtime up that may not be an issue in the near term if you don't consume much memory.

Or if what you want to do is have a very locked down and limited UI built on top of the android runtime, you would instead develop a custom home screen , test this on an unmodified emulator, and then deploy it on a build customized to lack any means of installing other applications.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号