Is there an ADB command to enable/disable mobile data?(Rooted Device) - android

I'm looking for an adb shell command to enable/disable mobile data. The app is only being tested on rooted devices so I have adb root privileges. I looked around and found that wifi can be enabled/disabled with:
$ adb shell svc wifi enable
$ adb shell svc wifi disable
These work for me but I wasn't able to find anything for mobile data.
Any reference to a list of adb shell svc commands that can be performed would be appreciated as well. I know there's a list of key input commands from this question and obviously I'm aware of the developer page but there's no mention of svc.
Lastly, what is svc?

I found the answer to my question:
To enable mobile data:
$ adb shell svc data enable
To disable mobile data:
$ adb shell svc data disable

Related

ADB shell bluetooth commands [duplicate]

I am working on automating bluetooth actions on android like enable/disable, pairing/unpairing devices etc.
I want to know how to interact with unrooted android device for above mentioned bluetooth operations using adb shell commands or android intents.
For example, i want to know which devices are bluetooth paired with my android phone using adb shell commands.
is it possible?
dumpsys is your friend:
Find your bluetooth service (must be running): adb shell dumpsys -l
Mine is bluetooth_manager, so I run: adb shell dumpsys bluetooth_manager
In output you can find section "Bonded devices"

How to disconnect from a wifi network through adb?

I understand we could turn off Wifi through the "adb shell svc wifi disable" command but I don't want to completely turn off Wifi. I want to disconnect from a particular ssid through adb. Is it possible?
Edit: I got a notification saying this question is identified as a dupe of this question: How to turn off Wifi via ADB?. It actually is not. As mentioned clearly in the first paragraph, I don't want to turn off wifi but want to simply disconnect from a particular network. This is like long pressing a network and tapping "Forget network". Essentially I want to simulate a condition of the user moving out of a wifi network without having to turn off wifi.
If you have root access, you can make it by using wpa_cli.
First, you can use the wpa_cli`s list_networks to get the network id of the network that you want to disconnect
$ adb shell
# wpa_cli
> list_networks
**network id** / ssid / bssid / flags
0 001aLinksys14081-2G any [CURRENT]
and then you just need to run the wpa_cli remove_network {network id}, where the {network id} parameter is the one that you got on the list_networks method.
One option is to use cmd wifi. For disconnecting from a Wi-Fi network, you can "forget" it like so:
adb shell cmd wifi list-networks
adb shell cmd wifi forget-network <networkId from list-networks>
You can view the help documentation for cmd wifi with:
adb shell cmd wifi -h
This command did it for me
docker exec -it $container_id /bin/bash -c "cd /root//shared-tools/android-sdk/platform-tools; ./adb shell 'svc wifi disable'"
You cannot. But, this will not be enough to satisfying your question, there is tricky way to connect to "other wifi". (Yes, it is not disconnect)
Install an app, and send command to the app via adb.
See this: https://stackoverflow.com/a/37303412/850347
I already build an app which does so and it's available here: https://github.com/steinwurf/adb-join-wifi
Once the app is installed, a wifi access point can be joined using the following ADB command:
adb shell am start -n com.steinwurf.adbjoinwifi/com.steinwurf.adbjoinwifi.MainActivity -e ssid [SSID] -e password_type [PASSWORD_TYPE] -e password [WIFI PASSWORD]
See this: https://stackoverflow.com/a/37303412/850347

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
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"
If connected to a valid network, it shows
"CONNECTED/CONNECTED". It also shows the name of the connected network.
If wifi has been enabled but it is yet to connect to a network, it shows "DISCONNECTED/SCANNING".
If wifi is disabled, it shows "DISCONNECTED/DISCONNECTED".
Below command will give you the internet status and connectivity mode(cellular or Wi-Fi)
adb shell dumpsys connectivity
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.
This would only tell you if there is internet access but you can do:
adb shell ping www.google.com
adb shell dumpsys wifi | sed -n '1p'
is faster and safer than
adb shell dumpsys wifi | grep "Wi-Fi is"
because the output of dumpsys wifi contains the system logs that may have been contaminated by other applications
Atish's answer was working fine until Android 11/R. For this OS onwards, I recommend using Abhishek's suggestion:
adb shell dumpsys wifi | grep "curState=ConnectedState"
Not perfect, but you could dump UI layout and then search for ON/OFF text like this (bash):
adb pull $(adb shell uiautomator dump | grep -o '[^ ]*.xml') ui.xml
grep 'text="OFF"' ui.xml
if [ $? == 0 ]; then
# Turn WIFI on
fi

How to control bluetooth operations using adb shell?

I am working on automating bluetooth actions on android like enable/disable, pairing/unpairing devices etc.
I want to know how to interact with unrooted android device for above mentioned bluetooth operations using adb shell commands or android intents.
For example, i want to know which devices are bluetooth paired with my android phone using adb shell commands.
is it possible?
dumpsys is your friend:
Find your bluetooth service (must be running): adb shell dumpsys -l
Mine is bluetooth_manager, so I run: adb shell dumpsys bluetooth_manager
In output you can find section "Bonded devices"

Getting Error while configuring ADB

Trying to configure ADB so that I can debug it via wifi, I have checked on Google but not getting proper resolution.
Tell me what to enter in port address, device ip.
Moreover setprop service.adb.tcp.port command is running when i give space between set and prop, bit confuse...
Seeking for help
I got the following article, and wanted help in the same context.
disconnect device from usb then tell it to listen on 4455
adb tcpip 4455
restarting in TCP mode port: 4455
connect to the device using a specified ip:port. my device is using wifi
adb connect 192.168.1.103:4455
connected to 192.168.1.103:4455
now do normal adb commands over tcp
adb shell
when your done, you can put it back in USB mode
adb usb
restarting in USB mode
Help me
These are commands for the shell of the android device, not for the host system.
Type adb shell to get the device's shell and then enter them. If you get back to the windows shell prompt you are in the wrong place.
However those commands may not be effective on a secured device anyway.
setprop is an Android command and is meant to be used in a terminal after su on the device (you can do adb shell setprop ... but when you adb shell stop adbd you'll loose your device connection). The easier way if already connected via USB is adb tcpip 8600 and then adb connect IP_OF_PHONE:8600 -- but this will only work if adb shell will get you a root prompt (starts with # and not $). Be aware that anyone on your wifi network can access your device!

Categories

Resources