diff options
-rw-r--r-- | AndroidManifest.xml | 3 | ||||
-rw-r--r-- | tests/src/se/leap/bitmaskclient/test/ConnectionManager.java | 33 |
2 files changed, 15 insertions, 21 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 505f6ee1..2ac10a26 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -24,6 +24,9 @@ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/> + <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/> + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> + <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> <!-- if you want to run the unit test for Dashboard you will need that you uncomment the following line --> <!-- <uses-permission android:name="android.permission.WRITE_SETTINGS" /> --> diff --git a/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java index 8722bb13..62a8f0ad 100644 --- a/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java +++ b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java @@ -10,27 +10,18 @@ import android.util.Log; public class ConnectionManager { static void setMobileDataEnabled(boolean enabled, Context context) { final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - try { - final Class conmanClass = Class.forName(conman.getClass().getName()); - final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService"); - iConnectivityManagerField.setAccessible(true); - final Object iConnectivityManager = iConnectivityManagerField.get(conman); - final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); - final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE); - setMobileDataEnabledMethod.setAccessible(true); - - setMobileDataEnabledMethod.invoke(iConnectivityManager, enabled); - Log.d("testDashboard", "setMobileDataEnabled(" + enabled + ");"); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } catch (InvocationTargetException e) { - e.printStackTrace(); + 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(); + } + } } } } |