Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test wifi connection via adb?

Im automating wifi off/on via adb.

I would either like to disable/enable wifi based on the test case

so far I have found good information here

However I want to test the connection before executing following command

adb shell am start -a android.intent.action.MAIN -n         com.android.settings/.wifi.WifiSettings adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23

Above command disables wifi if enabled, enables wifi if disabled. I want to first test the connection and take action if required. I am wondering if there is a way to do using adb command. This can be achieved programatically but I want it to be done through adb for making it more reliable.

Also following command works only if device is rooted

adb shell "svc wifi enable" 

Also following command launches test on screen but provides no info via adb

adb shell am start -n com.android.settings/.wifi.WifiStatusTest
like image 226
Venkatesh Avatar asked Jul 24 '15 07:07

Venkatesh


3 Answers

Below command will give you the internet status and connectivity mode(cellular or Wi-Fi)

adb shell dumpsys connectivity
like image 52
nramesh1990 Avatar answered Sep 21 '22 15:09

nramesh1990


To know everything about Wifi status of the device:

adb shell dumpsys wifi

To just know whether it's enabled or not:

adb shell dumpsys wifi | grep "Wi-Fi is"

To know more detailed status:

adb shell dumpsys wifi | grep "mNetworkInfo"

  1. If connected to a valid network, it shows "CONNECTED/CONNECTED". It also shows the name of the connected network.
  2. If wifi has been enabled but it is yet to connect to a network, it shows "DISCONNECTED/SCANNING".
  3. If wifi is disabled, it shows "DISCONNECTED/DISCONNECTED".
like image 32
Atish Sanyal Avatar answered Sep 19 '22 15:09

Atish Sanyal


If you're trying to determine whether or not WiFi is turned on you can run adb shell settings get global wifi_on which returns 1 if it's on and 0 if it's off.

If you have multiple devices connected you can run adb -s [UDID_HERE] shell settings get global wifi_on to get the WiFi status of an individual phone. To find the UDID you can run adb devices.

like image 39
Josh Correia Avatar answered Sep 17 '22 15:09

Josh Correia