Skip to content

Commit

Permalink
cmd/gogio: add android foreground permission
Browse files Browse the repository at this point in the history
This adds the permission android.permission.FOREGROUND_SERVICE to the
android application Metadata

Signed-off-by: Masala <[email protected]>
  • Loading branch information
mixmasala committed Sep 17, 2023
1 parent 7cb98d0 commit 697be40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gogio/androidbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type manifestData struct {
Features []string
IconSnip string
AppName string
HasService bool
}

const (
Expand All @@ -68,6 +69,7 @@ const (
<item name="android:statusBarColor">#40000000</item>
</style>
</resources>`
foregroundPermission = "android.permission.FOREGROUND_SERVICE"
)

func init() {
Expand Down Expand Up @@ -446,6 +448,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
Features: features,
IconSnip: iconSnip,
AppName: appName,
HasService: stringsContains(permissions, foregroundPermission),
}
tmpl, err := template.New("test").Parse(
`<?xml version="1.0" encoding="utf-8"?>
Expand All @@ -468,6 +471,19 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
{{if .HasService}}
<service android:name="org.gioui.GioForegroundService"
android:stopWithTask="true">
<meta-data android:name="org.gioui.ForegroundChannelID"
android:value="gio_foreground" />
<meta-data android:name="org.gioui.ForegroundChannelName"
android:value="GioForeground" />
<meta-data android:name="org.gioui.ForegroundChannelDesc"
android:value="" />
<meta-data android:name="org.gioui.ForegroundNotificationID"
android:value="0x42424242" />
</service>
{{end}}
</application>
</manifest>`)
var manifestBuffer bytes.Buffer
Expand Down Expand Up @@ -867,6 +883,15 @@ func getPermissions(ps []string) ([]string, []string) {
return permissions, features
}

func stringsContains(strings []string, str string) bool {
for _, s := range strings {
if str == s {
return true
}
}
return false
}

func latestPlatform(sdk string) (string, error) {
allPlats, err := filepath.Glob(filepath.Join(sdk, "platforms", "android-*"))
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions gogio/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var AndroidPermissions = map[string][]string{
"wakelock": {
"android.permission.WAKE_LOCK",
},
"foreground": {
"android.permission.FOREGROUND_SERVICE",
},
}

var AndroidFeatures = map[string][]string{
Expand Down

0 comments on commit 697be40

Please sign in to comment.