-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[client] Android debug bundle support #5888
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b317825
Fix debug bundle temp file creation on Android
pappz 1d792f0
Add logcat log collection for Android debug bundles
pappz a35ecf9
Add DebugBundle method with PlatformFiles fallback
pappz f01c1ee
Add timeout to debug bundle upload on Android
pappz 1c2275e
Streams logcat output through the anonymizer via io.Pipe
pappz 0920e6a
Update linter in makefile
pappz aa1c194
Protect Android Client state with RWMutex
pappz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //go:build android | ||
|
|
||
| package debug | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "os/exec" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| func (g *BundleGenerator) addPlatformLog() error { | ||
| cmd := exec.Command("/system/bin/logcat", "-d") | ||
| stdout, err := cmd.StdoutPipe() | ||
| if err != nil { | ||
| return fmt.Errorf("logcat stdout pipe: %w", err) | ||
| } | ||
|
|
||
| if err := cmd.Start(); err != nil { | ||
| return fmt.Errorf("start logcat: %w", err) | ||
| } | ||
|
|
||
| var logReader io.Reader = stdout | ||
| if g.anonymize { | ||
| var pw *io.PipeWriter | ||
| logReader, pw = io.Pipe() | ||
| go anonymizeLog(stdout, pw, g.anonymizer) | ||
| } | ||
|
|
||
| if err := g.addFileToZip(logReader, "logcat.txt"); err != nil { | ||
| return fmt.Errorf("add logcat to zip: %w", err) | ||
| } | ||
|
|
||
| if err := cmd.Wait(); err != nil { | ||
| return fmt.Errorf("wait logcat: %w", err) | ||
| } | ||
|
|
||
| log.Debug("added logcat output to debug bundle") | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //go:build !android | ||
|
|
||
| package debug | ||
|
|
||
| import ( | ||
| "slices" | ||
|
|
||
| log "github.com/sirupsen/logrus" | ||
|
|
||
| "github.com/netbirdio/netbird/util" | ||
| ) | ||
|
|
||
| func (g *BundleGenerator) addPlatformLog() error { | ||
| if g.logPath != "" && !slices.Contains(util.SpecialLogs, g.logPath) { | ||
| if err := g.addLogfile(); err != nil { | ||
| log.Errorf("failed to add log file to debug bundle: %v", err) | ||
| if err := g.trySystemdLogFallback(); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } else if err := g.trySystemdLogFallback(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StateFilePath()is still ignored for Android debug bundles.DebugBundlereceivesplatformFiles, but only uses the config path and cache dir. The bundle generator still resolvesstate.jsonfrom the default service-manager location, so Troubleshoot bundles created from the Android app will miss the real sandboxed state file. Please threadplatformFiles.StateFilePath()intoGeneratorDependenciesand makeaddStateFile()use it.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Android, addStateFile() calls NewServiceManager("").GetStatePath() which resolves to /var/lib/netbird/state.json (the Linux default), not the app's actual state file path that Java passes via PlatformFiles.StateFilePath(). The bundle silently skips the state file since that path doesn't exist on Android.
However, this is a pre-existing issue in the upstream debug.go, not something introduced by this PR. The fix would involve adding a StatePath field to GeneratorDependencies and threading it through addStateFile() with a fallback to the current ServiceManager lookup when empty. I'll address this in a follow-up to keep this PR focused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pappz, thanks for the detailed explanation — that confirms this is a pre-existing gap indebug.go, not a regression introduced here. The fix approach you've described (adding aStatePathfield toGeneratorDependencieswith a fallback toNewServiceManager("").GetStatePath()when empty) sounds right. Happy to keep this PR focused and defer to a follow-up.Would you like me to open a GitHub issue to track this? It would capture the context:
addStateFile()on Android resolves to/var/lib/netbird/state.jsonviaNewServiceManagerinstead of the app-sandbox path fromPlatformFiles.StateFilePath(), and the fix involves threadingStatePaththroughGeneratorDependencies.✏️ Learnings added
🧠 Learnings used