Skip to content

Commit

Permalink
Merge pull request #26210 from brave/update_automatic_flag_behaviour_vpn
Browse files Browse the repository at this point in the history
Resolve an issue with automatic flag for timezone
  • Loading branch information
deeppandya authored Oct 25, 2024
2 parents e83e96e + 446a2ae commit 3373071
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import org.chromium.brave_vpn.mojom.BraveVpnConstants;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.billing.InAppPurchaseWrapper;
import org.chromium.chrome.browser.billing.PurchaseModel;
Expand Down Expand Up @@ -65,31 +66,37 @@ public static void handleOnGetTimezonesForRegions(Activity activity,
BraveVpnServerRegion braveVpnServerRegion =
BraveVpnUtils.getServerRegionForTimeZone(
jsonTimezones, TimeZone.getDefault().getID());
String region = braveVpnServerRegion.getRegionName();
if (TextUtils.isEmpty(region)) {
String regionFromTimeZone = braveVpnServerRegion.getRegionName();
if (TextUtils.isEmpty(regionFromTimeZone)) {
BraveVpnUtils.showToast(
String.format(
activity.getResources()
.getString(R.string.couldnt_get_matching_timezone),
TimeZone.getDefault().getID()));
return;
}
if (BraveVpnUtils.selectedServerRegion != null) {
if (!BraveVpnUtils.selectedServerRegion
.getRegionName()
.equals(BraveVpnPrefUtils.PREF_BRAVE_VPN_AUTOMATIC)) {
region = BraveVpnUtils.selectedServerRegion.getRegionName();
braveVpnServerRegion = BraveVpnUtils.selectedServerRegion;
}
String regionForHostName = regionFromTimeZone;
String regionPrecision = braveVpnServerRegion.getRegionPrecision();

// Determine the region for host name and precision
if (BraveVpnUtils.selectedServerRegion != null
&& !BraveVpnUtils.selectedServerRegion
.getRegionName()
.equals(BraveVpnPrefUtils.PREF_BRAVE_VPN_AUTOMATIC)) {

regionForHostName = BraveVpnUtils.selectedServerRegion.getRegionName();
braveVpnServerRegion = BraveVpnUtils.selectedServerRegion;
regionPrecision = braveVpnServerRegion.getRegionPrecision();
} else {
String serverRegion = BraveVpnPrefUtils.getRegionName();
region =
serverRegion.equals(BraveVpnPrefUtils.PREF_BRAVE_VPN_AUTOMATIC)
? region
: serverRegion;
if (serverRegion.equals(BraveVpnPrefUtils.PREF_BRAVE_VPN_AUTOMATIC)) {
regionPrecision = BraveVpnConstants.REGION_PRECISION_DEFAULT;
} else {
regionForHostName = serverRegion;
}
}
BraveVpnNativeWorker.getInstance()
.getHostnamesForRegion(region, braveVpnServerRegion.getRegionPrecision());
.getHostnamesForRegion(regionForHostName, regionPrecision);
braveVpnPrefModel.setServerRegion(braveVpnServerRegion);
} else {
BraveVpnUtils.showToast(
Expand Down

0 comments on commit 3373071

Please sign in to comment.