diff options
author | cyBerta <cyberta@riseup.net> | 2024-10-26 01:47:00 +0200 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2024-12-11 00:09:34 +0000 |
commit | 980b0038ac33ea650450fe70025f2a72402307c3 (patch) | |
tree | 8b7f4ce31e46620dd84f97e984b6f40c9f7f285f /app/src/main/java/se/leap/bitmaskclient/providersetup | |
parent | 53381d8985bf881723d065a0cc6f7ae465d72933 (diff) |
add new java swagger model classes to Provider model, replace java models of generated go swagger structs
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/providersetup')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java index 254591a2..6e748afa 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java @@ -38,11 +38,13 @@ import java.security.cert.X509Certificate; import java.util.ArrayList; import de.blinkt.openvpn.core.VpnStatus; +import io.swagger.client.JSON; +import io.swagger.client.model.ModelsBridge; +import io.swagger.client.model.ModelsEIPService; +import io.swagger.client.model.ModelsGateway; +import io.swagger.client.model.ModelsProvider; import mobile.BitmaskMobile; -import mobilemodels.Bridges; -import mobilemodels.Gateways; -import models.ModelsEIPService; -import models.ModelsProvider; +import se.leap.bitmaskclient.BuildConfig; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.base.models.ProviderObservable; @@ -119,7 +121,8 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro configureBaseCountryCode(bm, parameters); try { - ModelsEIPService service = bm.getService(); + String serviceJson = bm.getService(); + ModelsEIPService service = JSON.createGson().create().fromJson(serviceJson, ModelsEIPService.class); provider.setService(service); } catch (Exception e) { return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null); @@ -127,19 +130,24 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro if (PreferenceHelper.getUseBridges()) { try { - Bridges bridges = bm.getAllBridges("", "", "", ""); - if (bridges.length() == 0) { + String bridgesJson = bm.getAllBridges("", "", "", ""); + if (bridgesJson.isEmpty()) { //TODO send no bridges error event } + ModelsBridge[] bridges = JSON.createGson().create().fromJson(bridgesJson, ModelsBridge[].class); provider.setBridges(bridges); } catch (Exception e) { // TODO: send failed to fetch bridges event } } else { - Gateways gateways = null; - try { - gateways = bm.getAllGateways("", "", ""); - provider.setGateways(gateways); + try { + String gatewaysJson = bm.getAllGateways("", "", ""); + if (gatewaysJson.isEmpty()) { + //TODO send no bridges error event + } + ModelsGateway[] gateways = JSON.createGson().create().fromJson(gatewaysJson, ModelsGateway[].class); + + provider.setGateways(gateways); } catch (Exception e) { // TODO: send return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null); @@ -189,33 +197,49 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro configureBaseCountryCode(bm, parameters); try { - ModelsProvider p = bm.getProvider(); + String providerJson = bm.getProvider(); + Log.d(TAG, "provider Json reponse: " + providerJson); + ModelsProvider p = JSON.createGson().create().fromJson(providerJson, ModelsProvider.class); provider.setModelsProvider(p); ProviderSetupObservable.updateProgress(DOWNLOADED_PROVIDER_JSON); } catch (Exception e) { + Log.w(TAG, "failed fo fetch provider.json: " + e.getMessage()); + e.printStackTrace(); return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null); } try { - ModelsEIPService service = bm.getService(); + String serviceJson = bm.getService(); + Log.d(TAG, "service Json reponse: " + serviceJson); + ModelsEIPService service = JSON.createGson().create().fromJson(serviceJson, ModelsEIPService.class); provider.setService(service); ProviderSetupObservable.updateProgress(DOWNLOADED_EIP_SERVICE_JSON); } catch (Exception e) { + Log.w(TAG, "failed to fetch service.json: " + e.getMessage()); + e.printStackTrace(); return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null); } try { // TODO: check if provider supports this API endpoint? - Gateways gateways = bm.getAllGateways("", "", ""); + String gatewaysJson = bm.getAllGateways("", "", ""); + Log.d(TAG, "gateways Json reponse: " + gatewaysJson); + ModelsGateway[] gateways = JSON.createGson().create().fromJson(gatewaysJson, ModelsGateway[].class); provider.setGateways(gateways); } catch (Exception e) { + Log.w(TAG, "failed to fetch gateways: " + e.getMessage()); + e.printStackTrace(); return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null); } try { // TODO: check if provider supports this API endpoint? - Bridges bridges = bm.getAllBridges("", "", "", ""); + String bridgesJson = bm.getAllBridges("", "", "", ""); + Log.d(TAG, "bridges Json reponse: " + bridgesJson); + ModelsBridge[] bridges = JSON.createGson().create().fromJson(bridgesJson, ModelsBridge[].class); provider.setBridges(bridges); } catch (Exception e) { + Log.w(TAG, "failed to fetch bridges: " + e.getMessage()); + e.printStackTrace(); return eventSender.setErrorResult(currentDownload, R.string.error_json_exception_user_message, null); } @@ -237,14 +261,14 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro TorStatusObservable.getStatus() == OFF) { try { // FIXME: doGeolocationLookup currently sets the country code implicitly, change that in bitmask-core - bm.doGeolocationLookup(); + cc = bm.getGeolocation(); } catch (Exception e) { // print exception and ignore e.printStackTrace(); + cc = ""; } - } else { - bm.setCountryCode(cc); } + bm.setCountryCode(cc); } Bundle validateProviderDetails(Provider provider) { |