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