Nagaraja Thangavelu
Nagaraja Thangavelu

Reputation: 1168

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?

Upvotes: 2

Views: 3923

Answers (3)

Sion C
Sion C

Reputation: 451

"shell dumpsys connectivit"

enter image description here

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

Upvotes: 1

Alex Kosh
Alex Kosh

Reputation: 2554

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)

Upvotes: 1

Abhishek
Abhishek

Reputation: 316

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

Upvotes: 4

Related Questions