mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-22 08:03:30 +01:00
Fill the UI version info in system meta on Android (#2077)
This commit is contained in:
parent
521f7dd39f
commit
c311d0d19e
@ -57,15 +57,17 @@ type Client struct {
|
|||||||
ctxCancel context.CancelFunc
|
ctxCancel context.CancelFunc
|
||||||
ctxCancelLock *sync.Mutex
|
ctxCancelLock *sync.Mutex
|
||||||
deviceName string
|
deviceName string
|
||||||
|
uiVersion string
|
||||||
networkChangeListener listener.NetworkChangeListener
|
networkChangeListener listener.NetworkChangeListener
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient instantiate a new Client
|
// 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)
|
net.SetAndroidProtectSocketFn(tunAdapter.ProtectSocket)
|
||||||
return &Client{
|
return &Client{
|
||||||
cfgFile: cfgFile,
|
cfgFile: cfgFile,
|
||||||
deviceName: deviceName,
|
deviceName: deviceName,
|
||||||
|
uiVersion: uiVersion,
|
||||||
tunAdapter: tunAdapter,
|
tunAdapter: tunAdapter,
|
||||||
iFaceDiscover: iFaceDiscover,
|
iFaceDiscover: iFaceDiscover,
|
||||||
recorder: peer.NewRecorder(""),
|
recorder: peer.NewRecorder(""),
|
||||||
@ -88,6 +90,9 @@ func (c *Client) Run(urlOpener URLOpener, dns *DNSList, dnsReadyListener DnsRead
|
|||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
//nolint
|
//nolint
|
||||||
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
|
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
|
||||||
|
//nolint
|
||||||
|
ctxWithValues = context.WithValue(ctxWithValues, system.UiVersionCtxKey, c.uiVersion)
|
||||||
|
|
||||||
c.ctxCancelLock.Lock()
|
c.ctxCancelLock.Lock()
|
||||||
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
|
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
|
||||||
defer c.ctxCancel()
|
defer c.ctxCancel()
|
||||||
|
@ -20,6 +20,9 @@ const OsVersionCtxKey = "OsVersion"
|
|||||||
// OsNameCtxKey context key for operating system name
|
// OsNameCtxKey context key for operating system name
|
||||||
const OsNameCtxKey = "OsName"
|
const OsNameCtxKey = "OsName"
|
||||||
|
|
||||||
|
// UiVersionCtxKey context key for user UI version
|
||||||
|
const UiVersionCtxKey = "user-agent"
|
||||||
|
|
||||||
type NetworkAddress struct {
|
type NetworkAddress struct {
|
||||||
NetIP netip.Prefix
|
NetIP netip.Prefix
|
||||||
Mac string
|
Mac string
|
||||||
|
@ -28,10 +28,18 @@ func GetInfo(ctx context.Context) *Info {
|
|||||||
kernelVersion = osInfo[2]
|
kernelVersion = osInfo[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
gio := &Info{Kernel: kernel, Platform: "unknown", OS: "android", OSVersion: osVersion(), GoOS: runtime.GOOS, CPUs: runtime.NumCPU(), KernelVersion: kernelVersion}
|
gio := &Info{
|
||||||
gio.Hostname = extractDeviceName(ctx, "android")
|
GoOS: runtime.GOOS,
|
||||||
gio.WiretrusteeVersion = version.NetbirdVersion()
|
Kernel: kernel,
|
||||||
gio.UIVersion = extractUserAgent(ctx)
|
Platform: "unknown",
|
||||||
|
OS: "android",
|
||||||
|
OSVersion: osVersion(),
|
||||||
|
Hostname: extractDeviceName(ctx, "android"),
|
||||||
|
CPUs: runtime.NumCPU(),
|
||||||
|
WiretrusteeVersion: version.NetbirdVersion(),
|
||||||
|
UIVersion: extractUIVersion(ctx),
|
||||||
|
KernelVersion: kernelVersion,
|
||||||
|
}
|
||||||
|
|
||||||
return gio
|
return gio
|
||||||
}
|
}
|
||||||
@ -45,6 +53,14 @@ func osVersion() string {
|
|||||||
return run("/system/bin/getprop", "ro.build.version.release")
|
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 {
|
func run(name string, arg ...string) string {
|
||||||
cmd := exec.Command(name, arg...)
|
cmd := exec.Command(name, arg...)
|
||||||
cmd.Stdin = strings.NewReader("some")
|
cmd.Stdin = strings.NewReader("some")
|
||||||
|
Loading…
Reference in New Issue
Block a user