I'm writing a python script that makes calls to adb to perform JUnit tests. I've used 'adb get-state' and 'adb wait-for-device' to wait for when the emulator is booted and ready to go, but for some reason, both of these kick off too early. After these functions return, I get this error when I start to run my tests:
android.util.AndroidException: Can't connect to activity manager; is the system running?
Is there a way I can get the status of the activity manager? If I could just poll that status that should be sufficient.
Thanks!
adb wait-for-device tells you if the adbd on the device is responsive. However, that it a linux-level daemon on the device, well below the level of the android platform which is normally started after (except in the case where ADB has just been enabled from the settings menu).
Particularly on emulators, starting up the java-level android runtime is a lengthy process, so there can be a period of seconds to minutes when adbd is responsive, but there is no ActivityManager to talk to.
After adb wait-for-server, putting an attempt to do whatever you are trying to do (presumably run the 'am' command) in a loop with a one second delay and checking the output may be the simplest solution.
Related
I'm having a problem keeping scripts running (in background) through ADB on my non-rooted Mate 10 after the phone has been unplugged.
I've tried to use the nohup command which has always worked for me with other Android devices, to no avail. I know that nohup only protects from SIGHUP and SIGQUIT signals and so the device might be sending a different signal to kill the process.
I have also tried spawning a child task which runs the script to try to 'hide' the spawned process and tried calling /system/bin/sh to spawn a shell within a shell which have both also failed.
Does anyone have some ideas on alternatives to nohup for non-rooted Android OS or any other ideas on how to solve this issue?
Edit: disown and screen are not present in the Mate 10's shell so they cannot be used.
there are several options:
disown
You can combine disown and & to push your script to the background
$ disown [your_command] &
[your_command] can be checked by the jobs command. Once typed you will
$ jobs
[1]+ Running [your_command]
screen
Is a virtual terminal. Screen will keep running even if your session gets disconnected. When you reconnect to the server you can reconnect to the screen session and everything will be as if nothing happened.
link: gnu screen manual
background push
[your_command] &>/dev/null &
&>/dev/null redirects all the command output to a black hole.
& runs the process in the background.
I want to measure the current consumption of my device while running different test cases. (Have a tool to measure current consumption).
I have automated the test cases using UIAutomator. But for running the script I have to connect the device via USB or WiFi. In both cases current consumption of the device gets higher.
Is there any method by which I can stop the current coming from USB and run the script?
I have tried:
adb shell dumpsys battery set usb 0
This stops the charging through USB but the current reading is still more, because I think device is still getting the current it only stops the battery charging.
Connect with ADB over wifi. Start a test case that doesn't do anything and measure current increase (consider doing this multiple times). That's your baseline. When you run the real test, however much the current increases above that is due to the test.
My problem is solved. I used:
adb shell
uiautomator runtest projectname.jar -c pkg.cls &
Because of &, the script keeps running even when I disconnect the USB cable
this is my steps:
adb connect 'my android IP address'
connected
adb reboot //in this step my phone is rebooting and the process is hang.
What can be the problem, is there any fix or workaround?
When i working on ADB with USB cable it's working well.
thanks
Somewhat speculation, but adb reboot may shut the phone down abruptly enough that the ADBD on the phone never gets to properly close the TCP connection to the ADB server on your development machine. This would be a lot like the way "hung" TCP connections can result from pulling out a network cable - TCP is designed to survive intermittent communication failures, and so doesn't give up on the possibility of the other end answering until a fairly substantial amount of time (in human terms) has passed.
It's entirely plausible that the ADB server isn't written to take into account the combination of two features which are even individually a bit on the obscure side - TCP connection with rebooting.
If that is the case, your practical options may be to have something kill the ADB server immediately after issuing the reboot, or else modify ADB (it's open source after all) to more intelligently handle this, for example automatically disconnecting after a second or two of non-response if it has issued a reset command.
We have test suite where adb clients connect to multiple android devices.
Our test suite raises these requests to connect, get device state and run applications in it.
I would like to simulate a scenario where adb server hangs.
I tried issuing "adb kill-server" but any adb request from client starts the adb server.
Is there anyway we can stop the adb server from listening to adb client requests ?
Of course there is a long way of compiling adb service and changing the code our self.
But any easy way to get this done?
Do you need to still have a connection (that doesn't respond to commands), or is it fine to kill the connection altogether? Sounds to me like killing the connection would be fine since you say that you tried adb kill-server.
In that case, how about trying to connect to the device in TCP/IP mode without having set up the adb server to listen on a network port? I.e. something like:
adb tcpip 12345
Another suggestion would be to actually disable adb interface totally in the device. While this may or may not stop the adb server, you would still get your desired result i.e no connection for adb clients.
The way this could be done is that on a ROOTED device, do
adb shell
su
echo 1 > /sys/class/android_usb/f_adb/on
This one is what I could do on an HTC Vivid which I have on hand. For other devices, the paths might be different but they should all be similar. Once your reboot the phone, adb starts working again.
How to find what service running on background on Android?
like input method service, ....
Using adb or terminal on android device ?
Could I use "top" or "ps" command?
Maybe I have to ask in another way?
Does the service be presented as one "process", then we can use "ps" or "top" command to find it?
A more precise way to show running services is by using dumpsys.
To get a list of all running services:
adb shell dumpsys activity services
To show the status of a particular service:
adb shell dumpsys activity services <partial-service-name>
For example, if your service name is com.example.MyService:
adb shell dumpsys activity services MyService
If you are running the emulator or have a connected device, you can launch adb with 'adb shell' from the command line and you can run all those linux binaries like top and ps.