Skip to content

feat: Add custom Android route CIDR support#208

Open
Asutorufa wants to merge 6 commits intomainfrom
feature/custom-android-routes-15319386141857302974
Open

feat: Add custom Android route CIDR support#208
Asutorufa wants to merge 6 commits intomainfrom
feature/custom-android-routes-15319386141857302974

Conversation

@Asutorufa
Copy link
Collaborator

This PR adds the ability for users to create, edit, and delete custom Android route configurations (CIDR lists).

Changes:

  1. UI:

    • Added RouteConfigScreen to list and add new routes.
    • Added RouteEditScreen to edit the CIDR content of a route or delete it.
    • Added a "Route Config" entry in the Advanced Settings to access these screens.
    • Updated the "Route" list preference in Settings to dynamically load available routes from the store.
  2. Logic:

    • MainApplication: On startup, checks if saved_routes_list exists in the store. If not, initializes it with the default routes ("All", "Non-Local", "Non-Chinese") and their standard CIDR lists.
    • YuhaiinVpnService: Modified configure() to fetch the selected route's CIDR content from the store (key route_content_<Name>) instead of using hardcoded logic. Added a fallback to 0.0.0.0/0 and ::/0 if the content is empty.
  3. Validation:

    • Route names cannot contain / to prevent navigation issues.
    • Route content is validated line-by-line using Yuhaiin.parseCIDR. Invalid lines prevent saving.
  4. Resources:

    • Added necessary string resources and a vector drawable for the save icon.

PR created automatically by Jules for task 15319386141857302974 started by @Asutorufa

- Introduced `RouteConfigScreen` and `RouteEditScreen` for managing custom routes.
- Stored route configurations in `MainApplication.Store` with editable CIDR lists.
- Initialized default routes (All, Non-Local, Non-Chinese) as editable saved routes.
- Updated `YuhaiinVpnService` to use dynamic route configuration from the store.
- Updated `Setting` screen to link to the new route configuration UI.
- Added input validation for route names and CIDR content.

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Asutorufa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application's network routing capabilities by providing users with the flexibility to define and manage their own custom Android route configurations. This allows for more granular control over network traffic, moving away from static, predefined routes to a fully customizable system that adapts to user-specific needs and preferences.

Highlights

  • Custom Route Configuration UI: Introduced new UI screens (RouteConfigScreen and RouteEditScreen) allowing users to create, edit, and delete custom Android route configurations (CIDR lists). A new 'Route Config' entry has been added to Advanced Settings for access.
  • Dynamic Route Loading and Persistence: The application now dynamically loads available routes from the store. On startup, MainApplication initializes default routes ('All', 'Non-Local', 'Non-Chinese') if no custom routes are saved. The 'Route' list preference in Settings is updated to reflect these dynamic routes.
  • VPN Service Integration: The YuhaiinVpnService has been modified to fetch the selected route's CIDR content directly from the store, replacing previously hardcoded logic. A fallback to 0.0.0.0/0 and ::/0 is implemented if the route content is empty.
  • Input Validation: Implemented validation for custom route names (disallowing '/') and route content. CIDR entries are validated line-by-line using Yuhaiin.parseCIDR, preventing invalid configurations from being saved.
  • New Resources: Added new string resources for the route configuration screens and an updated vector drawable for a save icon.
Changelog
  • app/src/main/kotlin/io/github/asutorufa/yuhaiin/MainApplication.kt
    • Added initRoutes() function to initialize default route configurations ('All', 'Non-Local', 'Non-Chinese') and their corresponding CIDR lists in the store if they don't already exist.
    • Called initRoutes() during application startup.
  • app/src/main/kotlin/io/github/asutorufa/yuhaiin/compose/Main.kt
    • Imported RouteConfigScreen and RouteEditScreen for navigation.
    • Added composable routes for RouteConfig and RouteEdit/{routeName} to the navigation graph, enabling access to the new route management screens.
  • app/src/main/kotlin/io/github/asutorufa/yuhaiin/compose/Setting.kt
    • Imported RouteConfig and getStringSet for route management.
    • Modified the ListPreferenceSetting for routes to dynamically load entries from saved_routes_list in the store, falling back to default string array if not found.
    • Added a RouteConfig settings item to the Advanced Settings section, which navigates to the RouteConfigScreen.
  • app/src/main/kotlin/io/github/asutorufa/yuhaiin/compose/route/RouteConfig.kt
    • New file: Defines the RouteConfig Composable, which is a SettingsItem that serves as the entry point to the route configuration screens.
  • app/src/main/kotlin/io/github/asutorufa/yuhaiin/compose/route/RouteConfigScreen.kt
    • New file: Implements RouteConfigScreen for listing existing custom routes and providing an option to add new ones.
    • Implements RouteEditScreen for editing the CIDR content of a specific route and deleting it.
    • Includes dialogs for adding new routes and confirming route deletion.
    • Incorporates input validation for route names (no empty names, no duplicates, no '/' character) and CIDR content (line-by-line parsing).
  • app/src/main/kotlin/io/github/asutorufa/yuhaiin/service/YuhaiinVpnService.kt
    • Removed the when statement that hardcoded route selection logic based on string resources.
    • Modified configure() to retrieve the selected route's name from the store and then fetch its corresponding CIDR content (route_content_<Name>) from the store.
    • Iterates through the fetched CIDR content (split by newline) and adds each valid CIDR to the VPN service configuration.
    • Added a fallback to 0.0.0.0/0 and ::/0 if the fetched route content is blank.
  • app/src/main/res/drawable/save.xml
    • Updated the vector drawable for the save icon to a different design.
  • app/src/main/res/values/route_strings.xml
    • New file: Added various string resources for the route configuration UI, including titles, hints, error messages, and confirmation texts.
