I need to forward a port on an android emulator, right now I had to type the command every time:
adb forward tcp:23946 tcp:23946
Is there any way to make this automatic? I tried to replace adb with a script but that command won't work until the device is up and running.
Any ideas?
Based on this answer (which I've tested and works, though it wasn't for a scenario like this one), you could simply write a script that waits until the emulator is booted.
Something like (pseudocode, don't know which platform you're on) :)
emulator #emulator-name
while ('adb shell getprop init.svc.bootanim' == "running") sleep(10s)
adb forward tcp:23946 tcp:23946
Related
I am trying to make a small shell script that would pass some adb commands, reboot the device, and once the device reboots, again pass some adb commands.
I was thinking of passing adb devices at regular intervals through out the period the device is rebooting so as to know when the next adb command could be passed(not sure there are any other better methods for doing this). For this purpose I need to check the response of each adb devices command. Is there any method to read this response?
I am a novice in shell scripts. Kindly excuse it the method I am adopting to achieve this task is not correct.
Any help or suggestions would be much appreciated.
You can make an if statement from the response:
device=$(adb devices)
while true
do
sleep 5
if [ "$(adb devices)"="$device" ];
then
echo "device rebooted"
break
fi
done
This would check ten times in an intervall of 5 secs.
I am trying to make integration tests which test Fingerprint.
According to google doc to invoke finger touch on emulator from terminal you need to use:
adb -e emu finger touch < finger_id >
And this works for me. In my case id is 45146572. However in test you cannot input this command on your own as it should be done automatically.
I've been trying various things to make a workaround (eg. trying to understand how app is receiving information from sensor - maybe by some kind of broadcast intent etc.) and for now I still don't know how to do it.
I know that UiAutomation and UiAutomator's class - UiDevice has method
executeShellCommand
and I think that this might be helpful. But even if I do something like:
getUiDevice().executeShellCommand("-e emu finger touch 45146572");
My device won't react to it (I've tried on both classes and various threads). I believe this is caused by the fact executeShellCommand is running already inside shell. So it's like I've typed to terminal
Kamils-MacBook-Pro:~ F1sherKK$ adb shell
root#generic_x86_64:/ #
And I guess that's the problem, because google wants:
adb -e emu finger touch
not
adb shell -e emu finger touch
My knowledge about shell might be not enough maybe. I've looked through all documentation many times.
Do you have any idea how to call finger touch from shell?
I believe you have to be using different format of password. It should be "aa11aa" which is LetterLetterNumberNumberLetterLetter.
I am building an Android application that is designed to help with load testing. When the app launches we are sending extra values to the main activity so that we can control what kind of load each app executes. Currently, we are doing this, scripted, via the terminal using adb directly which is pretty straight forward:
adb shell am start -e key1 value1 -e key2 value2 -n bla.bla/bla.MainActivity
For debugging purposes, I'd like to be able to do this from IntelliJ but I don't see anything in my run configuration screen that let's me pass anything to adb. Is this possible?
Might be waaaaaay late on this one, but you can always try the BashSupport plugin on the IntelliJ Repo.
What I'm doing:
I've built GNU emacs for native use on an phone.
I run emacs in daemon mode on the phone, so I connect to it anytime with emacsclient, to continue working with regular files, run processes, etc.
When logging in from the terminal on the phone, I'm currently user 10157, everything works:
$ id
uid=10157(10157) gid=10157(10157)
groups=10157(10157),1015(1015),1023(1023),1028(1028),3003(3003)
When I connect via ssh to the phone from a PC (I use DigiSSHd on the phone), it logs me in as a regular user 10282, everything works:
$ id
uid=10282 gid=10282 groups=1015(1015),1023(1023),1028(1028),3003(3003)
Emacs runs fine etc. However, this way I can't connect via emacsclient to the emacs process running under user 10157. This is desirable, since I don't want to start two emacs processes, since I want to continue working with files that I have open in emacs under user 10157.
Therefore:
$ su - 10157
Fine, I can run emacs etc. However, I cannot access the web.
$ ping -c1 google.com
You must have internet permissions to use ping. Aborting.
$ id
uid=10157(10157) gid=10157(10157) groups=10157(10157)
Thus I'm no longer in group 3003, necessary for internet access, besides other groups also.
Why does this group info get stripped, and how can I remedy this, so I can continue accessing the web when su as this user under ssh?
When i run the command:
busybox --list
I don't see su in the list.
su --help
shows Superuser.apk in the help text. It means su is provided by Superuser app.
I followed the steps described by you and i could su as another user and still have internet permission as shown below.
I have the following apps installed.
BusyBox v1.18.5-Stericson
Superuser v3.0.7
Terminal Emulator v1.0.45
SSHDroid v1.9.6
Suggestion:
I think the issue is with su on your device. You may try this one.
https://play.google.com/store/apps/details?id=com.noshufou.android.su
If i just use adb shell without running SSHDroid still i can su as another user with internet permission.
Note: The BusyBox id command doesn't show groups information always.
According to the standard man page for su (from a linux box)
When - is used, it must be specified as the last su option. The other forms (-l and --login) do not have this restriction.
Based on that, try
$ su 10157 -
I'm probably missing something here because this seems way too obvious but why not just 'sudo -u 10157' your emacs program?
you'd still have access to the net and your emacs would be working. or did I miss something important?
Permissions are not environment variables that can be inherited via su -.
Moreover, gid are are hard coded and their associations with each APP uid cannot be changed after installation.
10157 should be the uid of the DigiSSHd application, thus you could try to rebuild it after changing the AndroidManifest.xml to require the proper permission.
You can find something useful here and here.
The same should work for BusyBox (see here).
However, you could open some security hole by enabling NETWORK access through such applications.
Please guide me about this error
2011-05-02 18:37:20 - SimpleOptionMenu] The connection to adb is down, and a severe error has occured.
[2011-05-02 18:37:20 - SimpleOptionMenu] You must restart adb and Eclipse.
[2011-05-02 18:37:20 - SimpleOptionMenu] Please ensure that adb is correctly located at 'F:\android-sdk-windows\platform-tools\adb.exe' and can be executed.
It was working fine and now i am getting this error . I have restarted eclipse but nothing happed . Thanks
When I faced with this problem, resetting adb is usually the solution.
If this not solves, unplugging-replugging the device works. I never have had to restart Eclipse.
By the way, Reset adb option can be found in DDMS(Dalvik Debug Monitor Server)'s Devices tab.
I have had this error from time to time too, and restarting Eclipse has fixed it. My best guess is that you had the misfortune of getting the error twice in a row. Try restarting again and see if it goes away.
Writing this post has had the unfortunate effect of making me realize that the Android SDK bears a striking resemblance to Windows.
I do not know the reason but restating up my system worked for me :) !!!
I just posted the response below here:
adb kill-server not responding?.
I am duplicating it here too as Google considers this thread as one of
the top hits.
If zombie adb process is not the issue i.e. there's no adb.exe in the task-manager list, the problem is usually adb ports e.g. 5555, 5554, 5037 etc., being taken by other applications.
Solutions:
On all Windows: find the process taking one of those ports using netstat -bn and kill it from task-manager Ctrl+Shift+Esc is the shortcut.
On Windows 7 and 8: there's this new tool called Resource Monitor. It'll also allow you to find out the blocked port and blocking process under the network tab.
On Linux: the similar is done with netstat -pn. Feel free to use your grep foo as needed and kill the blocking process with kill or pkill.
Change Default ADB Port: Apparently default ADB port can be changed as described here by setting up an environmental variable before launching ADB. Give it shot. It'll allow more flexibility if you don't want to kill the blocking processes.