2

I was just wondering how to find the state of Wifi tethering through ADB.

Although, there are some options to find the state through WifiManager() as described in this answer, I just want to know if its possible through ADB?

Community
  • 1
  • 1
Nagaraja Thangavelu
  • 1,168
  • 1
  • 15
  • 31

3 Answers3

4

you can use adb shell dumpsys wifi and search for curState=TetheredState to check wifi tethering is enabled.

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
Abhishek
  • 306
  • 2
  • 8
1

Command adb shell dumpsys wifi didn't work for me.

So, here is another solution:

  1. Run adb shell dumpsys connectivity
  2. Search for interface pattern tetherableWifiRegexs:
  3. Use that regex pattern to search for enabled interfaces. Example: ap\d - TetheredState
  4. If there is a match, WiFi tethering is on

Also here is my Python implementation:

import re
import subprocess
import time

def run_adb(command):
    res = subprocess.run(['adb'] + command.split(), capture_output=True)
    time.sleep(0.1)
    return res

def is_wifi_hotspot_enabled():
    output = run_adb('shell dumpsys connectivity').stdout.decode()

    pattern = 'ap\d'
    if match := re.search('tetherableWifiRegexs: \[(.*)\]', output):
        pattern = match.group(1)

    match = re.search(f'{pattern} - TetheredState', output)
    return (match is not None)
Alex Kosh
  • 2,206
  • 2
  • 19
  • 18
1

"shell dumpsys connectivit"

enter image description here

wlan0 - TetheredState - lastError = 0
wlan0 - AvailableState - lastError = 0
Sion C
  • 439
  • 2
  • 14