From d353838a9763e2d13ca2d67f4b974f97e83442c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Thu, 30 May 2024 14:20:06 +0200 Subject: [PATCH] Fill the UI version info in system meta on Android --- client/android/client.go | 7 ++++++- client/system/info.go | 3 +++ client/system/info_android.go | 24 ++++++++++++++++++++---- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/client/android/client.go b/client/android/client.go index d0efb47ed27..d937e132e35 100644 --- a/client/android/client.go +++ b/client/android/client.go @@ -57,15 +57,17 @@ type Client struct { ctxCancel context.CancelFunc ctxCancelLock *sync.Mutex deviceName string + uiVersion string networkChangeListener listener.NetworkChangeListener } // NewClient instantiate a new Client -func NewClient(cfgFile, deviceName string, tunAdapter TunAdapter, iFaceDiscover IFaceDiscover, networkChangeListener NetworkChangeListener) *Client { +func NewClient(cfgFile, deviceName string, uiVersion string, tunAdapter TunAdapter, iFaceDiscover IFaceDiscover, networkChangeListener NetworkChangeListener) *Client { net.SetAndroidProtectSocketFn(tunAdapter.ProtectSocket) return &Client{ cfgFile: cfgFile, deviceName: deviceName, + uiVersion: uiVersion, tunAdapter: tunAdapter, iFaceDiscover: iFaceDiscover, recorder: peer.NewRecorder(""), @@ -88,6 +90,9 @@ func (c *Client) Run(urlOpener URLOpener, dns *DNSList, dnsReadyListener DnsRead var ctx context.Context //nolint ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName) + //nolint + ctxWithValues = context.WithValue(ctxWithValues, system.UiVersionCtxKey, c.uiVersion) + c.ctxCancelLock.Lock() ctx, c.ctxCancel = context.WithCancel(ctxWithValues) defer c.ctxCancel() diff --git a/client/system/info.go b/client/system/info.go index 097c6706e43..e2e0572061f 100644 --- a/client/system/info.go +++ b/client/system/info.go @@ -20,6 +20,9 @@ const OsVersionCtxKey = "OsVersion" // OsNameCtxKey context key for operating system name const OsNameCtxKey = "OsName" +// UiVersionCtxKey context key for user UI version +const UiVersionCtxKey = "user-agent" + type NetworkAddress struct { NetIP netip.Prefix Mac string diff --git a/client/system/info_android.go b/client/system/info_android.go index be62352f709..7f5dd371b8a 100644 --- a/client/system/info_android.go +++ b/client/system/info_android.go @@ -28,10 +28,18 @@ func GetInfo(ctx context.Context) *Info { kernelVersion = osInfo[2] } - gio := &Info{Kernel: kernel, Platform: "unknown", OS: "android", OSVersion: osVersion(), GoOS: runtime.GOOS, CPUs: runtime.NumCPU(), KernelVersion: kernelVersion} - gio.Hostname = extractDeviceName(ctx, "android") - gio.WiretrusteeVersion = version.NetbirdVersion() - gio.UIVersion = extractUserAgent(ctx) + gio := &Info{ + GoOS: runtime.GOOS, + Kernel: kernel, + Platform: "unknown", + OS: "android", + OSVersion: osVersion(), + Hostname: extractDeviceName(ctx, "android"), + CPUs: runtime.NumCPU(), + WiretrusteeVersion: version.NetbirdVersion(), + UIVersion: extractUIVersion(ctx), + KernelVersion: kernelVersion, + } return gio } @@ -45,6 +53,14 @@ func osVersion() string { return run("/system/bin/getprop", "ro.build.version.release") } +func extractUIVersion(ctx context.Context) string { + v, ok := ctx.Value(UiVersionCtxKey).(string) + if !ok { + return "" + } + return v +} + func run(name string, arg ...string) string { cmd := exec.Command(name, arg...) cmd.Stdin = strings.NewReader("some")