summaryrefslogtreecommitdiff
path: root/tests/src/se
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/se')
-rw-r--r--tests/src/se/leap/bitmaskclient/test/ConnectionManager.java33
1 files changed, 12 insertions, 21 deletions
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();
+ }
+ }
}
}
}