ADB loses device connection after setNetworkConnection API is used

Hello Appium Community,

I’m trying to test some features of an app while it’s offline or in airplane mode. I’m trying to use the setNetworkConnection method to toggle my devices wifi connection during a test. However, the ADB server loses connection to my device while this method is run, my test is stalled and eventually fails.

Is anyone having trouble with this as well? Can anyone help me out?

Sincerely,
Michael

Here is a snippet of my Appium logs:

3204d04ec7bxxxxx[debug] Responding to client with success: {"status":0,"value":true,"sessionId":"a6978b91-0c14-4d12-9ea0-c8b302a8e185"}
info: <-- POST /wd/hub/session/a6978b91-0c14-4d12-9ea0-c8b302a8e185/element/43/click 200 538.511 ms - 76 {"status":0,"value":true,"sessionId":"a6978b91-0c14-4d12-9ea0-c8b302a8e185"}
info: --> POST /wd/hub/session/a6978b91-0c14-4d12-9ea0-c8b302a8e185/network_connection {"name":"network_connection","parameters":{"type":0}}
info: Setting network connection
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx shell "settings put global airplane_mode_on 0"
info: [debug] Stopping logcat capture
info: [debug] Logcat terminated with code null, signal SIGTERM
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx kill-server
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx wait-for-device
info: [debug] UiAutomator exited
info: error sending command, reconnecting device and retrying: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx wait-for-device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx devices
info: [debug] 0 device(s) connected
info: [debug] Could not find devices, restarting adb server...
info: [debug] Retrying restartAdb
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx kill-server
info: [debug] Getting connected devices...
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx devices
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx kill-server
info: [debug] Getting connected devices...
info: [debug] executing: "/Users/michael/Desktop/android/sdk/platform-tools/adb" -s 3204d04ec7bxxxxx devices
info: [debug] 0 device(s) connected
3 Likes

I’m running on Mac OSX 10.9.4 using a physical Samsung Galaxy Tab 8 and Appium server version 1.2.2

-Michael

@Michael
I encountered the same issue on Android after I updated to Java client 2.0.0. I am using Appium 1.2.3 and Samsung Galaxy S4.

This causes all the following tests to fail. It was working fine with Java client 1.7, I guess the update caused it.

The exact exception details are:

org.openqa.selenium.WebDriverException: undefined status object (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 40.94 seconds
Build info: version: ‘2.43.1’, revision: ‘5163bceef1bc36d43f3dc0b83c88998168a363a0’, time: ‘2014-09-10 09:43:55’
System info: host: ‘IT95MXR’, ip: ‘192.168.56.1’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_20’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{rotatable=true, networkConnectionEnabled=true, acceptSslCerts=true, platformVersion=19, automationName=selendroid, browserName=selendroid, takesScreenshot=true, javascriptEnabled=true, platformName=android, handlesAlerts=true, version=0.10.0, platform=ANDROID}]
Session ID: 6e89048e-99cd-06d5-bce2-31ffd6cc1082
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:176)
at io.appium.java_client.android.AndroidDriver.setNetworkConnection(AndroidDriver.java:142)

It might be related to this issue:

Hello Hassan,

Thanks for the response, I was hoping I wasn’t the only one seeing this. I would like to make a correction my device was Samsung Galaxy Tab 3 (8 inches) running OS version 4.4.2.

Here is how the exception in my console looks like:

org.openqa.selenium.WebDriverException: undefined status object (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 49.35 seconds
Build info: version: '2.42.2', revision: '6a6995d31c7c56c340d6f45a76976d43506cd6cc', time: '2014-06-03 10:52:47'
System info: host: 'N/A', ip: 'N/A', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9.4', java.version: '1.7.0_55'
Session ID: 8bdcedc5-99f0-4c6b-86d1-7c485c46bdc7
Driver info: io.appium.java_client.AppiumDriver
Capabilities [{platformVersion=4.1, platform=LINUX, javascriptEnabled=true, databaseEnabled=false, browserName=Android, webStorageEnabled=false, networkConnectionEnabled=true, desired={}, locationContextEnabled=false, warnings={}, takesScreenshot=true}]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
	at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:102)
	at io.appium.java_client.AppiumDriver.setNetworkConnection(AppiumDriver.java:606)
	at common_classes.android.AndroidDeviceCommands.turnOffConnection(AndroidDeviceCommands.java:53)
	at Module_View_Tests.module_download_sequence_1(Module_View_Tests.java:113) 

