Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Author: Masala <[email protected]> #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions gogio/androidbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type manifestData struct {
Features []string
IconSnip string
AppName string
HasService bool
}

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

func init() {
Expand Down Expand Up @@ -448,6 +450,7 @@ func exeAndroid(tmpDir string, tools *androidTools, bi *buildInfo, extraJars, pe
Features: features,
IconSnip: iconSnip,
AppName: appName,
HasService: stringsContains(perms, "foreground"),
}
tmpl, err := template.New("test").Parse(
`<?xml version="1.0" encoding="utf-8"?>
Expand All @@ -470,6 +473,17 @@ 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't submit this change before your change that adds GioForegroundService, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

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.ForegroundNotificationID"
android:value="0x42424242" />
</service>
{{end}}
</application>
</manifest>`)
var manifestBuffer bytes.Buffer
Expand Down Expand Up @@ -869,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