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