简体   繁体   中英

How to execute adb commands programmatically in android

I manually rooted my emulator using following commands

adb shell mount -o rw,remount -t yaffs2 /dev/block/mtdblock03 /system
adb push su /system/xbin/su
adb shell chmod 06755 /system
adb shell chmod 06755 /system/xbin/su
adb install superuser.apk

It is successfully rooted and working su command but while closing emulator and again opening emulator then su command is not working. To overcome this one I want to create a sample app for execute above commands programmaticaly using

Runtime.getRuntime().exec();

Please can one help me how to execute above commands programmatically.

The emulator is rooted out of the box in that the ADB shell runs as root.

What you've done is not "rooted" it, but rather used that pre-existing root shell to install a common hack which will then let application programs run helper tasks as root.

But you cannot do this from an application on the device which does not already have the ability to launch a helper as root - so you are stuck with a circular dependency or chicken-and-egg problem of needing root in order to install a root helper.

You will not be able to do this on the device or even emulator without finding a security hole (or pre-existing intentional privilege escalation mechanism) to exploit.

However:

  • you could read up on how to make the emulator's state persistent, and do it manually only once

  • you could issue the commands from a script running on the develpment machine, rather than on the device/emulator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM