diff options
author | Parménides GV <parmegv@sdf.org> | 2014-04-07 20:43:34 +0200 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2014-04-08 11:43:27 +0200 |
commit | c206a91d320995f37f8abb33188bfd384249da3d (patch) | |
tree | 10a7d8a9dd7f24437ac4851b8d01edbd5dd3ee3b /app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java | |
parent | 910b0e1746ab3f63e63808b198ad51fec5b635e5 (diff) |
Next step: compile jni sources correctly.
Diffstat (limited to 'app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java')
-rw-r--r-- | app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java new file mode 100644 index 00000000..f1cbff19 --- /dev/null +++ b/app/src/androidTest/java/se/leap/bitmaskclient/test/ConnectionManager.java @@ -0,0 +1,33 @@ +package se.leap.bitmaskclient.test; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.wifi.WifiManager; +import android.util.Log; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class ConnectionManager { + static void setMobileDataEnabled(boolean enabled, Context context) { + final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + Method[] methods = conman.getClass().getMethods(); + for (Method method : methods) { + if (method.getName().equals("setMobileDataEnabled")) { + method.setAccessible(true); + try { + method.invoke(conman, enabled); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + } + } + + static void setWifiEnabled(boolean enabled, Context context) { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + wifiManager.setWifiEnabled(enabled); + } +} |