From 6c7eda789ac7ee5c0369409cb27430f0074dfc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 30 Jan 2014 18:59:07 +0100 Subject: 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. --- .../leap/bitmaskclient/test/ConnectionManager.java | 33 ++++++++-------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'tests/src') 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(); + } + } } } } -- cgit v1.2.3