I’m seeing this while using Java Client 1.7, so I’m surprised to hear it was working for you on this version.

@Michael

It was working on Samsung Galaxy S4 and at the same time not working with Samsung Galaxy Tab2(10.1)… both using Java client 1.7… This is included in the bug report I referred to earlier.

After switching to Java client 2.0.0, both devices stopped working. I guess the cause of the problem might have been around for a while prior to 1.7 maybe.

@Hassan_Radi

Today, I got my hands on a few extra devices and tried running the test. The test seems to successfully pass (and toggle the connection) when I use a LG Nexus 4. All the other devices I used were made by Samsung and failed the tests. So I’m thinking the problem might be manufacturer specific. I’ll keep looking into it, but If you can please test using non-Samsung devices and let me know how that goes for you.

Sincerely,
Michael

But it was already working on Samsung S4 before, it’s not a problem with the manufacturer I guess otherwise it shouldn’t have worked before. Sadly all the devices I have are Samsung devices, but I will keep that in mind in case I managed to get my hands on one.

I tried to run Appium from source and it worked with a Samsung Galaxy S4 device and failed with another Samsung device (Tablet tab2 10.1), so I guess it’s not related to a device manufacturer as you thought. I think it’s more related to the API level that is used on the device.

ADB didn’t lose connection with the device, but the netwrok connection’s state wasn’t changed as expected and that’s what caused the test to fail.

Appium’s log:

