2020-06-19 17:40:18 -04:00
|
|
|
package android
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"gioui.org/app"
|
|
|
|
"github.com/tailscale/tailscale-android/jni"
|
|
|
|
)
|
|
|
|
|
|
|
|
type NotificationChannel struct {
|
2020-06-19 18:35:55 -04:00
|
|
|
id string
|
2020-06-19 17:40:18 -04:00
|
|
|
}
|
|
|
|
|
2020-06-19 18:35:55 -04:00
|
|
|
func NewChannel(id, name, description string) (*NotificationChannel, error) {
|
2020-06-19 18:28:01 -04:00
|
|
|
if err := jni.Do(jni.JVMFor(app.JavaVM()), func(env jni.Env) error {
|
|
|
|
appCtx := jni.Object(app.AppContext())
|
|
|
|
classLoader := jni.ClassLoaderFor(env, appCtx)
|
2020-06-19 17:40:18 -04:00
|
|
|
notifyClass, err := jni.LoadClass(env, classLoader, "ht/sr/git/whereswaldon/niotify/NotificationHelper")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-06-19 18:35:55 -04:00
|
|
|
newChannelMethod := jni.GetStaticMethodID(env, notifyClass, "newChannel", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V")
|
|
|
|
jname := jni.Value(jni.JavaString(env, name))
|
|
|
|
jdescription := jni.Value(jni.JavaString(env, description))
|
|
|
|
jID := jni.Value(jni.JavaString(env, id))
|
|
|
|
err = jni.CallStaticVoidMethod(env, notifyClass, newChannelMethod, jni.Value(app.AppContext()), jID, jname, jdescription)
|
2020-06-19 18:28:01 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2020-06-19 17:40:18 -04:00
|
|
|
}); err != nil {
|
|
|
|
return nil, fmt.Errorf("failed creating notification channel: %w", err)
|
|
|
|
}
|
2020-06-19 18:28:01 -04:00
|
|
|
nc := &NotificationChannel{
|
2020-06-19 18:35:55 -04:00
|
|
|
id: id,
|
2020-06-19 18:28:01 -04:00
|
|
|
}
|
|
|
|
return nc, nil
|
2020-06-19 17:40:18 -04:00
|
|
|
}
|