22

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?

Community
  • 1
  • 1
Patrick
  • 11,552
  • 7
  • 29
  • 41

1 Answers1

56

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
Patrick
  • 11,552
  • 7
  • 29
  • 41
  • 5
    If you run this command directly from shell or through terminal emulator you will need to get root privileges first with `su` command. – bizzz Oct 07 '15 at 11:07
  • @bizzz any tips on how to install `su`? – sdgfsdh Jul 22 '16 at 17:24
  • 3
    @sdgfsdh that can be a smooth or not so smooth process, depends on your phone really. Google something like your phone model + "root and install su" for instructions – bizzz Jul 24 '16 at 07:15
  • 1
    Works perfectly on 8.0, but doesn't work on 5.0 lollipop and previous versions. Do you have any idea, how can I fix it? – Alexander Marochko Aug 12 '19 at 08:48
  • @AlexanderMarochko did you find the solution in 5.0 or previous versions. – Fatih TAN Nov 14 '19 at 08:50
  • @FatihTAN as far as i remember, it worked better to me via `adb shell settings put global airplane_mode_on 0` and `adb shell am broadcast -a android.intent.action.AIRPLANE_MODE` but finally on pre-lollipop devices i used Automate app, that was enough for my purposes – Alexander Marochko Nov 15 '19 at 20:58
  • @Patrick were you able to find the meaning for `SVC`? Using `SVC` to turn on/ wifi and Mobile data works for me with my Android 8. While trying to research the `SVC` command on my own, I wasn't sure if this feature is deprecated or not or what the acronym stands for. I've tried looking, but there wasn't much on topic. Using an adb command: `adb -s shell am broadcast -a io.appium.settings.data_connection -n io.appium.settings/.receivers.DataConnectionSettingReceiver --es setstatus ` doesn't have any affect on my device, (regarding Mobile Data, works with WiFi.) – InvisibleExo Feb 17 '20 at 07:16
  • @InvisibleExo I still don't know what it stands for but I do know it's responsible for accessing the data, power, and usb functionality. All svc commands (that I've found thus far) start with `svc data`, `svc wifi`, `svc power`, `svc usb`. – Patrick Feb 17 '20 at 07:57
  • @Patrick, yeah its got a few more features if you run `svc` without additional arguments or use `help` such as bluetooth, though doesn't seem responsive with my device and nfc. I wanted to know more to help my decision where to use those commands in my code since they actually work. I tried looking at the offical android studio for any mention with adb commands, but haven't found any mention. – InvisibleExo Feb 17 '20 at 09:14
  • 1
    Found this post while still investigating the topic about `SVC` is doing. Link: [link](https://stackoverflow.com/questions/26539445/the-setmobiledataenabled-method-is-no-longer-callable-as-of-android-l-and-later) – InvisibleExo Feb 17 '20 at 20:15