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.
Related
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
I send debug commands via adb in windows to my rooted android device.
command is in a loop:
adb shell input tap 200 200
but it seems there is a second or fewer delay in each command to run in device.
is there any way to send commands on device without delay or decrease it?
Note: I used tasker and result was same as adb in windows.
There is no delay "between" the commands. It just takes about a second (depending on the device) to run the input command.
I have made a mistake somewhere in my code that my Android app crashes when I switch off the network in the emulator while the app's HTTPClient is making some request.
But I cannot debug it, because when I switched off the network, I also lost the ADB connection. Thus I cannot see what exception is causing the crash.
I have tried switching off the network by:
F8
Set 'Data' to 'Unregistered' or 'Denied' in DDMS Emulator Control
I can put my Mac offline and ADB will stay up, but unfortunately I cannot reproduce the crash that way.
Is there a way to turn off network in the emulator, while keeping ADB alive? I basically need access to the LogCat entries.
Thanks!
You can run logcat from the device instead of from ADB and redirect it to a file for offline reading.
adb shell logcat [-v threadtime] > /sdcard/mylogs/logcat.log
Instead of
adb logcat [-v threadtime]
Then you can get the file when you reconnect to the device.
On linux this is pretty simple with iptables firewall. I suppose you trying to debug api calls so just block api host:
iptables -I OUTPUT -d api.example.com -j DROP
Sure you can do the same thing with Mac or Windows firewall.
You could always put the device into airplane mode, that will still allow you to connect over adb but not give the emulator a connection to the internet. You can also turn off data through eclipse via the emulator control section in ddms by putting in unregistered/denied to the data drop down.
I know this is old question but someone might use find for this.
My setup
Eclipse Kepler with emulated android 4.4
If you want to keep your adb alive and network turned off, you can try this.
Start emulated device
Activate flight/airplane mode
Restart Eclipse
It should work! Check DDMS perspective for attached devices or use adb devices 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.
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.