summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorcyBerta <cyberta@riseup.net>2021-11-23 12:34:00 +0100
committercyBerta <cyberta@riseup.net>2021-11-23 12:34:00 +0100
commit829849c074d397ceba59c89fe4be0bd65ea49f6f (patch)
treed0236bf91d5303d24687f263633406d7d13980b6 /app/src/main
parent9bf787465a3ae22c76249317496c8927b22ffdb4 (diff)
calculate fake load from timezone distance if menshen doesn't serve load info
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java3
2 files changed, 13 insertions, 1 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
index 92010992..6c242e5a 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/ConfigHelper.java
@@ -206,6 +206,17 @@ public class ConfigHelper {
return dist;
}
+ /**
+ *
+ * @param remoteTimezone
+ * @return a value between 0.1 and 1.0
+ */
+ public static double getConnectionQualityFromTimezoneDistance(int remoteTimezone) {
+ int localTimeZone = ConfigHelper.getCurrentTimezone();
+ int distance = ConfigHelper.timezoneDistance(localTimeZone, remoteTimezone);
+ return Math.max(distance / 12.0, 0.1);
+ }
+
public static String getProviderFormattedString(Resources resources, @StringRes int resourceId) {
String appName = resources.getString(R.string.app_name);
return resources.getString(resourceId, appName);
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
index 8a48684f..a3d3abbc 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/Gateway.java
@@ -33,6 +33,7 @@ import java.util.Set;
import de.blinkt.openvpn.VpnProfile;
import de.blinkt.openvpn.core.ConfigParser;
import de.blinkt.openvpn.core.connection.Connection;
+import se.leap.bitmaskclient.base.utils.ConfigHelper;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
import static se.leap.bitmaskclient.base.models.Constants.FULLNESS;
@@ -156,7 +157,7 @@ public class Gateway {
try {
return load.getDouble(FULLNESS);
} catch (JSONException | NullPointerException e) {
- return 0;
+ return ConfigHelper.getConnectionQualityFromTimezoneDistance(timezone);
}
}