cmd/tailscale,java/com/tailscale/ipn: provide OSVersion and DeviceModel for the backend

Signed-off-by: Elias Naur <mail@eliasnaur.com>
pull/3/head
Elias Naur 4 years ago
parent 93afdf1e5d
commit 9e45538997

@ -97,7 +97,7 @@ public class App extends Application {
return getModelName(); return getModelName();
} }
private String getModelName() { String getModelName() {
String manu = Build.MANUFACTURER; String manu = Build.MANUFACTURER;
String model = Build.MODEL; String model = Build.MODEL;
// Strip manufacturer from model. // Strip manufacturer from model.
@ -109,6 +109,10 @@ public class App extends Application {
return manu + " " + model; return manu + " " + model;
} }
String getOSVersion() {
return Build.VERSION.RELEASE;
}
// get user defined nickname from Settings // get user defined nickname from Settings
// returns null if not available // returns null if not available
private String getUserConfiguredDeviceName() { private String getUserConfiguredDeviceName() {

@ -191,6 +191,8 @@ func (a *App) runBackend() error {
prefs = p.Clone() prefs = p.Clone()
if first { if first {
prefs.Hostname = a.hostname() prefs.Hostname = a.hostname()
prefs.OSVersion = a.osVersion()
prefs.DeviceModel = a.modelName()
go b.backend.SetPrefs(prefs) go b.backend.SetPrefs(prefs)
} }
a.setPrefs(prefs) a.setPrefs(prefs)
@ -315,6 +317,39 @@ func (a *App) hostname() string {
return hostname return hostname
} }
// osVersion returns android.os.Build.MODEL.
func (a *App) osVersion() string {
var version string
err := jni.Do(a.jvm, func(env jni.Env) error {
cls := jni.GetObjectClass(env, a.appCtx)
m := jni.GetMethodID(env, cls, "getOSVersion", "()Ljava/lang/String;")
n, err := jni.CallObjectMethod(env, a.appCtx, m)
version = jni.GoString(env, jni.String(n))
return err
})
if err != nil {
panic(err)
}
return version
}
// modelName return the MANUFACTURER + MODEL from
// android.os.Build.
func (a *App) modelName() string {
var model string
err := jni.Do(a.jvm, func(env jni.Env) error {
cls := jni.GetObjectClass(env, a.appCtx)
m := jni.GetMethodID(env, cls, "getModelName", "()Ljava/lang/String;")
n, err := jni.CallObjectMethod(env, a.appCtx, m)
model = jni.GoString(env, jni.String(n))
return err
})
if err != nil {
panic(err)
}
return model
}
// updateNotification updates the foreground persistent status notification. // updateNotification updates the foreground persistent status notification.
func (a *App) updateNotification(service jni.Object, state ipn.State) error { func (a *App) updateNotification(service jni.Object, state ipn.State) error {
var msg, title string var msg, title string

Loading…
Cancel
Save