From 5a9e76403d352a58599ac5cc70ab42e079905ba0 Mon Sep 17 00:00:00 2001 From: vladimir Date: Tue, 17 Jan 2023 13:52:52 +0200 Subject: [PATCH] Add android specific debug info --- api/config.go | 2 +- log/output.go | 4 ++-- utils/debug/debug.go | 36 ------------------------------ utils/debug/debug_android.go | 29 ++++++++++++++++++++++++ utils/debug/debug_default.go | 43 ++++++++++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 39 deletions(-) create mode 100644 utils/debug/debug_android.go create mode 100644 utils/debug/debug_default.go diff --git a/api/config.go b/api/config.go index 7b037d88..9e9fac10 100644 --- a/api/config.go +++ b/api/config.go @@ -64,7 +64,7 @@ func registerConfig() error { err = config.Register(&config.Option{ Name: "API Keys", Key: CfgAPIKeys, - Description: "Define API keys for priviledged access to the API. Every entry is a separate API key with respective permissions. Format is `?read=&write=`. Permissions are `anyone`, `user` and `admin`, and may be omitted.", + Description: "Define API keys for privileged access to the API. Every entry is a separate API key with respective permissions. Format is `?read=&write=`. Permissions are `anyone`, `user` and `admin`, and may be omitted.", Sensitive: true, OptType: config.OptTypeStringArray, ExpertiseLevel: config.ExpertiseLevelDeveloper, diff --git a/log/output.go b/log/output.go index f3831c25..d8a29a40 100644 --- a/log/output.go +++ b/log/output.go @@ -17,10 +17,10 @@ type ( // AdapterFunc is a convenience type for implementing // Adapter. - AdapterFunc func(msg Message, duplciates uint64) + AdapterFunc func(msg Message, duplicates uint64) // FormatFunc formats msg into a string. - FormatFunc func(msg Message, duplciates uint64) string + FormatFunc func(msg Message, duplicates uint64) string // SimpleFileAdapter implements Adapter and writes all // messages to File. diff --git a/utils/debug/debug.go b/utils/debug/debug.go index 7ff5dec0..70e5192d 100644 --- a/utils/debug/debug.go +++ b/utils/debug/debug.go @@ -2,14 +2,11 @@ package debug import ( "bytes" - "context" "fmt" "runtime/pprof" "strings" "time" - "github.com/shirou/gopsutil/host" - "github.com/safing/portbase/info" "github.com/safing/portbase/log" "github.com/safing/portbase/modules" @@ -94,39 +91,6 @@ func (di *Info) AddVersionInfo() { ) } -// AddPlatformInfo adds OS and platform information. -func (di *Info) AddPlatformInfo(ctx context.Context) { - // Get information from the system. - info, err := host.InfoWithContext(ctx) - if err != nil { - di.AddSection( - "Platform Information", - NoFlags, - fmt.Sprintf("Failed to get: %s", err), - ) - return - } - - // Check if we want to add virtulization information. - var virtInfo string - if info.VirtualizationRole == "guest" { - if info.VirtualizationSystem != "" { - virtInfo = fmt.Sprintf("VM: %s", info.VirtualizationSystem) - } else { - virtInfo = "VM: unidentified" - } - } - - // Add section. - di.AddSection( - fmt.Sprintf("Platform: %s %s", info.Platform, info.PlatformVersion), - UseCodeSection|AddContentLineBreaks, - fmt.Sprintf("System: %s %s (%s) %s", info.Platform, info.OS, info.PlatformFamily, info.PlatformVersion), - fmt.Sprintf("Kernel: %s %s", info.KernelVersion, info.KernelArch), - virtInfo, - ) -} - // AddGoroutineStack adds the current goroutine stack. func (di *Info) AddGoroutineStack() { buf := new(bytes.Buffer) diff --git a/utils/debug/debug_android.go b/utils/debug/debug_android.go new file mode 100644 index 00000000..6a4496d6 --- /dev/null +++ b/utils/debug/debug_android.go @@ -0,0 +1,29 @@ +package debug + +import ( + "context" + "fmt" + + "github.com/safing/portmaster-android/go/app_interface" +) + +// AddPlatformInfo adds OS and platform information. +func (di *Info) AddPlatformInfo(_ context.Context) { + // Get information from the system. + info, err := app_interface.GetPlatformInfo() + if err != nil { + di.AddSection( + "Platform Information", + NoFlags, + fmt.Sprintf("Failed to get: %s", err), + ) + return + } + + // Add section. + di.AddSection( + fmt.Sprintf("Platform: Android %s", info.VersionCode), + UseCodeSection|AddContentLineBreaks, + fmt.Sprintf("SDK: %d %s", info.SDK, info.Incremental), + fmt.Sprintf("Device: %s %s (%s)", info.Manufacturer, info.Brand, info.Board)) +} diff --git a/utils/debug/debug_default.go b/utils/debug/debug_default.go new file mode 100644 index 00000000..cb429b81 --- /dev/null +++ b/utils/debug/debug_default.go @@ -0,0 +1,43 @@ +//go:build !android + +package debug + +import ( + "context" + "fmt" + + "github.com/shirou/gopsutil/host" +) + +// AddPlatformInfo adds OS and platform information. +func (di *Info) AddPlatformInfo(ctx context.Context) { + // Get information from the system. + info, err := host.InfoWithContext(ctx) + if err != nil { + di.AddSection( + "Platform Information", + NoFlags, + fmt.Sprintf("Failed to get: %s", err), + ) + return + } + + // Check if we want to add virtulization information. + var virtInfo string + if info.VirtualizationRole == "guest" { + if info.VirtualizationSystem != "" { + virtInfo = fmt.Sprintf("VM: %s", info.VirtualizationSystem) + } else { + virtInfo = "VM: unidentified" + } + } + + // Add section. + di.AddSection( + fmt.Sprintf("Platform: %s %s", info.Platform, info.PlatformVersion), + UseCodeSection|AddContentLineBreaks, + fmt.Sprintf("System: %s %s (%s) %s", info.Platform, info.OS, info.PlatformFamily, info.PlatformVersion), + fmt.Sprintf("Kernel: %s %s", info.KernelVersion, info.KernelArch), + virtInfo, + ) +}