Reputation: 1168
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?
Upvotes: 2
Views: 3923
Reputation: 451
"shell dumpsys connectivit"
wlan0 - TetheredState - lastError = 0
wlan0 - AvailableState - lastError = 0
Upvotes: 1
Reputation: 2554
Command adb shell dumpsys wifi
didn't work for me.
So, here is another solution:
adb shell dumpsys connectivity
tetherableWifiRegexs:
ap\d - TetheredState
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)
Upvotes: 1
Reputation: 316
you can use adb shell dumpsys wifi
and search for curState=TetheredState
to check wifi tethering is enabled.
Upvotes: 4