]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/app_manager.py
session: Provide waydroid.host_data_path prop
[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 cm = tools.helpers.ipc.DBusContainerService()
19 session = cm.GetSession()
20 if session["state"] == "FROZEN":
21 cm.Unfreeze()
22
23 tmp_dir = tools.config.session_defaults["waydroid_data"] + "/waydroid_tmp"
24 if not os.path.exists(tmp_dir):
25 os.makedirs(tmp_dir)
26
27 shutil.copyfile(args.PACKAGE, tmp_dir + "/base.apk")
28 platformService = IPlatform.get_service(args)
29 if platformService:
30 platformService.installApp("/data/waydroid_tmp/base.apk")
31 else:
32 logging.error("Failed to access IPlatform service")
33 os.remove(tmp_dir + "/base.apk")
34
35 if session["state"] == "FROZEN":
36 cm.Freeze()
37 except (dbus.DBusException, KeyError):
38 logging.error("WayDroid session is stopped")
39
40 def remove(args):
41 try:
42 tools.helpers.ipc.DBusSessionService()
43
44 cm = tools.helpers.ipc.DBusContainerService()
45 session = cm.GetSession()
46 if session["state"] == "FROZEN":
47 cm.Unfreeze()
48
49 platformService = IPlatform.get_service(args)
50 if platformService:
51 ret = platformService.removeApp(args.PACKAGE)
52 if ret != 0:
53 logging.error("Failed to uninstall package: {}".format(args.PACKAGE))
54 else:
55 logging.error("Failed to access IPlatform service")
56
57 if session["state"] == "FROZEN":
58 cm.Freeze()
59 except dbus.DBusException:
60 logging.error("WayDroid session is stopped")
61
62 def maybeLaunchLater(args, launchNow):
63 try:
64 tools.helpers.ipc.DBusSessionService()
65 try:
66 tools.helpers.ipc.DBusContainerService().Unfreeze()
67 except:
68 logging.error("Failed to unfreeze container. Trying to launch anyways...")
69 launchNow()
70 except dbus.DBusException:
71 logging.error("Starting waydroid session")
72 tools.actions.session_manager.start(args, launchNow, background=False)
73
74 def launch(args):
75 def justLaunch():
76 platformService = IPlatform.get_service(args)
77 if platformService:
78 platformService.setprop("waydroid.active_apps", args.PACKAGE)
79 ret = platformService.launchApp(args.PACKAGE)
80 multiwin = platformService.getprop(
81 "persist.waydroid.multi_windows", "false")
82 if multiwin == "false":
83 platformService.settingsPutString(
84 2, "policy_control", "immersive.status=*")
85 else:
86 platformService.settingsPutString(
87 2, "policy_control", "immersive.full=*")
88 else:
89 logging.error("Failed to access IPlatform service")
90 maybeLaunchLater(args, justLaunch)
91
92 def list(args):
93 try:
94 tools.helpers.ipc.DBusSessionService()
95
96 cm = tools.helpers.ipc.DBusContainerService()
97 session = cm.GetSession()
98 if session["state"] == "FROZEN":
99 cm.Unfreeze()
100
101 platformService = IPlatform.get_service(args)
102 if platformService:
103 appsList = platformService.getAppsInfo()
104 for app in appsList:
105 print("Name: " + app["name"])
106 print("packageName: " + app["packageName"])
107 print("categories:")
108 for cat in app["categories"]:
109 print("\t" + cat)
110 else:
111 logging.error("Failed to access IPlatform service")
112
113 if session["state"] == "FROZEN":
114 cm.Freeze()
115 except dbus.DBusException:
116 logging.error("WayDroid session is stopped")
117
118 def showFullUI(args):
119 def justShow():
120 platformService = IPlatform.get_service(args)
121 if platformService:
122 platformService.setprop("waydroid.active_apps", "Waydroid")
123 platformService.settingsPutString(2, "policy_control", "null*")
124 # HACK: Refresh display contents
125 statusBarService = IStatusBarService.get_service(args)
126 if statusBarService:
127 statusBarService.expand()
128 time.sleep(0.5)
129 statusBarService.collapse()
130 else:
131 logging.error("Failed to access IPlatform service")
132 maybeLaunchLater(args, justShow)
133
134 def intent(args):
135 def justLaunch():
136 platformService = IPlatform.get_service(args)
137 if platformService:
138 ret = platformService.launchIntent(args.ACTION, args.URI)
139 if ret == "":
140 return
141 pkg = ret if ret != "android" else "Waydroid"
142 platformService.setprop("waydroid.active_apps", pkg)
143 multiwin = platformService.getprop(
144 "persist.waydroid.multi_windows", "false")
145 if multiwin == "false":
146 platformService.settingsPutString(
147 2, "policy_control", "immersive.status=*")
148 else:
149 platformService.settingsPutString(
150 2, "policy_control", "immersive.full=*")
151 else:
152 logging.error("Failed to access IPlatform service")
153 maybeLaunchLater(args, justLaunch)