From 0e6ae1dc4f01a48856755a45e22d4a64991fe8b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 28 Jan 2014 20:46:45 +0100 Subject: Android support library v4 added. Look at https://leap.se/code/issues/5062#note-3: I'm going to remove android-support-v4.jar from .gitignore based on https://developer.android.com/tools/support-library/index.html#overview and http://www.in-nomine.org/2012/02/26/adding-android-support-v4-to-your-android-application-in-intellij-idea/ --- tests/libs/android-support-v4.jar | Bin 0 -> 627582 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/libs/android-support-v4.jar (limited to 'tests') diff --git a/tests/libs/android-support-v4.jar b/tests/libs/android-support-v4.jar new file mode 100644 index 00000000..96644edb Binary files /dev/null and b/tests/libs/android-support-v4.jar differ -- cgit v1.2.3 From 8d1b47a498df5d0f4e4e619f8373aaa1ad4dcd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 29 Jan 2014 16:29:11 +0100 Subject: testSwitchProvider updated. It shouldn't expect the previous provider to be back again pressing the back button after hitting "Switch provider". --- .../se/leap/bitmaskclient/test/testDashboard.java | 60 ++++++++++------------ 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/src/se/leap/bitmaskclient/test/testDashboard.java b/tests/src/se/leap/bitmaskclient/test/testDashboard.java index 31039797..a6b25c0a 100644 --- a/tests/src/se/leap/bitmaskclient/test/testDashboard.java +++ b/tests/src/se/leap/bitmaskclient/test/testDashboard.java @@ -1,18 +1,22 @@ package se.leap.bitmaskclient.test; -import se.leap.bitmaskclient.ConfigurationWizard; -import se.leap.bitmaskclient.Dashboard; -import se.leap.bitmaskclient.R; -import se.leap.openvpn.MainActivity; + import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.net.ConnectivityManager; import android.provider.Settings; import android.test.ActivityInstrumentationTestCase2; import android.util.Log; - import com.jayway.android.robotium.solo.Solo; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import se.leap.bitmaskclient.ConfigurationWizard; +import se.leap.bitmaskclient.Dashboard; +import se.leap.bitmaskclient.R; +import se.leap.openvpn.MainActivity; public class testDashboard extends ActivityInstrumentationTestCase2 { @@ -97,10 +101,6 @@ public class testDashboard extends ActivityInstrumentationTestCase2 { solo.clickOnMenuItem("Switch provider"); solo.waitForActivity(ConfigurationWizard.class); solo.goBack(); - - solo.clickOnMenuItem("Switch provider"); - solo.waitForActivity(ConfigurationWizard.class); - solo.goBack(); } public void testIcsOpenVpnInterface() { @@ -113,28 +113,24 @@ public class testDashboard extends ActivityInstrumentationTestCase2 { solo.waitForActivity(MainActivity.class); } - private void setAirplaneMode(boolean airplane_mode) { - Context context = solo.getCurrentActivity().getApplicationContext(); - boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; - Log.d("AirplaneMode", "Service state: " + isEnabled); - Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, airplane_mode ? 1 : 0); - - // Post an intent to reload - Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); - intent.putExtra("state", airplane_mode); - Log.d("AirplaneMode", "New Service state: " + !isEnabled); - solo.getCurrentActivity().sendBroadcast(intent); - - IntentFilter intentFilter = new IntentFilter("android.intent.action.SERVICE_STATE"); - - BroadcastReceiver receiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; - Log.d("AirplaneMode", "Service state changed: " + isEnabled); - } - }; - - context.registerReceiver(receiver, intentFilter); + private void setAirplaneMode(boolean airplane_mode) { + Context context = solo.getCurrentActivity().getApplicationContext(); + 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, !airplane_mode); + } catch (ClassNotFoundException e) { + } catch (NoSuchMethodException e) { + } catch (IllegalAccessException e) { + } catch (NoSuchFieldException e) { + } catch (InvocationTargetException e) { } + } } -- cgit v1.2.3 From 00dedc1f763093eb22bec0ff15c9fbdb7ca88d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Wed, 29 Jan 2014 17:09:12 +0100 Subject: New method to set on/off data connection. Used in tests, but it's going to be used in the near future when blocking data connections until EIP is on. --- .../leap/bitmaskclient/test/ConnectionManager.java | 36 +++++++++++++++++++ .../test/testConfigurationWizard.java | 10 +++--- .../se/leap/bitmaskclient/test/testDashboard.java | 40 ++++------------------ 3 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 tests/src/se/leap/bitmaskclient/test/ConnectionManager.java (limited to 'tests') diff --git a/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java new file mode 100644 index 00000000..8722bb13 --- /dev/null +++ b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java @@ -0,0 +1,36 @@ +package se.leap.bitmaskclient.test; + +import android.content.Context; +import android.net.ConnectivityManager; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +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(); + } + } +} diff --git a/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java b/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java index 55fd87ae..847d8cdd 100644 --- a/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java +++ b/tests/src/se/leap/bitmaskclient/test/testConfigurationWizard.java @@ -1,15 +1,14 @@ package se.leap.bitmaskclient.test; +import android.test.ActivityInstrumentationTestCase2; +import android.widget.ListView; +import com.jayway.android.robotium.solo.Solo; import java.io.IOException; - import se.leap.bitmaskclient.AboutActivity; import se.leap.bitmaskclient.ConfigurationWizard; import se.leap.bitmaskclient.ProviderDetailFragment; import se.leap.bitmaskclient.R; -import android.test.ActivityInstrumentationTestCase2; -import android.widget.ListView; - -import com.jayway.android.robotium.solo.Solo; +import se.leap.bitmaskclient.test.ConnectionManager; public class testConfigurationWizard extends ActivityInstrumentationTestCase2 { @@ -24,6 +23,7 @@ public class testConfigurationWizard extends ActivityInstrumentationTestCase2 { @@ -30,7 +26,7 @@ public class testDashboard extends ActivityInstrumentationTestCase2 { protected void setUp() throws Exception { super.setUp(); solo = new Solo(getInstrumentation(), getActivity()); - setAirplaneMode(false); + ConnectionManager.setMobileDataEnabled(true, solo.getCurrentActivity().getApplicationContext()); } @Override @@ -53,21 +49,18 @@ public class testDashboard extends ActivityInstrumentationTestCase2 { solo.clickOnView(solo.getView(R.id.eipSwitch)); if(!solo.waitForText("Not running! Connection not secure")) - fail(); - /* setAirplaneMode isn't working right now. - setAirplaneMode(true); - if(!solo.waitForLogMessage("Service state changed")) - fail(); + fail(); + + ConnectionManager.setMobileDataEnabled(false, solo.getCurrentActivity().getApplicationContext()); solo.clickOnView(solo.getView(R.id.eipSwitch)); if(!solo.waitForText("Initiating connection")) fail(); if(!solo.waitForText("Waiting for usable network")) fail(); - */ } - public void testLogInAndOut() { + public void testLogInAndOut() { long miliseconds_to_log_in = 40 * 1000; solo.clickOnActionBarItem(R.id.login_button); solo.enterText(0, "parmegvtest1"); @@ -112,25 +105,4 @@ public class testDashboard extends ActivityInstrumentationTestCase2 { solo.clickOnMenuItem("ICS OpenVPN Interface"); solo.waitForActivity(MainActivity.class); } - - private void setAirplaneMode(boolean airplane_mode) { - Context context = solo.getCurrentActivity().getApplicationContext(); - 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, !airplane_mode); - } catch (ClassNotFoundException e) { - } catch (NoSuchMethodException e) { - } catch (IllegalAccessException e) { - } catch (NoSuchFieldException e) { - } catch (InvocationTargetException e) { - } - } } -- cgit v1.2.3 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') 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 From c1c7d1f7106afa4e2300f37355642c56641884e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 30 Jan 2014 19:54:58 +0100 Subject: Wi-Fi on/off method in ConnectionManager for tests --- tests/src/se/leap/bitmaskclient/test/ConnectionManager.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java index 62a8f0ad..f1cbff19 100644 --- a/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java +++ b/tests/src/se/leap/bitmaskclient/test/ConnectionManager.java @@ -2,10 +2,11 @@ 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; -import android.util.Log; public class ConnectionManager { static void setMobileDataEnabled(boolean enabled, Context context) { @@ -24,4 +25,9 @@ public class ConnectionManager { } } } + + static void setWifiEnabled(boolean enabled, Context context) { + WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + wifiManager.setWifiEnabled(enabled); + } } -- cgit v1.2.3