Skip to content

Commit a9fefc1

Browse files
committed
cmd/gogio: add android foreground permission
This adds the permission android.permission.FOREGROUND_SERVICE to the android application Metadata Signed-off-by: Masala <[email protected]>
1 parent 02068d6 commit a9fefc1

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

gogio/androidbuild.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type manifestData struct {
4949
Features []string
5050
IconSnip string
5151
AppName string
52+
HasService bool
5253
}
5354

5455
const (
@@ -68,6 +69,7 @@ const (
6869
<item name="android:statusBarColor">#40000000</item>
6970
</style>
7071
</resources>`
72+
foregroundPermission = "android.permission.FOREGROUND_SERVICE"
7173
)
7274

7375
func init() {
@@ -446,6 +448,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
446448
Features: features,
447449
IconSnip: iconSnip,
448450
AppName: appName,
451+
HasService: stringsContains(permissions, foregroundPermission),
449452
}
450453
tmpl, err := template.New("test").Parse(
451454
`<?xml version="1.0" encoding="utf-8"?>
@@ -468,6 +471,19 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
468471
<category android:name="android.intent.category.LAUNCHER" />
469472
</intent-filter>
470473
</activity>
474+
{{if .HasService}}
475+
<service android:name="org.gioui.GioForegroundService"
476+
android:stopWithTask="true">
477+
<meta-data android:name="org.gioui.ForegroundChannelID"
478+
android:value="gio_foreground" />
479+
<meta-data android:name="org.gioui.ForegroundChannelName"
480+
android:value="GioForeground" />
481+
<meta-data android:name="org.gioui.ForegroundChannelDesc"
482+
android:value="" />
483+
<meta-data android:name="org.gioui.ForegroundNotificationID"
484+
android:value="0x42424242" />
485+
</service>
486+
{{end}}
471487
</application>
472488
</manifest>`)
473489
var manifestBuffer bytes.Buffer
@@ -865,6 +881,15 @@ func getPermissions(ps []string) ([]string, []string) {
865881
return permissions, features
866882
}
867883

884+
func stringsContains(strings []string, str string) bool {
885+
for _, s := range strings {
886+
if str == s {
887+
return true
888+
}
889+
}
890+
return false
891+
}
892+
868893
func latestPlatform(sdk string) (string, error) {
869894
allPlats, err := filepath.Glob(filepath.Join(sdk, "platforms", "android-*"))
870895
if err != nil {

gogio/permission.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ var AndroidPermissions = map[string][]string{
2222
"wakelock": {
2323
"android.permission.WAKE_LOCK",
2424
},
25+
"foreground": {
26+
"android.permission.FOREGROUND_SERVICE",
27+
},
2528
}
2629

2730
var AndroidFeatures = map[string][]string{

0 commit comments

Comments
 (0)