diff options
author | cyBerta <cyberta@riseup.net> | 2024-12-07 16:11:53 +0100 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2024-12-11 00:09:34 +0000 |
commit | 420950ee88060dad67c07627b5d07f6ef15b9559 (patch) | |
tree | 47f1ab55595a6c5fd070d45bbd3d555c0f5f8282 /app/src/main/java | |
parent | 4fd0c5e51ad3fa0d5696f726e5966503325c046d (diff) |
move api version parsing to top of Provider's define() method. Check if provider json contains the fields 'allow_registration' and 'allow_anonymous', in order to work around half-baken menshen model parsing
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/base/models/Provider.java | 24 |
1 files changed, 17 insertions, 7 deletions
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 5b5fac48..0818c7bd 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 @@ -52,6 +52,7 @@ import java.security.PrivateKey; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Locale; import java.util.Objects; import java.util.Set; @@ -726,15 +727,20 @@ public final class Provider implements Parcelable { private boolean parseDefinition(JSONObject definition) { try { + this.apiVersions = parseApiVersionsArray(); + this.apiVersion = selectPreferredApiVersion(); + this.domain = getDefinition().getString(Provider.DOMAIN); String pin = definition.getString(CA_CERT_FINGERPRINT); this.certificatePin = pin.split(":")[1].trim(); this.certificatePinEncoding = pin.split(":")[0].trim(); 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.apiVersions = parseApiVersionsArray(); - this.apiVersion = selectPreferredApiVersion(); - this.domain = getDefinition().getString(Provider.DOMAIN); + JSONObject serviceJSONObject = definition.getJSONObject(Provider.SERVICE); + if (serviceJSONObject.has(PROVIDER_ALLOW_ANONYMOUS)) { + this.allowAnonymous = serviceJSONObject.getBoolean(PROVIDER_ALLOW_ANONYMOUS); + } + if (serviceJSONObject.has(PROVIDER_ALLOWED_REGISTERED)) { + this.allowRegistered = serviceJSONObject.getBoolean(PROVIDER_ALLOWED_REGISTERED); + } return true; } catch (JSONException | ArrayIndexOutOfBoundsException | MalformedURLException | NullPointerException | NumberFormatException e) { return false; @@ -745,7 +751,7 @@ public final class Provider implements Parcelable { @returns latest api version supported by client and server or the version set in 'api_version' in case there's not a common supported version */ - private int selectPreferredApiVersion() throws JSONException { + private int selectPreferredApiVersion() throws JSONException, NumberFormatException { if (apiVersions.length == 0) { return Integer.parseInt(getDefinition().getString(Provider.API_VERSION)); } @@ -767,7 +773,11 @@ public final class Provider implements Parcelable { JSONArray versions = getDefinition().getJSONArray(Provider.API_VERSIONS); versionArray = new int[versions.length()]; for (int i = 0; i < versions.length(); i++) { - versionArray[i] = Integer.parseInt(versions.getString(i)); + try { + versionArray[i] = Integer.parseInt(versions.getString(i)); + } catch (NumberFormatException e) { + e.printStackTrace(); + } } } catch (JSONException ignore) { // this backend doesn't support api_versions yet |