2014-10-09 18:26:17:136 - info: Getting network connection
2014-10-09 18:26:17:136 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 shell “settings get global airplane_mode_on”
2014-10-09 18:26:17:194 - info: [debug] Responding to client with success: {“status”:0,“value”:1,“sessionId”:“25842f53-4291-0623-77d7-f3cd60d09b03”}
2014-10-09 18:26:17:195 - info: e[37m<-- POST /wd/hub/session/25842f53-4291-0623-77d7-f3cd60d09b03/network_connection e[39me[32m200e[39me[90m 9684.573 ms - 73e[39m e[90m{“status”:0,“value”:1,“sessionId”:“25842f53-4291-0623-77d7-f3cd60d09b03”}e[39m
2014-10-09 18:26:17:405 - info: e[37m–>e[39m e[37mGETe[39m e[37m/wd/hub/session/25842f53-4291-0623-77d7-f3cd60d09b03/network_connectione[39m e[90m{}e[39m
2014-10-09 18:26:17:406 - info: Getting network connection
2014-10-09 18:26:17:406 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 shell “settings get global airplane_mode_on”
2014-10-09 18:26:17:475 - info: [debug] Responding to client with success: {“status”:0,“value”:1,“sessionId”:“25842f53-4291-0623-77d7-f3cd60d09b03”}
2014-10-09 18:26:17:476 - info: e[37m<-- GET /wd/hub/session/25842f53-4291-0623-77d7-f3cd60d09b03/network_connection e[39me[32m200e[39me[90m 70.861 ms - 73e[39m e[90m{“status”:0,“value”:1,“sessionId”:“25842f53-4291-0623-77d7-f3cd60d09b03”}e[39m
2014-10-09 18:26:17:481 - info: e[37m–>e[39m e[37mPOSTe[39m e[37m/wd/hub/session/25842f53-4291-0623-77d7-f3cd60d09b03/network_connectione[39m e[90m{“name”:“network_connection”,“parameters”:{“type”:1}}e[39m
2014-10-09 18:26:17:481 - info: Setting network connection
2014-10-09 18:26:17:482 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 shell “settings put global airplane_mode_on 1”
2014-10-09 18:26:17:550 - info: [debug] Stopping logcat capture
2014-10-09 18:26:17:555 - info: [debug] Logcat terminated with code null, signal SIGTERM
2014-10-09 18:26:17:555 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 kill-server
2014-10-09 18:26:17:604 - info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
2014-10-09 18:26:17:605 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 wait-for-device
2014-10-09 18:26:21:690 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 shell “echo ‘ready’”
2014-10-09 18:26:21:766 - info: [debug] Starting logcat capture
2014-10-09 18:26:21:807 - info: [debug] Forwarding system:8081 to device:8080
2014-10-09 18:26:21:807 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 forward tcp:8081 tcp:8080
2014-10-09 18:26:21:857 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 shell “am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true”
2014-10-09 18:26:22:582 - info: [debug] Stopping logcat capture
2014-10-09 18:26:22:584 - info: [debug] Logcat terminated with code null, signal SIGTERM
2014-10-09 18:26:22:584 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 kill-server
2014-10-09 18:26:22:638 - info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
2014-10-09 18:26:22:638 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 wait-for-device
2014-10-09 18:26:26:736 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 shell “echo ‘ready’”
2014-10-09 18:26:26:799 - info: [debug] Starting logcat capture
2014-10-09 18:26:26:844 - info: [debug] Forwarding system:8081 to device:8080
2014-10-09 18:26:26:845 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 forward tcp:8081 tcp:8080
2014-10-09 18:26:26:898 - info: Getting network connection
2014-10-09 18:26:26:898 - info: [debug] executing: “C:\AndroidSDK\sdk\platform-tools\adb.exe” -s c161f246b289770 shell “settings get global airplane_mode_on”
2014-10-09 18:26:26:961 - info: [debug] Responding to client with success: {“status”:0,“value”:1,“sessionId”:“25842f53-4291-0623-77d7-f3cd60d09b03”}
2014-10-09 18:26:26:962 - info: e[37m<-- POST /wd/hub/session/25842f53-4291-0623-77d7-f3cd60d09b03/network_connection e[39me[32m200e[39me[90m 9480.620 ms - 73e[39m e[90m{“status”:0,“value”:1,“sessionId”:“25842f53-4291-0623-77d7-f3cd60d09b03”}e[39m

2 Likes

I’m experiencing the same issue: set_network_connection works on a Nexus 7 (Asus), but it fails on a Nexus 10 (Samsung). I’m using Appium v1.2.4 from source and the Python client.

1 Like

@Hassan_Radi

I’m not sure the API level is the culprit. SetNetWorkConnection works on my LG Nexus 4(Android OS v4.4.4) and fails on a Samsung Nexus 10 (Android OS v4.4.4 ) .

Hi all ,
I am trying to do the same,can you please guide me how to exactly get the network status from the
device:I wrote the below code and itz not wrkin:

NetworkConnectionSettings ncs;
ncs.getnetworkconnection();
and then trying to print the same to console.

Hi,
Experiencing this issue as well, on both Nexus 4 (4.4) and Nexus 5 (5.0).
It looks like the command fails only if ‘autoLaunch’: False, which is weird but quite reproducible in my environment.

Hey
Did you find a solution to the problem?

@shvekiasaf, @asafge:

The bug consists of two parts:
1- Turning airplane on/off is done differently depending on the API level of the device as this topic suggests. This explains why it works on a certain device and not on another device with different API levels.
2- The fact that it works on a device with a certain API level and doesn’t work on another device with the same API level suggests that it might be a bug in the Appium server code which requires some research from their side to reach a solution.

Right now the Appium team has marked the bug as a requested feature and there is no indicator when it should be fixed.

The Stackoverflow topic I mentioned above has a universal solution that is supposed to work on all rooted devices regardless of the API level of the device.

2 Likes

Hi,

Is there a way in appium to throttle network speed it is getting from its wifi or data connection

I saw this —> public NetworkConnectionSetting(int bitmask)

but not sure how do it works

ADB loses device connection after setNetworkConnection method is invoked. in case when the appium is configured to pre-launch application.
I unchecked it in Appium settings and that worked for me.

@Hassan_Radi
I’m facing same problem…
Before working fine on Samsung s4, but suddenly stops working, have made no changes to complete setup and also working fine for all other device…
Do you have any solution for same?

Configurations:
Appium 1.3.4, java client 2.1, OS - windows, Device - Samsung S4, Android version - 5.0.1

@rashiatry
Sorry I don’t have any solution to this problem.

Hi! we have the same issue with appium java client 3.2.0 and appium server 1.4.8, and it’s reproduced on all our devices (we run tests on Nexus 5 with versions 4.4, 5.0, 5,1, 6.0). May be there is some progress on this issue?