Activity
  • The pull request was created by Asutorufa to address task 15319386141857302974.
  • No further human activity (comments, reviews, or progress updates) has been recorded on this pull request since its creation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces custom route configuration, covering UI for creation, editing, and deletion, and backend logic. However, there are security and performance concerns: heavy operations like JSON parsing and large string splitting on the main thread can cause ANR issues, and route name validation is insufficient against navigation-related injection. Additionally, consider centralizing store keys, optimizing CIDR validation, using formatted string resources for UI text, and cleaning up redundant validation logic.

google-labs-jules bot and others added 5 commits February 9, 2026 09:55
- Introduced `RouteConfigScreen` and `RouteEditScreen` for managing custom routes.
- Stored route configurations in `MainApplication.Store` with editable CIDR lists.
- Initialized default routes (All, Non-Local, Non-Chinese) as editable saved routes.
- Updated `YuhaiinVpnService` to use dynamic route configuration from the store.
- Updated `Setting` screen to link to the new route configuration UI.
- Added `Store.remove` extension function to handle route deletion.
- Added input validation for route names and CIDR content.

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
- Introduced `RouteConfigScreen` and `RouteEditScreen` for managing custom routes.
- Stored route configurations in `MainApplication.Store` with editable CIDR lists.
- Initialized default routes (All, Non-Local, Non-Chinese) as editable saved routes.
- Updated `YuhaiinVpnService` to use dynamic route configuration from the store.
- Updated `Setting` screen to link to the new route configuration UI.
- Added `Store.remove` extension function to handle route deletion.
- Added input validation for route names and CIDR content.
- Ensured no mock artifacts are included in the build.

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
- Introduced `RouteConfigScreen` and `RouteEditScreen` for managing custom routes.
- Stored route configurations in `MainApplication.Store` with editable CIDR lists.
- Initialized default routes (All, Non-Local, Non-Chinese) as editable saved routes.
- Updated `YuhaiinVpnService` to use dynamic route configuration from the store.
- Updated `Setting` screen to link to the new route configuration UI.
- Added `Store.remove` extension function to handle route deletion.
- Added input validation for route names and CIDR content.
- Refined UI with swipe-to-delete, monospace font for editing, and shared element transitions.

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
- Introduced `RouteConfigScreen` and `RouteEditScreen` for managing custom routes.
- Stored route configurations in `MainApplication.Store` with editable CIDR lists.
- Initialized default routes (All, Non-Local, Non-Chinese) as editable saved routes.
- Updated `YuhaiinVpnService` to use dynamic route configuration from the store.
- Updated `Setting` screen to link to the new route configuration UI.
- Added `Store.remove` extension function to handle route deletion.
- Added input validation for route names and CIDR content.
- Refined UI with swipe-to-delete, monospace font for editing, and shared element transitions.
- Fixed an issue where swipe-to-delete would not reset if cancelled.

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
- Introduced `RouteConfigScreen` and `RouteEditScreen` for managing custom routes.
- Stored route configurations in `MainApplication.Store` with editable CIDR lists.
- Initialized default routes (All, Non-Local, Non-Chinese) as editable saved routes.
- Updated `YuhaiinVpnService` to use dynamic route configuration from the store.
- Updated `Setting` screen to link to the new route configuration UI.
- Added `Store.remove` extension function to handle route deletion.
- Added input validation for route names and CIDR content.
- Refined UI with swipe-to-delete, monospace font for editing, and shared element transitions.
- Fixed threading issues by moving store operations to background threads.
- Centralized store keys in `Constants.kt`.

Co-authored-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant