summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2024-10-11 13:42:44 +0200
committercyberta <cyberta@riseup.net>2024-12-11 00:09:34 +0000
commitd39906d0111a44aca40da352f992d6e4519b9d68 (patch)
tree10d1e2efdf9b30ce550e3a7833740e5787aac85a /app/src/main/java/se/leap/bitmaskclient
parent42859e489e7bb21a9346ad0fdb5cf99c9812ac8e (diff)
implement ProviderAPI's DOWNLOAD_SERVICE_JSON action for v5
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java55
1 files changed, 55 insertions, 0 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 b425cfb7..254591a2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiManagerV5.java
@@ -71,6 +71,17 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro
eventSender.sendToReceiverOrBroadcast(receiver, PROVIDER_NOK, result, provider);
}
break;
+
+ case DOWNLOAD_SERVICE_JSON:
+ result = updateServiceInfos(provider, parameters);
+ if (result.getBoolean(BROADCAST_RESULT_KEY)) {
+ serviceCallback.saveProvider(provider);
+ eventSender.sendToReceiverOrBroadcast(receiver, CORRECTLY_DOWNLOADED_EIP_SERVICE, result, provider);
+ } else {
+ eventSender.sendToReceiverOrBroadcast(receiver, INCORRECTLY_DOWNLOADED_EIP_SERVICE, result, provider);
+ }
+ break;
+
case DOWNLOAD_VPN_CERTIFICATE:
result = updateVpnCertificate(provider);
if (result.getBoolean(BROADCAST_RESULT_KEY)) {
@@ -95,6 +106,50 @@ public class ProviderApiManagerV5 extends ProviderApiManagerBase implements IPro
}
+ private Bundle updateServiceInfos(Provider provider, Bundle parameters) {
+ Bundle currentDownload = new Bundle();
+
+ BitmaskMobile bm;
+ try {
+ bm = new BitmaskMobile(provider.getMainUrl(), new PreferenceHelper.SharedPreferenceStore());
+ } catch (IllegalStateException e) {
+ return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null);
+ }
+
+ configureBaseCountryCode(bm, parameters);
+
+ try {
+ ModelsEIPService service = bm.getService();
+ provider.setService(service);
+ } catch (Exception e) {
+ return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null);
+ }
+
+ if (PreferenceHelper.getUseBridges()) {
+ try {
+ Bridges bridges = bm.getAllBridges("", "", "", "");
+ if (bridges.length() == 0) {
+ //TODO send no bridges error event
+ }
+ provider.setBridges(bridges);
+ } catch (Exception e) {
+ // TODO: send failed to fetch bridges event
+ }
+ } else {
+ Gateways gateways = null;
+ try {
+ gateways = bm.getAllGateways("", "", "");
+ provider.setGateways(gateways);
+ } catch (Exception e) {
+ // TODO: send
+ return eventSender.setErrorResult(currentDownload, R.string.config_error_found, null);
+
+ }
+ }
+
+ return currentDownload;
+
+ }
protected Bundle setupProvider(Provider provider, Bundle parameters) {
Bundle currentDownload = new Bundle();