summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-01-30 18:59:07 +0100
committerParménides GV <parmegv@sdf.org>2014-01-30 18:59:07 +0100
commit6c7eda789ac7ee5c0369409cb27430f0074dfc07 (patch)
treeda119da7f5d9ff1ed22a2b45fb29c3bed34df948 /tests/src
parent00dedc1f763093eb22bec0ff15c9fbdb7ca88d65 (diff)
Set data connection status works.
Tested both in real device with Cyanogenmod 4.3.1 and in api 18 emulator. Next step: wi-fi toggling.
Diffstat (limited to 'tests/src')
-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();
+ }
+ }
}
}
}