I am writing Instrumentation tests for my app on Android Studios testing on an emulator with Espresso. I need to disable the internet from within the test to make sure my error handling functionality works when the user does not have internet available. I've searched all over for an easy way to programmatically disable the internet from an emulated device. Here is the closest I've come, which does not work.
WifiManager wifiManager = (WifiManager) mActivityRule.getActivity().getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
Even calling this in the @Before code block does nothing, and I also have the necessary privileges set in the AndroidManifest.xml file to change the wifi settings.