Im automating a testing procedure for wifi calling and I was wondering is there a way to turn off/on wifi via adb?
I would either like to disable/enable wifi or kill wifi calling (com.movial.wificall) and restart it.
Is it possible to do this all via adb and shell commands?
so far I have found:
android.net.wifi.WifiManager
setWifiEnabled(true/false)
Im just not sure how to put it together
Enable:
adb shell su -c 'svc wifi enable'
Disable:
adb shell su -c 'svc wifi disable'
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
adb shell input keyevent 20 & adb shell input keyevent 23
The first line launch "wifi.WifiSettings" activity which open the WiFi Settings page. The second line simulate key presses.
I tested those two lines on a Droid X. But Key Events above probably need to edit in other devices because of different Settings layout.
More info about "keyevents" here.
adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23
(the first one can be 20 as well) - this is working if there is no option selected when you enter the wifi settings screen (if there is, you should skip the first event - Bartek Lipinski 2015-01-22 23:55
su
here like @IvanMorgillo said adb shell su -c 'svc wifi disable'
Aquarius Power 2016-02-18 02:24
sh: resetreason: can't execute: Permission denied
how should i get permissions? the phone wasn't locked eithe - ThunderWiring 2017-04-19 20:45
I was searching for the same to turn bluetooth on/off, and I found this:
adb shell svc wifi enable|disable
adb shell su -c 'svc wifi enable'
didn't (since it wasn't rooted - trevren11 2018-06-15 16:49
Simple way to switch wifi on non-rooted devices is to use simple app:
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WifiManager wfm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
try {
wfm.setWifiEnabled(Boolean.parseBoolean(getIntent().getStringExtra("wifi")));
} catch (Exception e) {
}
System.exit(0);
}
}
AndroidManifest.xml:
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
ADB commands:
$ adb shell am start -n org.mytools.config/.MainActivity -e wifi true
$ adb shell am start -n org.mytools.config/.MainActivity -e wifi false
android/android-sdk/platform-tools
open cmd here and type the following commands
adb shell
su
svc wifi enable/disable
done!!!!!
adb shell "svc wifi enable"
This worked & it makes action in background without opening related option !!
I tested this command:
adb shell am start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings
adb shell input keyevent 19 & adb shell input keyevent 19 & adb shell input keyevent 23
and only works on window's prompt, maybe because of some driver
about adb shell svc wifi enable|disable
i guess that only work with root permission
use with quotes
ex: adb shell "svc wifi enable"
this will work :)
I can just do:
settings put global wifi_on 0
settings put global wifi_scan_always_enabled 0
Sometimes, if done during boot (i.e. to fix bootloop such as this), it doesn't apply well and you can proceed also enabling airplane mode first:
settings put global airplane_mode_on 1
settings put global wifi_on 0
settings put global wifi_scan_always_enabled 0
Other option is to force this with:
while true; do settings put global wifi_on 0; done
Tested in Android 7 on LG G5 (SE) with (unrooted) stock mod.