summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java26
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java4
-rw-r--r--app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java41
4 files changed, 9 insertions, 67 deletions
diff --git a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java
index cbb58f0f..a4f09806 100644
--- a/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java
+++ b/app/src/main/java/de/blinkt/openvpn/core/NetworkUtils.java
@@ -80,30 +80,4 @@ public class NetworkUtils {
}
return nets;
}
-
- public static boolean isConnectedToWifi(Context context) {
- ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
- NetworkInfo wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
- Log.d(TAG, "isConnectedToWifi (<=LOLLIPOP_MR1): " + wifi.isConnected());
- return wifi.isConnected();
- } else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
- NetworkInfo[] netInfos = connManager.getAllNetworkInfo();
- for (NetworkInfo netInfo : netInfos) {
- if (netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI) {
- Log.d(TAG, "isConnectedToWifi (<= Build.VERSION_CODES.O_MR1): " + netInfo.isConnected());
- return netInfo.isConnected();
- }
- }
- } else {
- NetworkInfo netInfo = connManager.getActiveNetworkInfo();
- if(netInfo != null) {
- NetworkCapabilities networkCapabilities = connManager.getNetworkCapabilities(connManager.getActiveNetwork());
- Log.d(TAG, "isConnectedToWifi (> Build.VERSION_CODES.O_MR1): " + networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI));
- return networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
- }
- }
-
- return false;
- }
} \ No newline at end of file
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java
index 335d70b2..c45d7ae9 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderAPI.java
@@ -155,11 +155,6 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB
}
@Override
- public boolean isConnectedToWifi() {
- return NetworkUtils.isConnectedToWifi(getApplicationContext());
- }
-
- @Override
public void startTorService() throws InterruptedException, IllegalStateException {
initTorServiceConnection(this);
Intent torServiceIntent = new Intent(this, TorService.class);
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
index 0c09aec1..7872fb32 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java
@@ -153,7 +153,6 @@ public abstract class ProviderApiManagerBase {
void startTorService() throws InterruptedException, IllegalStateException;
void stopTorService();
int getTorHttpTunnelPort();
- boolean isConnectedToWifi();
}
private final ProviderApiServiceCallback serviceCallback;
@@ -305,8 +304,7 @@ public abstract class ProviderApiManagerBase {
protected boolean startTorProxy() throws InterruptedException, IllegalStateException, TimeoutException {
if (EipStatus.getInstance().isDisconnected() &&
- PreferenceHelper.getUseTor(preferences) &&
- serviceCallback.isConnectedToWifi()
+ PreferenceHelper.getUseTor(preferences)
) {
serviceCallback.startTorService();
waitForTorCircuits();
diff --git a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
index 5ecde5d4..3411274a 100644
--- a/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
+++ b/app/src/test/java/se/leap/bitmaskclient/eip/ProviderApiManagerTest.java
@@ -108,13 +108,11 @@ public class ProviderApiManagerTest {
static class TestProviderApiServiceCallback implements ProviderApiManagerBase.ProviderApiServiceCallback {
Throwable startTorServiceException;
- boolean isConnectedToWifi;
TestProviderApiServiceCallback() {
- new TestProviderApiServiceCallback(null/*, 0*/, true);
+ new TestProviderApiServiceCallback(null);
}
- TestProviderApiServiceCallback(@Nullable Throwable startTorServiceException/*, int torHttpTunnelPort*/, boolean isConnectedToWifi) {
+ TestProviderApiServiceCallback(@Nullable Throwable startTorServiceException) {
this.startTorServiceException = startTorServiceException;
- this.isConnectedToWifi = isConnectedToWifi;
}
@Override
@@ -142,10 +140,6 @@ public class ProviderApiManagerTest {
return 0;
}
- @Override
- public boolean isConnectedToWifi() {
- return this.isConnectedToWifi;
- }
}
@Before
@@ -627,7 +621,7 @@ public class ProviderApiManagerTest {
mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, true));
+ providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null));
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -641,31 +635,12 @@ public class ProviderApiManagerTest {
}
@Test
- public void test_handleIntentSetupProvider_TorFallback_SecondTryFailedNoWifi() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
- Provider provider = getConfiguredProviderAPIv4();
-
- mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
- mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, false));
-
- Intent providerApiCommand = mockIntent();
- providerApiCommand.putExtra(PROVIDER_KEY, provider);
- providerApiCommand.setAction(ProviderAPI.SET_UP_PROVIDER);
- providerApiCommand.putExtra(ProviderAPI.RECEIVER_KEY, mockResultReceiver(PROVIDER_NOK));
-
- mockTorStatusObservable(null);
-
- providerApiManager.handleIntent(providerApiCommand);
- assertEquals(-1, TorStatusObservable.getProxyPort());
- }
-
- @Test
public void test_handleIntentSetupProvider_TorFallbackStartServiceException_SecondTryFailed() throws IOException, CertificateEncodingException, NoSuchAlgorithmException, TimeoutException, InterruptedException {
Provider provider = getConfiguredProviderAPIv4();
mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(new IllegalStateException("Tor service start not failed."), true));
+ providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(new IllegalStateException("Tor service start not failed.")));
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -684,7 +659,7 @@ public class ProviderApiManagerTest {
mockFingerprintForCertificate(" a5244308a1374709a9afce95e3ae47c1b44bc2398c0a70ccbf8b3a8a97f29494");
mockProviderApiConnector(ERROR_DNS_RESUOLUTION_TOR_FALLBACK);
- providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, true));
+ providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null));
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -705,7 +680,7 @@ public class ProviderApiManagerTest {
mockProviderApiConnector(NO_ERROR_API_V4);
mockPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_TOR, true).commit();
- providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, true));
+ providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null));
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -726,7 +701,7 @@ public class ProviderApiManagerTest {
mockProviderApiConnector(NO_ERROR_API_V4);
mockPreferences.edit().putBoolean(USE_BRIDGES, false).putBoolean(USE_TOR, false).commit();
- providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, true));
+ providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null));
Intent providerApiCommand = mockIntent();
providerApiCommand.putExtra(PROVIDER_KEY, provider);
@@ -744,7 +719,7 @@ public class ProviderApiManagerTest {
Provider provider = getConfiguredProviderAPIv4();
mockPreferences.edit().putBoolean(USE_BRIDGES, true).putBoolean(USE_TOR, true).commit();
- providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null, true));
+ providerApiManager = new ProviderApiManager(mockPreferences, mockResources, mockClientGenerator(), new TestProviderApiServiceCallback(null));
Bundle expectedResult = mockBundle();
expectedResult.putBoolean(BROADCAST_RESULT_KEY, false);