Skip to content

Commit a638b49

Browse files
author
mirkobrombin
committed
fix[close #112]: Waydroid/binder module not working
1 parent 4d45e04 commit a638b49

File tree

2 files changed

+43
-52
lines changed

2 files changed

+43
-52
lines changed

cmd/waydroid.go

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,19 @@ func NewWayCommand() []*cmdr.Command {
158158
return []*cmdr.Command{cmd}
159159
}
160160

161-
func wayClean(cmd *cobra.Command, args []string) error {
162-
if !core.IsWayland() {
161+
func isSupported() {
162+
switch core.IsSupported() {
163+
case 1:
163164
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
164165
os.Exit(1)
165-
return nil
166+
case 2:
167+
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.secureBoot"))
168+
os.Exit(1)
166169
}
170+
}
171+
172+
func wayClean(cmd *cobra.Command, args []string) error {
173+
isSupported()
167174

168175
cmdr.Info.Println(vso.Trans("waydroid.clean.info.index"))
169176
_, err := os.Stat(core.IndexCacheDir)
@@ -188,10 +195,7 @@ func wayClean(cmd *cobra.Command, args []string) error {
188195
}
189196

190197
func wayDelete(cmd *cobra.Command, args []string) error {
191-
if !core.IsWayland() {
192-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
193-
os.Exit(1)
194-
}
198+
isSupported()
195199

196200
if core.AskConfirmation(vso.Trans("waydroid.delete.confirmation"), false) {
197201
return core.WayDelete()
@@ -200,10 +204,7 @@ func wayDelete(cmd *cobra.Command, args []string) error {
200204
}
201205

202206
func wayInfo(cmd *cobra.Command, args []string) error {
203-
if !core.IsWayland() {
204-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
205-
os.Exit(1)
206-
}
207+
isSupported()
207208

208209
if len(args) < 1 {
209210
cmdr.Error.Println(vso.Trans("waydroid.error.noArguments"))
@@ -245,10 +246,7 @@ func wayInfo(cmd *cobra.Command, args []string) error {
245246
}
246247

247248
func wayStatus(cmd *cobra.Command, args []string) error {
248-
if !core.IsWayland() {
249-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
250-
os.Exit(1)
251-
}
249+
isSupported()
252250

253251
_, err := core.GetWay()
254252
if err != nil {
@@ -263,10 +261,7 @@ func wayStatus(cmd *cobra.Command, args []string) error {
263261
}
264262

265263
func wayInit(cmd *cobra.Command, args []string) error {
266-
if !core.IsWayland() {
267-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
268-
os.Exit(1)
269-
}
264+
isSupported()
270265

271266
force, _ := cmd.Flags().GetBool("force")
272267

@@ -289,10 +284,7 @@ func wayInit(cmd *cobra.Command, args []string) error {
289284
}
290285

291286
func wayInstallRemote(search string, noconfirm bool, noprompt bool) (string, core.FdroidPackage, error) {
292-
if !core.IsWayland() {
293-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
294-
os.Exit(1)
295-
}
287+
isSupported()
296288

297289
_, err := os.Stat(core.APKCacheDir)
298290
if os.IsNotExist(err) {
@@ -345,10 +337,7 @@ func wayInstallRemote(search string, noconfirm bool, noprompt bool) (string, cor
345337
}
346338

347339
func wayInstall(cmd *cobra.Command, args []string) error {
348-
if !core.IsWayland() {
349-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
350-
os.Exit(1)
351-
}
340+
isSupported()
352341

353342
if len(args) == 0 {
354343
cmdr.Error.Println(vso.Trans("waydroid.error.noArguments"))
@@ -423,10 +412,7 @@ func wayInstall(cmd *cobra.Command, args []string) error {
423412
}
424413

425414
func wayLaunch(cmd *cobra.Command, args []string) error {
426-
if !core.IsWayland() {
427-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
428-
os.Exit(1)
429-
}
415+
isSupported()
430416

431417
way, err := core.GetWay()
432418
if err != nil {
@@ -444,10 +430,7 @@ func wayLaunch(cmd *cobra.Command, args []string) error {
444430
}
445431

446432
func wayLauncher(cmd *cobra.Command, args []string) error {
447-
if !core.IsWayland() {
448-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
449-
os.Exit(1)
450-
}
433+
isSupported()
451434

452435
way, err := core.GetWay()
453436
if err != nil {
@@ -465,10 +448,7 @@ func wayLauncher(cmd *cobra.Command, args []string) error {
465448
}
466449

467450
func wayRemove(cmd *cobra.Command, args []string) error {
468-
if !core.IsWayland() {
469-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
470-
os.Exit(1)
471-
}
451+
isSupported()
472452

473453
way, err := core.GetWay()
474454
if err != nil {
@@ -541,10 +521,7 @@ func wayRemove(cmd *cobra.Command, args []string) error {
541521
}
542522

543523
func waySearch(cmd *cobra.Command, args []string) error {
544-
if !core.IsWayland() {
545-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
546-
os.Exit(1)
547-
}
524+
isSupported()
548525

549526
if len(args) == 0 {
550527
cmdr.Error.Println(vso.Trans("waydroid.error.noArguments"))
@@ -568,10 +545,7 @@ func waySearch(cmd *cobra.Command, args []string) error {
568545
}
569546

570547
func waySync(cmd *cobra.Command, args []string) error {
571-
if !core.IsWayland() {
572-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
573-
os.Exit(1)
574-
}
548+
isSupported()
575549

576550
err := core.GetRepos()
577551
if err != nil {
@@ -583,10 +557,7 @@ func waySync(cmd *cobra.Command, args []string) error {
583557
}
584558

585559
func wayUpdate(cmd *cobra.Command, args []string) error {
586-
if !core.IsWayland() {
587-
cmdr.Error.Println(vso.Trans("waydroid.vso.errors.notWayland"))
588-
os.Exit(1)
589-
}
560+
isSupported()
590561

591562
db, err := core.GetWayDatabase()
592563
if err != nil {

core/waydroid.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"encoding/json"
1414
"fmt"
1515
"os"
16+
"os/exec"
1617
"strings"
1718
"time"
1819

@@ -279,6 +280,25 @@ func WayDelete() error {
279280
return nil
280281
}
281282

282-
func IsWayland() bool {
283+
func isWayland() bool {
283284
return os.Getenv("XDG_SESSION_TYPE") == "wayland"
284285
}
286+
287+
func isSecureBootDisabled() bool {
288+
cmd := exec.Command("mokutil", "--sb-state")
289+
out, err := cmd.Output()
290+
if err != nil {
291+
return false
292+
}
293+
return !strings.Contains(string(out), "enabled")
294+
}
295+
296+
func IsSupported() int {
297+
if !isWayland() {
298+
return 1
299+
}
300+
if !isSecureBootDisabled() {
301+
return 2
302+
}
303+
return 0
304+
}

0 commit comments

Comments
 (0)