@@ -71,6 +71,8 @@ public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities){
7171 .put (SHAKE , postC ("/session/:sessionId/appium/device/shake" ))
7272 .put (COMPLEX_FIND , postC ("/session/:sessionId/appium/app/complex_find" ))
7373 .put (OPEN_NOTIFICATIONS , postC ("/session/:sessionId/appium/device/open_notifications" ))
74+ .put (GET_NETWORK_CONNECTION , getC ("/session/:sessionId/network_connection" ))
75+ .put (SET_NETWORK_CONNECTION , postC ("/session/:sessionId/network_connection" ))
7476 ;
7577 ImmutableMap <String , CommandInfo > mobileCommands = builder .build ();
7678
@@ -515,6 +517,36 @@ public MobileElement scrollToExact(String text) {
515517 return complexFind .scrollToExact (text );
516518 }
517519
520+ /**
521+ * Get the current network settings of the device.
522+ * This is an Android-only method
523+ *
524+ * @return NetworkConnectionSetting objects will let you inspect the status of AirplaneMode, Wifi, Data connections
525+ */
526+ public NetworkConnectionSetting getNetworkConnection () {
527+ Response response = execute (GET_NETWORK_CONNECTION );
528+
529+ return new NetworkConnectionSetting (Integer .parseInt (response .getValue ().toString ()));
530+ }
531+
532+ /**
533+ * Set the network connection of the device.
534+ * This is an Android-only method
535+ *
536+ * @param connection The NetworkConnectionSetting configuration to use for the device
537+ */
538+ public void setNetworkConnection (NetworkConnectionSetting connection ) {
539+ // the new version of the webdriver protocol is going forward with sending JSON message which look like
540+ // {name: "name of endpoint", parameters: "JSON parameters"}
541+ // this is for webdrivers which run on protocols besides HTTP (like TCP)
542+ // we're implementing that pattern here, for this new method, but haven't translated it to all other commands yet
543+ ImmutableMap .Builder builder = ImmutableMap .builder ();
544+ builder .put ("name" , "network_connection" )
545+ .put ("parameters" , ImmutableMap .of ("type" , connection .value ));
546+
547+ execute (SET_NETWORK_CONNECTION , builder .build ());
548+ }
549+
518550 @ Override
519551 public WebDriver context (String name ) {
520552 if (name == null ) {
0 commit comments