]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/app_manager.py
Move session IPC to dbus
[waydroid.git] / tools / actions / app_manager.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 import logging
4 import os
5 import shutil
6 import time
7 import tools.config
8 import tools.helpers.props
9 import tools.helpers.ipc
10 from tools.interfaces import IPlatform
11 from tools.interfaces import IStatusBarService
12 import dbus
13
14 def install(args):
15 try:
16 tools.helpers.ipc.DBusSessionService()
17
18 tmp_dir = tools.config.session_defaults["waydroid_data"] + "/waydroid_tmp"
19 if not os.path.exists(tmp_dir):
20 os.makedirs(tmp_dir)
21
22 shutil.copyfile(args.PACKAGE, tmp_dir + "/base.apk")
23 platformService = IPlatform.get_service(args)
24 if platformService:
25 platformService.installApp("/data/waydroid_tmp/base.apk")
26 os.remove(tmp_dir + "/base.apk")
27 except (dbus.DBusException, KeyError):
28 logging.error("WayDroid session is stopped")
29
30 def remove(args):
31 try:
32 tools.helpers.ipc.DBusSessionService()
33
34 platformService = IPlatform.get_service(args)
35 if platformService:
36 ret = platformService.removeApp(args.PACKAGE)
37 if ret != 0:
38 logging.error("Failed to uninstall package: {}".format(args.PACKAGE))
39 except dbus.DBusException:
40 logging.error("WayDroid session is stopped")
41
42 def maybeLaunchLater(args, launchNow):
43 try:
44 tools.helpers.ipc.DBusSessionService()
45 try:
46 tools.helpers.ipc.DBusContainerService().Unfreeze()
47 except:
48 logging.error("Failed to unfreeze container. Trying to launch anyways...")
49 launchNow()
50 except dbus.DBusException:
51 logging.error("Starting waydroid session")
52 tools.actions.session_manager.start(args, launchNow)
53
54 def launch(args):
55 def justLaunch():
56 platformService = IPlatform.get_service(args)
57 if platformService:
58 platformService.setprop("waydroid.active_apps", args.PACKAGE)
59 ret = platformService.launchApp(args.PACKAGE)
60 multiwin = platformService.getprop(
61 "persist.waydroid.multi_windows", "false")
62 if multiwin == "false":
63 platformService.settingsPutString(
64 2, "policy_control", "immersive.status=*")
65 else:
66 platformService.settingsPutString(
67 2, "policy_control", "immersive.full=*")
68 else:
69 logging.error("Failed to access IPlatform service")
70 maybeLaunchLater(args, justLaunch)
71
72 def list(args):
73 try:
74 tools.helpers.ipc.DBusSessionService()
75
76 platformService = IPlatform.get_service(args)
77 if platformService:
78 appsList = platformService.getAppsInfo()
79 for app in appsList:
80 print("Name: " + app["name"])
81 print("packageName: " + app["packageName"])
82 print("categories:")
83 for cat in app["categories"]:
84 print("\t" + cat)
85 else:
86 logging.error("Failed to access IPlatform service")
87 except dbus.DBusException:
88 logging.error("WayDroid session is stopped")
89
90 def showFullUI(args):
91 def justShow():
92 platformService = IPlatform.get_service(args)
93 if platformService:
94 platformService.setprop("waydroid.active_apps", "Waydroid")
95 platformService.settingsPutString(2, "policy_control", "null*")
96 # HACK: Refresh display contents
97 statusBarService = IStatusBarService.get_service(args)
98 if statusBarService:
99 statusBarService.expand()
100 time.sleep(0.5)
101 statusBarService.collapse()
102 maybeLaunchLater(args, justShow)
103
104 def intent(args):
105 def justLaunch():
106 platformService = IPlatform.get_service(args)
107 if platformService:
108 ret = platformService.launchIntent(args.ACTION, args.URI)
109 if ret == "":
110 return
111 pkg = ret if ret != "android" else "Waydroid"
112 platformService.setprop("waydroid.active_apps", pkg)
113 multiwin = platformService.getprop(
114 "persist.waydroid.multi_windows", "false")
115 if multiwin == "false":
116 platformService.settingsPutString(
117 2, "policy_control", "immersive.status=*")
118 else:
119 platformService.settingsPutString(
120 2, "policy_control", "immersive.full=*")
121 else:
122 logging.error("Failed to access IPlatform service")
123 maybeLaunchLater(args, justLaunch)