Migrate to profile ids - #189
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughProfile handling now uses immutable profile IDs across the model, wrapper, UI, and engine entry points. The netbird submodule pointer also moved to a new commit. ChangesProfile Identity Refactoring
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant ProfilesFragment
participant ProfileManagerWrapper
participant GomobileProfileManager
ProfilesFragment->>ProfileManagerWrapper: switchProfile(profile.getID())
ProfileManagerWrapper->>ProfileManagerWrapper: stop VPN engine when needed
ProfileManagerWrapper->>GomobileProfileManager: switchProfile(id)
GomobileProfileManager-->>ProfileManagerWrapper: result
ProfileManagerWrapper-->>ProfilesFragment: callback
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/src/main/java/io/netbird/client/ui/profile/ProfilesFragment.java (1)
183-188:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAlways surface add-profile failures to the user.
When
e.getMessage()is null, this path only logs. Since the dialog callback still returnstrue, the dialog closes with no feedback.Suggested fix
Log.e(TAG, "Failed to add profile", e); String errorMsg = e.getMessage(); - if (errorMsg != null) { - Toast.makeText(requireContext(), - "Failed to add profile: " + e.getMessage(), - Toast.LENGTH_SHORT).show(); - } + Toast.makeText( + requireContext(), + errorMsg == null ? "Failed to add profile" : "Failed to add profile: " + errorMsg, + Toast.LENGTH_SHORT + ).show(); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/src/main/java/io/netbird/client/ui/profile/ProfilesFragment.java` around lines 183 - 188, In ProfilesFragment (the add-profile error handler where errorMsg = e.getMessage()), always show user feedback even when e.getMessage() is null: replace the conditional that only Toasts when errorMsg != null with logic that computes a safe message (use e.getMessage() if non-null, otherwise e.toString() or a generic "Failed to add profile" string) and call Toast.makeText(requireContext(), safeMessage, Toast.LENGTH_SHORT).show(); keep the rest of the dialog callback behavior unchanged so the dialog still returns true.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tool/src/main/java/io/netbird/client/tool/Profile.java`:
- Around line 10-15: Constructor Profile(String id, String name, boolean
isActive) currently allows a null id which breaks equals(), hashCode(), and
callers like ProfilesFragment.removeProfile(); validate the id parameter and
throw an IllegalArgumentException if id is null or empty, similarly to the
existing name check. Update the Profile constructor (Profile(String id, String
name, boolean isActive)) to perform the id null/empty check and document that id
is required so equals() and hashCode() can safely assume a non-null id (this
will prevent issues in ProfilesFragment.removeProfile() and calls like
profile.getID().equals(...)).
In `@tool/src/main/java/io/netbird/client/tool/ProfileManagerWrapper.java`:
- Around line 52-59: Do not return a fabricated Profile when
profileManager.getActiveProfile() fails; in getActiveProfile()
(ProfileManagerWrapper.getActiveProfile) remove the fallback new
Profile("default",...) and either return null or rethrow the exception so
callers can detect a real failure. Update callers such as logoutProfile() to
handle a null/exceptional result (check for null before comparing IDs and ensure
stopEngine() is invoked for the actual active profile) so failures don't
masquerade as a valid "default" profile.
---
Outside diff comments:
In `@app/src/main/java/io/netbird/client/ui/profile/ProfilesFragment.java`:
- Around line 183-188: In ProfilesFragment (the add-profile error handler where
errorMsg = e.getMessage()), always show user feedback even when e.getMessage()
is null: replace the conditional that only Toasts when errorMsg != null with
logic that computes a safe message (use e.getMessage() if non-null, otherwise
e.toString() or a generic "Failed to add profile" string) and call
Toast.makeText(requireContext(), safeMessage, Toast.LENGTH_SHORT).show(); keep
the rest of the dialog callback behavior unchanged so the dialog still returns
true.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5e4c18d5-613b-470a-bbf1-e9e6ae944678
📒 Files selected for processing (6)
app/src/main/java/io/netbird/client/MainActivity.javaapp/src/main/java/io/netbird/client/ui/profile/ProfilesFragment.javanetbirdtool/src/main/java/io/netbird/client/tool/EngineRunner.javatool/src/main/java/io/netbird/client/tool/Profile.javatool/src/main/java/io/netbird/client/tool/ProfileManagerWrapper.java
There was a problem hiding this comment.
♻️ Duplicate comments (1)
tool/src/main/java/io/netbird/client/tool/ProfileManagerWrapper.java (1)
94-107: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
logoutProfilenow aborts for unrelated profiles when active-profile lookup fails.
getActiveProfile()(Lines 52-63) was just changed to throwIllegalStateExceptioninstead of returning a"default"fallback.logoutProfile()calls it unguarded at Line 100, so any active-profile lookup failure now propagates and blocks logout of any profile id, even ones unrelated to the active profile — a regression from the previous fallback behavior. This is exactly the caller-update the prior review comment called out but wasn't applied here.Also, validation at Line 95 only checks
id == null, unlikeswitchProfile/removeProfilewhich also reject blank/whitespace ids.🔧 Proposed fix
public void logoutProfile(String id) throws Exception { - if (id == null) { - throw new IllegalArgumentException("Profile name cannot be empty"); + if (id == null || id.trim().isEmpty()) { + throw new IllegalArgumentException("Profile id cannot be empty"); } // Check if logging out from active profile - Profile activeProfile = getActiveProfile(); - if (activeProfile.getID().equals(id)) { - // Stop VPN service if logging out from active profile - stopEngine(); + try { + Profile activeProfile = getActiveProfile(); + if (activeProfile.getID().equals(id)) { + // Stop VPN service if logging out from active profile + stopEngine(); + } + } catch (Exception e) { + Log.w(TAG, "Could not determine active profile before logout, proceeding without engine stop check", e); } profileManager.logoutProfile(id); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tool/src/main/java/io/netbird/client/tool/ProfileManagerWrapper.java` around lines 94 - 107, `logoutProfile` should not let `getActiveProfile()` failures block logging out unrelated profiles, and its id validation should also reject blank or whitespace-only input. Update `ProfileManagerWrapper.logoutProfile` so it only calls `stopEngine()` when an active profile is successfully available and matches the target id, while allowing logout to continue otherwise; also align the `id` check with `switchProfile` and `removeProfile` by treating empty/blank ids as invalid.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@tool/src/main/java/io/netbird/client/tool/ProfileManagerWrapper.java`:
- Around line 94-107: `logoutProfile` should not let `getActiveProfile()`
failures block logging out unrelated profiles, and its id validation should also
reject blank or whitespace-only input. Update
`ProfileManagerWrapper.logoutProfile` so it only calls `stopEngine()` when an
active profile is successfully available and matches the target id, while
allowing logout to continue otherwise; also align the `id` check with
`switchProfile` and `removeProfile` by treating empty/blank ids as invalid.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e1a1eb62-8531-49fa-8f21-5846245313ae
📒 Files selected for processing (2)
netbirdtool/src/main/java/io/netbird/client/tool/ProfileManagerWrapper.java
Squash-merge the four commits from PR #189 (profile-id branch) onto the redesign branch, adapting the profile-id migration to the new bottom-nav UI instead of the old drawer/NavigationView layout: - getActiveProfile() now returns a Profile (with ID) instead of a String; update SettingsFragment and HomeFragment callers to use getName(). - Drop the PR's drawer-specific MainActivity changes (updateProfileMenuItem, drawer onKeyDown) — the redesign replaced the drawer with bottom nav. - Graft the new disable-IPv6 switch listener into AdvancedFragment and add the IPv6 settings row to fragment_advanced.xml in the redesign row style. - Bump netbird submodule to 62afff6 (adds Profile.ID to the gomobile binding). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Squash-merge the four commits from PR #189 (profile-id branch) onto the redesign branch, adapting the profile-id migration to the new bottom-nav UI instead of the old drawer/NavigationView layout: - getActiveProfile() now returns a Profile (with ID) instead of a String; update SettingsFragment and HomeFragment callers to use getName(). - Drop the PR's drawer-specific MainActivity changes (updateProfileMenuItem, drawer onKeyDown) — the redesign replaced the drawer with bottom nav. - Graft the new disable-IPv6 switch listener into AdvancedFragment and add the IPv6 settings row to fragment_advanced.xml in the redesign row style. - Bump netbird submodule to 62afff6 (adds Profile.ID to the gomobile binding).
* Add profile id migration * Check if ID is set on Profile * Bump netbird * Update profile-id-name branch * Fix active profile errors, bump netbird * Bump netbird to v0.74.0
This PR uses the new profile ids implemented in netbirdio/netbird#6326
The go bindings are updated to use the new profile with the id field. Sanitation is removed, as this is done by the go profilemanager.
Summary by CodeRabbit