Skip to content

Advanced server selection ux #25089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 31 commits into from
Sep 6, 2024
Merged

Advanced server selection ux #25089

merged 31 commits into from
Sep 6, 2024

Conversation

deeppandya
Copy link
Contributor

@deeppandya deeppandya commented Aug 12, 2024

Resolves brave/brave-browser#36277
Resolves brave/brave-browser#38186

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Android

Automatic

  1. Buy IAP subscription on fresh profile
  2. Create VPN profile
  3. Turn on VPN
  4. Go to Server selection page
  5. Observe -> Automatic should be selected

Optimal server location from the selected region

  1. Go to Server selection page
  2. Select USA as region
  3. On the next page, select Optimal
  4. Observe - > Best server location would be selected and it could give different location based on the available resources on the location at the time.

Specific server selection

  1. Go to Server selection page
  2. Select USA as region
  3. On the next page, select Atlanta
  4. Observe -> Atlanta should be selected as server location

Upgrade scenario

  1. After the upgrade, Go to Server selection page
  2. Observe -> Selected region from previous version should also be selected in the new UI
  3. Tap on the region
  4. And on the next page, Observe -> Optimal should be selected as we didn't have a granular details from previous version.
  5. New version of the app would follow the new changes moving forward

Desktop

BraveVPNServiceTest.*
BraveVPNUtilsUnitTest.*

  1. Open vpn panel and check main panel has sub label such as Optimal or city name.
image image
  1. Go to select page in vpn panel. Each country shows detailed server/city info in the sublabel
image
  1. Click country entry and it shows Optimal sub entry and its cities
image
  1. When click connect on Optimal, main panel's sub label has Optimal or city name if clicked on each city entry like the screen shot above at 1 step

  2. When click connen on country, it goes with optimal.
    image

  3. Select server panel has Automatic entry at the top. When clicks it, it picks current timezone's region
    image

  4. Existing users will see previously selected country with Optimal region

@deeppandya deeppandya force-pushed the advanced_server_selection_ux branch 2 times, most recently from 4de31c7 to 9390ef8 Compare August 19, 2024 20:33
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Aug 19, 2024
@deeppandya deeppandya force-pushed the advanced_server_selection_ux branch 4 times, most recently from 1cef4c4 to 0aaa6dc Compare August 21, 2024 23:50
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@simonhong simonhong self-assigned this Aug 27, 2024
@simonhong simonhong force-pushed the advanced_server_selection_ux branch from 618fbfe to b490aea Compare August 29, 2024 07:15
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@simonhong simonhong force-pushed the advanced_server_selection_ux branch 5 times, most recently from be17e54 to 02989ef Compare September 2, 2024 08:14
@deeppandya deeppandya force-pushed the advanced_server_selection_ux branch from 243e82b to 1bcc82e Compare September 4, 2024 21:43
@deeppandya deeppandya marked this pull request as ready for review September 4, 2024 21:44
@deeppandya deeppandya requested review from a team as code owners September 4, 2024 21:44
@deeppandya deeppandya force-pushed the advanced_server_selection_ux branch from 9100adc to 6965c93 Compare September 5, 2024 21:59
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

components/brave_vpn/resources LGTM with some nits

})

