diff options
author | cyBerta <cyberta@riseup.net> | 2024-10-10 20:19:04 +0200 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2024-12-11 00:09:34 +0000 |
commit | 5484bac21a3b1df96ec7b2a4d4d87df47933e069 (patch) | |
tree | ed9fc06cfabf91dfa7a1416005a0c12fd6376200 /app/src/main/java | |
parent | 3eb2fac776cc9222a756dcf474eaae6d386a1de3 (diff) |
refactoring in Provider class: replace DefaultURL with strings, keep api as integer instead of a string
Diffstat (limited to 'app/src/main/java')
11 files changed, 93 insertions, 84 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java index fb93796e..a3e0ae34 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java @@ -307,7 +307,7 @@ public class EipFragment extends Fragment implements PropertyChangeListener { Log.e(TAG, "context is null when trying to start VPN"); return; } - if (!provider.getGeoipUrl().isDefault() && provider.shouldUpdateGeoIpJson()) { + if (!provider.getGeoipUrl().isEmpty() && provider.shouldUpdateGeoIpJson()) { Bundle bundle = new Bundle(); bundle.putBoolean(EIP_ACTION_START, true); bundle.putBoolean(EIP_EARLY_ROUTES, false); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java index ed0a9a15..15bc4b6f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java @@ -68,17 +68,18 @@ public final class Provider implements Parcelable { private JSONObject eipServiceJson = new JSONObject(); private JSONObject geoIpJson = new JSONObject(); private JSONObject motdJson = new JSONObject(); - private DefaultedURL mainUrl = new DefaultedURL(); - private DefaultedURL apiUrl = new DefaultedURL(); - private DefaultedURL geoipUrl = new DefaultedURL(); - private DefaultedURL motdUrl = new DefaultedURL(); + private String mainUrl = ""; + private String apiUrl = ""; + private String geoipUrl = ""; + private String motdUrl = ""; + private Gateways gateways = null; private String domain = ""; private String providerIp = ""; // ip of the provider main url private String providerApiIp = ""; // ip of the provider api url private String certificatePin = ""; private String certificatePinEncoding = ""; private String caCert = ""; - private String apiVersion = ""; + private int apiVersion = 3; private String privateKeyString = ""; private transient PrivateKey privateKey = null; private String vpnCertificate = ""; @@ -127,9 +128,9 @@ public final class Provider implements Parcelable { public Provider(String mainUrl, String geoipUrl) { try { - this.mainUrl.setUrl(new URL(mainUrl)); + this.mainUrl = new URL(mainUrl).toString(); } catch (MalformedURLException e) { - this.mainUrl = new DefaultedURL(); + this.mainUrl = ""; } setGeoipUrl(geoipUrl); } @@ -142,7 +143,7 @@ public final class Provider implements Parcelable { public Provider(String mainUrl, String geoipUrl, String motdUrl, String providerIp, String providerApiIp) { try { - this.mainUrl.setUrl(new URL(mainUrl)); + this.mainUrl = new URL(mainUrl).toString(); if (providerIp != null) { this.providerIp = providerIp; } @@ -184,13 +185,19 @@ public final class Provider implements Parcelable { }; public boolean isConfigured() { - return !mainUrl.isDefault() && - !apiUrl.isDefault() && - hasCaCert() && - hasDefinition() && - hasVpnCertificate() && - hasEIP() && - hasPrivateKey(); + if (apiVersion < 5) { + return !mainUrl.isEmpty() && + !apiUrl.isEmpty() && + hasCaCert() && + hasDefinition() && + hasVpnCertificate() && + hasEIP() && + hasPrivateKey(); + } else { + return !mainUrl.isEmpty() && + hasVpnCertificate() && + hasPrivateKey(); + } } public boolean supportsPluggableTransports() { @@ -242,15 +249,23 @@ public final class Provider implements Parcelable { public String getIpForHostname(String host) { if (host != null) { - if (host.equals(mainUrl.getUrl().getHost())) { + if (host.equals(getHostFromUrl(mainUrl))) { return providerIp; - } else if (host.equals(apiUrl.getUrl().getHost())) { + } else if (host.equals(getHostFromUrl(apiUrl))) { return providerApiIp; } } return ""; } + private String getHostFromUrl(String url) { + try { + return new URL(url).getHost(); + } catch (MalformedURLException e) { + return ""; + } + } + public String getProviderApiIp() { return this.providerApiIp; } @@ -270,14 +285,15 @@ public final class Provider implements Parcelable { } public void setMainUrl(URL url) { - mainUrl.setUrl(url); + mainUrl = url.toString(); } public void setMainUrl(String url) { try { - mainUrl.setUrl(new URL(url)); + mainUrl = new URL(url).toString(); } catch (MalformedURLException e) { e.printStackTrace(); + mainUrl = ""; } } @@ -298,52 +314,46 @@ public final class Provider implements Parcelable { return domain; } - public String getMainUrlString() { - return getMainUrl().toString(); } - public DefaultedURL getMainUrl() { + public String getMainUrl() { return mainUrl; } - protected DefaultedURL getApiUrl() { - return apiUrl; - } - - public DefaultedURL getGeoipUrl() { + public String getGeoipUrl() { return geoipUrl; } public void setGeoipUrl(String url) { try { - this.geoipUrl.setUrl(new URL(url)); + this.geoipUrl = new URL(url).toString(); } catch (MalformedURLException e) { - this.geoipUrl = new DefaultedURL(); + this.geoipUrl = ""; } } - public DefaultedURL getMotdUrl() { + public String getMotdUrl() { return this.motdUrl; } public void setMotdUrl(String url) { try { - this.motdUrl.setUrl(new URL(url)); + this.motdUrl = new URL(url).toString(); } catch (MalformedURLException e) { - this.motdUrl = new DefaultedURL(); + this.motdUrl = ""; } } public String getApiUrlWithVersion() { - return getApiUrlString() + "/" + getApiVersion(); + return getApiUrl() + "/" + getApiVersion(); } - public String getApiUrlString() { - return getApiUrl().toString(); + public String getApiUrl() { + return apiUrl; } - public String getApiVersion() { + public int getApiVersion() { return apiVersion; } @@ -377,7 +387,7 @@ public final class Provider implements Parcelable { name = definition.getJSONObject(API_TERM_NAME).getString("en"); } catch (JSONException e2) { if (mainUrl != null) { - String host = mainUrl.getDomain(); + String host = getHostFromUrl(mainUrl); name = host.substring(0, host.indexOf(".")); } } @@ -424,11 +434,11 @@ public final class Provider implements Parcelable { @Override public void writeToParcel(Parcel parcel, int i) { parcel.writeString(getDomain()); - parcel.writeString(getMainUrlString()); + parcel.writeString(getMainUrl()); parcel.writeString(getProviderIp()); parcel.writeString(getProviderApiIp()); - parcel.writeString(getGeoipUrl().toString()); - parcel.writeString(getMotdUrl().toString()); + parcel.writeString(getGeoipUrl()); + parcel.writeString(getMotdUrl()); parcel.writeString(getDefinitionString()); parcel.writeString(getCaCert()); parcel.writeString(getEipServiceJsonString()); @@ -450,7 +460,7 @@ public final class Provider implements Parcelable { private Provider(Parcel in) { try { domain = in.readString(); - mainUrl.setUrl(new URL(in.readString())); + mainUrl = new URL(in.readString()).toString(); String tmpString = in.readString(); if (!tmpString.isEmpty()) { providerIp = tmpString; @@ -461,11 +471,11 @@ public final class Provider implements Parcelable { } tmpString = in.readString(); if (!tmpString.isEmpty()) { - geoipUrl.setUrl(new URL(tmpString)); + geoipUrl = new URL(tmpString).toString(); } tmpString = in.readString(); if (!tmpString.isEmpty()) { - motdUrl.setUrl(new URL(tmpString)); + motdUrl = new URL(tmpString).toString(); } tmpString = in.readString(); if (!tmpString.isEmpty()) { @@ -516,7 +526,7 @@ public final class Provider implements Parcelable { if (o instanceof Provider) { Provider p = (Provider) o; return getDomain().equals(p.getDomain()) && - mainUrl.getDomain().equals(p.mainUrl.getDomain()) && + getHostFromUrl(mainUrl).equals(getHostFromUrl(p.getMainUrl())) && definition.toString().equals(p.getDefinition().toString()) && eipServiceJson.toString().equals(p.getEipServiceJsonString()) && geoIpJson.toString().equals(p.getGeoIpJsonString()) && @@ -529,7 +539,7 @@ public final class Provider implements Parcelable { certificatePin.equals(p.getCertificatePin()) && certificatePinEncoding.equals(p.getCertificatePinEncoding()) && caCert.equals(p.getCaCert()) && - apiVersion.equals(p.getApiVersion()) && + apiVersion == p.getApiVersion() && privateKeyString.equals(p.getPrivateKeyString()) && vpnCertificate.equals(p.getVpnCertificate()) && allowAnonymous == p.allowsAnonymous() && @@ -551,7 +561,7 @@ public final class Provider implements Parcelable { @Override public int hashCode() { - return getMainUrlString().hashCode(); + return getMainUrl().hashCode(); } @Override @@ -564,13 +574,13 @@ public final class Provider implements Parcelable { String pin = definition.getString(CA_CERT_FINGERPRINT); this.certificatePin = pin.split(":")[1].trim(); this.certificatePinEncoding = pin.split(":")[0].trim(); - this.apiUrl.setUrl(new URL(definition.getString(API_URL))); + this.apiUrl = new URL(definition.getString(API_URL)).toString(); this.allowAnonymous = definition.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOW_ANONYMOUS); this.allowRegistered = definition.getJSONObject(Provider.SERVICE).getBoolean(PROVIDER_ALLOWED_REGISTERED); - this.apiVersion = getDefinition().getString(Provider.API_VERSION); + this.apiVersion = Integer.parseInt(getDefinition().getString(Provider.API_VERSION)); this.domain = getDefinition().getString(Provider.DOMAIN); return true; - } catch (JSONException | ArrayIndexOutOfBoundsException | MalformedURLException e) { + } catch (JSONException | ArrayIndexOutOfBoundsException | MalformedURLException | NullPointerException | NumberFormatException e) { return false; } } @@ -616,7 +626,7 @@ public final class Provider implements Parcelable { * @return true if last message of the day was shown more than 24h ago */ public boolean shouldShowMotdSeen() { - return !motdUrl.isDefault() && System.currentTimeMillis() - lastMotdSeen >= MOTD_TIMEOUT; + return !motdUrl.isEmpty() && System.currentTimeMillis() - lastMotdSeen >= MOTD_TIMEOUT; } /** @@ -652,7 +662,7 @@ public final class Provider implements Parcelable { } public boolean shouldUpdateMotdJson() { - return !motdUrl.isDefault() && System.currentTimeMillis() - lastMotdUpdate >= MOTD_TIMEOUT; + return !motdUrl.isEmpty() && System.currentTimeMillis() - lastMotdUpdate >= MOTD_TIMEOUT; } public void setMotdJson(@NonNull JSONObject motdJson) { @@ -709,9 +719,9 @@ public final class Provider implements Parcelable { } public boolean isDefault() { - return getMainUrl().isDefault() && - getApiUrl().isDefault() && - getGeoipUrl().isDefault() && + return getMainUrl().isEmpty() && + getApiUrl().isEmpty() && + getGeoipUrl().isEmpty() && certificatePin.isEmpty() && certificatePinEncoding.isEmpty() && caCert.isEmpty(); @@ -777,11 +787,11 @@ public final class Provider implements Parcelable { eipServiceJson = new JSONObject(); geoIpJson = new JSONObject(); motdJson = new JSONObject(); - apiUrl = new DefaultedURL(); + apiUrl = ""; certificatePin = ""; certificatePinEncoding = ""; caCert = ""; - apiVersion = ""; + apiVersion = 3; privateKeyString = ""; vpnCertificate = ""; allowRegistered = false; diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java index 694f2149..d40e075a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java @@ -215,7 +215,7 @@ public class PreferenceHelper { SharedPreferences.Editor editor = preferences.edit(); for (Provider provider : providers) { String providerDomain = provider.getDomain(); - editor.putString(Provider.MAIN_URL + "." + providerDomain, provider.getMainUrlString()); + editor.putString(Provider.MAIN_URL + "." + providerDomain, provider.getMainUrl()); newProviderDomains.add(providerDomain); } @@ -243,7 +243,7 @@ public class PreferenceHelper { putString(Provider.GEOIP_URL, provider.getGeoipUrl().toString()). putString(Provider.MOTD_URL, provider.getMotdUrl().toString()). putString(Provider.PROVIDER_API_IP, provider.getProviderApiIp()). - putString(Provider.MAIN_URL, provider.getMainUrlString()). + putString(Provider.MAIN_URL, provider.getMainUrl()). putString(Provider.KEY, provider.getDefinitionString()). putString(Provider.CA_CERT, provider.getCaCert()). putString(PROVIDER_EIP_DEFINITION, provider.getEipServiceJsonString()). @@ -263,9 +263,9 @@ public class PreferenceHelper { preferences.edit().putBoolean(PROVIDER_CONFIGURED, true). putString(Provider.PROVIDER_IP + "." + providerDomain, provider.getProviderIp()). putString(Provider.PROVIDER_API_IP + "." + providerDomain, provider.getProviderApiIp()). - putString(Provider.MAIN_URL + "." + providerDomain, provider.getMainUrlString()). - putString(Provider.GEOIP_URL + "." + providerDomain, provider.getGeoipUrl().toString()). - putString(Provider.MOTD_URL + "." + providerDomain, provider.getMotdUrl().toString()). + putString(Provider.MAIN_URL + "." + providerDomain, provider.getMainUrl()). + putString(Provider.GEOIP_URL + "." + providerDomain, provider.getGeoipUrl()). + putString(Provider.MOTD_URL + "." + providerDomain, provider.getMotdUrl()). putString(Provider.KEY + "." + providerDomain, provider.getDefinitionString()). putString(Provider.CA_CERT + "." + providerDomain, provider.getCaCert()). putString(PROVIDER_EIP_DEFINITION + "." + providerDomain, provider.getEipServiceJsonString()). diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java index 0d023dfc..f4110877 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManager.java @@ -140,7 +140,7 @@ public class ProviderApiManager extends ProviderApiManagerBase { private Bundle getAndSetProviderJson(Provider provider) { Bundle result = new Bundle(); - String providerJsonUrl = provider.getMainUrlString() + "/provider.json"; + String providerJsonUrl = provider.getMainUrl() + "/provider.json"; String providerDotJsonString = fetch(providerJsonUrl, true); if (ConfigHelper.checkErroneousDownload(providerDotJsonString) || !isValidJson(providerDotJsonString)) { 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 ea50e741..3032bd4f 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerBase.java @@ -143,7 +143,7 @@ public abstract class ProviderApiManagerBase { } protected void getPersistedProviderUpdates(Provider provider) { - String providerDomain = getDomainFromMainURL(provider.getMainUrlString()); + String providerDomain = getDomainFromMainURL(provider.getMainUrl()); if (hasUpdatedProviderDetails(providerDomain)) { provider.setCaCert(getPersistedProviderCA(providerDomain)); provider.define(getPersistedProviderDefinition(providerDomain)); diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerFactory.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerFactory.java index 5abec0af..b6c1c955 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerFactory.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerFactory.java @@ -17,7 +17,7 @@ public class ProviderApiManagerFactory { public IProviderApiManager getProviderApiManager(Provider provider) throws IllegalArgumentException { switch (provider.getApiVersion()) { - case "5": + case 5: return new ProviderApiManagerV5(resources, callback); default: OkHttpClientGenerator clientGenerator = new OkHttpClientGenerator(resources); diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3.java index a63899c0..f827d85d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV3.java @@ -17,7 +17,6 @@ package se.leap.bitmaskclient.providersetup; -import static android.text.TextUtils.isEmpty; import static se.leap.bitmaskclient.BuildConfig.DEBUG_MODE; import static se.leap.bitmaskclient.R.string.certificate_error; import static se.leap.bitmaskclient.R.string.downloading_vpn_certificate_failed; @@ -202,7 +201,7 @@ public class ProviderApiManagerV3 extends ProviderApiManagerBase implements IPro ProviderObservable.getInstance().setProviderForDns(null); break; case DOWNLOAD_GEOIP_JSON: - if (!provider.getGeoipUrl().isDefault()) { + if (!provider.getGeoipUrl().isEmpty()) { boolean startEIP = parameters.getBoolean(EIP_ACTION_START); ProviderObservable.getInstance().setProviderForDns(provider); result = getGeoIPJson(provider); @@ -227,7 +226,7 @@ public class ProviderApiManagerV3 extends ProviderApiManagerBase implements IPro public Bundle setupProvider(Provider provider, Bundle task) { Bundle currentDownload = new Bundle(); - if (isEmpty(provider.getMainUrlString()) || provider.getMainUrl().isDefault()) { + if (provider.getMainUrl().isEmpty()) { currentDownload.putBoolean(BROADCAST_RESULT_KEY, false); eventSender.setErrorResult(currentDownload, malformed_url, null); VpnStatus.logWarning("[API] MainURL String is not set. Cannot setup provider."); @@ -274,7 +273,7 @@ public class ProviderApiManagerV3 extends ProviderApiManagerBase implements IPro String providerDotJsonString; if(provider.getDefinitionString().length() == 0 || provider.getCaCert().isEmpty()) { - String providerJsonUrl = provider.getMainUrlString() + "/provider.json"; + String providerJsonUrl = provider.getMainUrl() + "/provider.json"; providerDotJsonString = downloadWithCommercialCA(providerJsonUrl, provider); } else { providerDotJsonString = downloadFromApiUrlWithProviderCA("/provider.json", provider); @@ -367,13 +366,13 @@ public class ProviderApiManagerV3 extends ProviderApiManagerBase implements IPro private Bundle getGeoIPJson(Provider provider) { Bundle result = new Bundle(); - if (!provider.shouldUpdateGeoIpJson() || provider.getGeoipUrl().isDefault() || VpnStatus.isVPNActive() || TorStatusObservable.getStatus() != OFF) { + if (!provider.shouldUpdateGeoIpJson() || provider.getGeoipUrl().isEmpty() || VpnStatus.isVPNActive() || TorStatusObservable.getStatus() != OFF) { result.putBoolean(BROADCAST_RESULT_KEY, false); return result; } try { - URL geoIpUrl = provider.getGeoipUrl().getUrl(); + URL geoIpUrl = new URL(provider.getGeoipUrl()); String geoipJsonString = downloadFromUrlWithProviderCA(geoIpUrl.toString(), provider, false); if (DEBUG_MODE) { @@ -389,7 +388,7 @@ public class ProviderApiManagerV3 extends ProviderApiManagerBase implements IPro result.putBoolean(BROADCAST_RESULT_KEY, true); } - } catch (JSONException | NullPointerException e) { + } catch (JSONException | NullPointerException | MalformedURLException e) { result.putBoolean(BROADCAST_RESULT_KEY, false); e.printStackTrace(); } @@ -477,7 +476,7 @@ public class ProviderApiManagerV3 extends ProviderApiManagerBase implements IPro * @return an empty string if it fails, the response body if not. */ private String downloadFromApiUrlWithProviderCA(String path, Provider provider) { - String baseUrl = provider.getApiUrlString(); + String baseUrl = provider.getApiUrl(); String urlString = baseUrl + path; return downloadFromUrlWithProviderCA(urlString, provider); } @@ -594,7 +593,7 @@ public class ProviderApiManagerV3 extends ProviderApiManagerBase implements IPro private boolean canConnect(Provider provider, Bundle result, int tries) { JSONObject errorJson = new JSONObject(); - String providerUrl = provider.getApiUrlString() + "/provider.json"; + String providerUrl = provider.getApiUrl() + "/provider.json"; OkHttpClient okHttpClient = clientGenerator.initSelfSignedCAHttpClient(provider.getCaCert(), getProxyPort(), errorJson); if (okHttpClient == null) { diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java index ee39499b..bd6c5ef2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java @@ -64,7 +64,7 @@ public class ProviderApiSetupBroadcastReceiver extends BroadcastReceiver { Provider handledProvider = resultData.getParcelable(Constants.PROVIDER_KEY); if (handledProvider != null && setupInterface.getProvider() != null && - handledProvider.getMainUrlString().equalsIgnoreCase(setupInterface.getProvider().getMainUrlString())) { + handledProvider.getMainUrl().equalsIgnoreCase(setupInterface.getProvider().getMainUrl())) { switch (resultCode) { case ProviderAPI.PROVIDER_OK: setupInterface.handleProviderSetUp(handledProvider); diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java index 9eacae5d..63fbde09 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java @@ -78,7 +78,7 @@ public class ProviderManager { private Set<String> getProviderUrlSetFromProviderSet(Set<Provider> providers) { HashSet<String> providerUrls = new HashSet<>(); for (Provider provider : providers) { - providerUrls.add(provider.getMainUrl().toString()); + providerUrls.add(provider.getMainUrl()); } return providerUrls; } @@ -152,10 +152,10 @@ public class ProviderManager { public boolean add(Provider element) { boolean addElement = element != null && - !defaultProviderURLs.contains(element.getMainUrlString()) && - !customProviders.containsKey(element.getMainUrlString()); + !defaultProviderURLs.contains(element.getMainUrl()) && + !customProviders.containsKey(element.getMainUrl()); if (addElement) { - customProviders.put(element.getMainUrlString(), element); + customProviders.put(element.getMainUrl(), element); return true; } return false; @@ -163,7 +163,7 @@ public class ProviderManager { public boolean remove(Object element) { return element instanceof Provider && - customProviders.remove(((Provider) element).getMainUrlString()) != null; + customProviders.remove(((Provider) element).getMainUrl()) != null; } public boolean addAll(Collection<? extends Provider> elements) { @@ -171,9 +171,9 @@ public class ProviderManager { boolean addedAll = true; while (iterator.hasNext()) { Provider p = (Provider) iterator.next(); - boolean containsKey = customProviders.containsKey(p.getMainUrlString()); + boolean containsKey = customProviders.containsKey(p.getMainUrl()); if (!containsKey) { - customProviders.put(p.getMainUrlString(), p); + customProviders.put(p.getMainUrl(), p); } addedAll = !containsKey && addedAll; } diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupFailedDialog.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupFailedDialog.java index 338a60e9..162238bf 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupFailedDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupFailedDialog.java @@ -136,7 +136,7 @@ public class ProviderSetupFailedDialog extends DialogFragment { break; case ERROR_NEW_URL_NO_VPN_PROVIDER: builder.setPositiveButton(R.string.retry, (dialog, id) - -> interfaceWithConfigurationWizard.addAndSelectNewProvider(provider.getMainUrlString())); + -> interfaceWithConfigurationWizard.addAndSelectNewProvider(provider.getMainUrl())); break; case ERROR_TOR_TIMEOUT: builder.setPositiveButton(R.string.retry, (dialog, id) -> { diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java index 621cb41a..c1a53545 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java @@ -215,7 +215,7 @@ public class ConfigureProviderFragment extends BaseSetupFragment implements Prop if (ignoreProviderAPIUpdates || provider == null || (setupActivityCallback.getSelectedProvider() != null && - !setupActivityCallback.getSelectedProvider().getMainUrlString().equals(provider.getMainUrlString()))) { + !setupActivityCallback.getSelectedProvider().getMainUrl().equals(provider.getMainUrl()))) { return; } |