First main question:
is it possible to switch(not only on or off) the state of the mobile data and wifi using adb?
(for example for wifi: if you don't know the state of the wifi now. you send several commands and then you are sure that the wifi state changed.)
if this is not possible then the question is how to find out the state of wifi and mobile data using adb?
second:
is it possible to switch the state of the wifi-hotspot and the usb-modem via abd?
what can I do:
I'm use
adb shell svc data enable/disable
adb shell svc wifi enable/disable
To turn on/of wifi and mobile data. But I don't know a way to switch the state with one command like "adb shell svc data toggle". Maybe there is a command that returns the state of the Wi-Fi or mobile data? Like adb shell svc data state
. and it returns "on" or "off".
is there a way to switch it when the phone is locked?
I also use such commands to switch the wifi-hotspot and usb-modem
(unlike first two commands above the screen may be off, but the phone must be unlocked):
adb shell am start -n com.android.settings/.TetherSettings
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 66
first line opens the settings page. keyevent 20 - simulates key press down, keyevent 66 - enter. it's for usb-modem. for wifi-hotspot i use same first line,key20 key66 key20 key66.
i have samsung a50(android 10) and ubuntu 20. the modem state switching bash script is located at /usr/local/bin so I can run it from the console just by writing the filename.