When I put this line in my test app,
Runtime.getRuntime().exec("uiautomator dump"), no .xml file was dumped. I am pretty sure I checked the correct location.
I tried to debug my app by putting a break point. When it reaches the break point, I adb shell on terminal to get into the device, and then manually run uiautomator dump from terminal, then it says killed, no .xml file was produced either.
adb shell uiautomator dump only produces .xml file when I killed my app, and run this command from terminal.
Is this a sort of permission or accessibility problem?
You can't use adb shell uiautomator dump while a test is running.
You can call UiDevice.dumpWindowHierarchy(..) from inside your test instead.
Related
I have an android 4.2 phone on which I wish to run the following script:
su
setprop service.adb.tcp.port 5555
stop adbd
start adbd
If I put it into and .sh file, and have the SManager app to run it, it does nothing, no error nothing, just get back the console. I allow root access for the app.
If I manually type it into Terminal Emulator, then it works.
How can I run .sh files easily (without much typing) other then SManager, as its obviously not working.
Thank you
All my scripts was ctrl c ctrl v to sh files.
Some windows spec char went into the script, and it did nothing.
As soon as i typed the whole thing in on touchkeyboard,
AND allowed Root run within SManager (it was not enough to start it as rooted only),
it came alive.
Thanks!
I want to encapsulate screenrecord command by java code and invoke it in android application.
Luckly I can start and kill the screenrecord process with root Process, and get a valid mp4 file.
I know that I can run screenrecord command under ADB without root, so I think I could do the same thing via java code which invoke a shell, but no luck, the command will produce a file but the file size is zero.
Am I doing something wrong?
ADB has the privilege: AID_GRAPHICS, which normal application doesn't have.
Can anyone tell me how can we get adb logs using eggPlant automation tool.Actually i want to have adb logs for my device when running eggPlant scripts.
Please help me out in this situation.
Actually, the previous answer is incorrect as adb command support does exist in eggPlant. There are ways to get adb logs in eggPlant. Here's how:
adb logcat is the command that enables getting adb logs. (Warning: This will print a ton of info!)
You need a way to execute adb logcat within eggPlant. This is accomplished using the shell command
On some systems (I am using eggPlant for Windows) you need to dump the output of the shell command to a file and then read the file back into a variable.
I guess there is no such command or something else.eggPlant identifies only object or script to execute the command.
I have an Android phone that has only su binary installed and it works, meaning I can adb shell into the phone and run an 'su' command and I will be root.
When I try to run a command via code, it doesn't seem to work no matter which way I try to run it. I've tried many different variants of the following command.
Runtime.getRuntime().exec("su -c ps");
When I run this command on another rooted phone with a Superuser.apk or SuperSU.apk app installed, I get a dialog asking if I want to allow it to run with root permissions. When the apks are not there, it never asks and the command never works.
I've tried installing the apks on the first phone but they don't seem to do anything. So, as the original question asks --> Is there any way to run the elevated command from within the app without the SU apps installed?
It might be because you need to pass the commands to su as parameters like this:
su -c 'ls -l'
Or you might need to specify the full path to su, but I don't see why it wouldn't work the way you have it:
Runtime.exec("/system/bin/su -c ps")Or maybeRuntime.exec("/system/bin/su -c \'ps\'")
Try checking the output of this command too: System.getenv("PATH")
Another variant could be Runtime.exec("su -c \'ls -s \'")
Make sure you don't forget to escape the single quotes as they are part of the actual String.
Thats the way that I've found works most consistently, and it has also worked on devices that don't have Superuser or SuperSU installed, as those apps only listen for the Broadcast that is sent out when an application tries to run a command as root. #Boardy SuperSU and Superuser intercept the broadcast and so act as a middle man between the app and root privileges, but its not necessary for a rooted device. It IS necessary if you want to have more control over the applications that are running commands as root, but even then it still only limits you to deciding which applications, not which commands, are given root privileges.
Also, you might wanna take a look at RootTools and more specifically, the RootTools.isAccessGiven() command, which requests root privileges for your app.
Source: Launch a script as root through ADB
Not all versions of an 'su' for Android will accept a command to execute from the command line parameters.
Where they do not, you will need to let 'su' launch a privileged shell, obtain its input file descriptor, and pipe command(s) into that. This has been covered numerous times here on Stackoverflow.
I believe you would need to have the SU apps installed as they are what provide the user the question as to whether the app should be allowed to run as root or not.
You should be able to do this.
try :
adb root shell ls -l
So I have a need to modify the Xoom tablet iptables rules and I created a shell script to do that, and it works if I run it directly from the shell but doesn't seems to work if I have an (Java) activity run it.
I must be missing something, can you guys give me some clue?
adb shell has root permissions, whereas Java doesn't.
in adb:
# id
uid=0(root) gid=0(root)
You can get your user id in Java to see what you're running as.
If you have access to the OS build, then you can raise your application level to system, but that still won't give you root. Here's an SO post on that if you're interested.