'How to find the WiFi tethering state through ADB?

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?



Solution 1:[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)

Solution 2:[2]

"shell dumpsys connectivit"

enter image description here

wlan0 - TetheredState - lastError = 0
wlan0 - AvailableState - lastError = 0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Kosh
Solution 2 Sion C