handler.on(Actions.purchaseExpired.getType(), async (store) => {
const [{ currentRegion }, { regions }] = await Promise.all([
getPanelBrowserAPI().serviceHandler.getSelectedRegion(),
getPanelBrowserAPI().serviceHandler.getAllRegions()
getPanelBrowserAPI().serviceHandler.getAllRegions(
REGION_PRECISION_CITY_BY_COUNTRY
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever call this function with a different precision?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we only call with this arg.
@deeppandya maybe we don't need to have param for this api(GetAllRegions)?
If you don't mind, I could change this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed that it may be useful for the desktop as it provides a different response based on the region_precision. If it's not useful for the desktop, we can surely get rid of it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 6f24b64

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops accidentally commented instead of approving

Copy link
Contributor

github-actions bot commented Sep 6, 2024

[puLL-Merge] - brave/brave-core@25089

Description

This PR implements significant changes to the Brave VPN feature, particularly focusing on the server selection functionality and UI improvements. The changes include updates to the region data structure, new API endpoints, UI enhancements for server selection, and modifications to the VPN service handling.

Changes

Changes

  1. Android Java Changes:

    • Added new activities and adapters for VPN server selection.
    • Updated existing VPN-related activities and adapters.
    • Modified BraveVpnNativeWorker to support new region data structure.
    • Added BraveVpnServiceFactoryAndroid for mojo interface handling.
  2. C++ Changes:

    • Updated BraveVpnService and related classes to support new region data structure.
    • Added new methods for handling region selection and data fetching.
    • Modified API request handling for new endpoints.
  3. UI/UX Changes:

    • Updated panel UI components for improved server selection experience.
    • Added new localized strings for server selection UI.
    • Implemented new UI for displaying country and city-level server information.
  4. Data Structure Changes:

    • Updated Region struct to include more detailed information (cities, server count, etc.).
    • Modified region data parsing and storage methods.
  5. Preference Handling:

    • Added new preferences for VPN region list version and automatic server selection.
    • Implemented migration for older region selection preferences.
  6. Mojo Interface Updates:

    • Modified brave_vpn.mojom to support new region data structure and methods.
  7. Resource Updates:

    • Added new icons and updated existing ones for VPN UI.

Possible Issues

  1. The changes to the region data structure and selection process may require careful testing to ensure backward compatibility with existing user configurations.
  2. The new UI for server selection introduces more complexity, which could potentially lead to performance issues on lower-end devices.

Security Hotspots

No significant security hotspots were identified in this change. However, as with any network-related feature, careful review of the new API endpoints and data handling should be conducted to ensure no sensitive information is exposed.

@@ -24,13 +28,36 @@ export const getLocale = (key: string, replacements?: Record<string, string>) =>

if (replacements) {
for (let item in replacements) {
returnVal = returnVal.replace(new RegExp('\\[\\[\\s*' + item + '\\s*\\]\\]'), replacements[item].toString())
returnVal = returnVal.replace(
new RegExp('\\[\\[\\s*' + item + '\\s*\\]\\]'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] RegExp() called with a replacements function argument, this might allow an attacker to cause a Regular Expression Denial-of-Service (ReDoS) within your application as RegExP blocks the main thread. For this reason, it is recommended to use hardcoded regexes instead. If your regex is run on user-controlled input, consider performing input validation or use a regex checking/sanitization library such as https://www.npmjs.com/package/recheck to verify that the regex does not appear vulnerable to ReDoS.

Source: https://semgrep.dev/r/javascript.lang.security.audit.detect-non-literal-regexp.detect-non-literal-regexp


Cc @thypon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a formatting change

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks @simonhong !

@simonhong
Copy link
Member

lgtm thanks @simonhong !

Thanks for great review :)

#if BUILDFLAG(IS_ANDROID)
api_request_->GetServerRegions(
base::BindOnce(&BraveVpnService::OnFetchRegionList,
base::Unretained(this), std::move(callback)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reported by reviewdog 🐶
[semgrep] base::Unretained is most of the time unrequited, and a weak reference is better suited for secure coding.
Consider swapping Unretained for a weak reference.
base::Unretained usage may be acceptable when a callback owner is guaranteed
to be destroyed with the object base::Unretained is pointing to, for example:

- PrefChangeRegistrar
- base::*Timer
- mojo::Receiver
- any other class member destroyed when the class is deallocated


Source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/client/chromium-uaf.yaml


Cc @thypon @goodov @iefremov

@deeppandya deeppandya merged commit f67bdee into master Sep 6, 2024
17 checks passed
@deeppandya deeppandya deleted the advanced_server_selection_ux branch September 6, 2024 12:36
@github-actions github-actions bot added this to the 1.71.x - Nightly milestone Sep 6, 2024
brave-builds added a commit that referenced this pull request Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build needs-security-review puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Desktop] Add advanced server selection UX to Brave VPN [Android] Update UX with advanced server selection