Skip to content

Commit a7d031d

Browse files
mixmasalaroot
authored andcommitted
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 03a1ada commit a7d031d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

gogio/androidbuild.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type manifestData struct {
4848
Features []string
4949
IconSnip string
5050
AppName string
51+
HasService bool
5152
}
5253

5354
const (
@@ -67,6 +68,7 @@ const (
6768
<item name="android:statusBarColor">#40000000</item>
6869
</style>
6970
</resources>`
71+
foregroundPermission = "android.permission.FOREGROUND_SERVICE"
7072
)
7173

7274
func init() {
@@ -448,6 +450,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
448450
Features: features,
449451
IconSnip: iconSnip,
450452
AppName: appName,
453+
HasService: stringsContains(perms, "foreground"),
451454
}
452455
tmpl, err := template.New("test").Parse(
453456
`<?xml version="1.0" encoding="utf-8"?>
@@ -470,6 +473,17 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
470473
<category android:name="android.intent.category.LAUNCHER" />
471474
</intent-filter>
472475
</activity>
476+
{{if .HasService}}
477+
<service android:name="org.gioui.GioForegroundService"
478+
android:stopWithTask="true">
479+
<meta-data android:name="org.gioui.ForegroundChannelID"
480+
android:value="gio_foreground" />
481+
<meta-data android:name="org.gioui.ForegroundChannelName"
482+
android:value="GioForeground" />
483+
<meta-data android:name="org.gioui.ForegroundNotificationID"
484+
android:value="0x42424242" />
485+
</service>
486+
{{end}}
473487
</application>
474488
</manifest>`)
475489
var manifestBuffer bytes.Buffer
@@ -869,6 +883,15 @@ func getPermissions(ps []string) ([]string, []string) {
869883
return permissions, features
870884
}
871885

886+
func stringsContains(strings []string, str string) bool {
887+
for _, s := range strings {
888+
if str == s {
889+
return true
890+
}
891+
}
892+
return false
893+
}
894+
872895
func latestPlatform(sdk string) (string, error) {
873896
allPlats, err := filepath.Glob(filepath.Join(sdk, "platforms", "android-*"))
874897
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)