]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/container_manager.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 from shutil
import which
12 from tools
import helpers
13 from tools
import services
16 import dbus
.exceptions
17 from gi
.repository
import GLib
19 class DbusContainerManager(dbus
.service
.Object
):
20 def __init__(self
, looper
, bus
, object_path
, args
):
23 dbus
.service
.Object
.__init
__(self
, bus
, object_path
)
25 @dbus.service.method("id.waydro.ContainerManager", in_signature
='a{ss}', out_signature
='')
26 def Start(self
, session
):
27 do_start(self
.args
, session
)
29 @dbus.service.method("id.waydro.ContainerManager", in_signature
='', out_signature
='')
33 @dbus.service.method("id.waydro.ContainerManager", in_signature
='', out_signature
='')
37 @dbus.service.method("id.waydro.ContainerManager", in_signature
='', out_signature
='')
41 @dbus.service.method("id.waydro.ContainerManager", in_signature
='', out_signature
='a{ss}')
44 session
= self
.args
.session
45 session
["state"] = helpers
.lxc
.status(self
.args
)
47 except AttributeError:
50 def service(args
, looper
):
51 dbus_obj
= DbusContainerManager(looper
, dbus
.SystemBus(), '/ContainerManager', args
)
54 def set_permissions(args
, perm_list
=None, mode
="777"):
55 def chmod(path
, mode
):
56 if os
.path
.exists(path
):
57 command
= ["chmod", mode
, "-R", path
]
58 tools
.helpers
.run
.user(args
, command
, check
=False)
67 "/sys/kernel/debug/sync/sw_sync",
83 perm_list
.extend(glob
.glob("/dev/fb*"))
85 perm_list
.extend(glob
.glob("/dev/video*"))
87 for path
in perm_list
:
92 name
= dbus
.service
.BusName("id.waydro.Container", dbus
.SystemBus(), do_not_queue
=True)
93 except dbus
.exceptions
.NameExistsException
:
94 logging
.error("Container service is already running")
97 status
= helpers
.lxc
.status(args
)
98 if status
== "STOPPED":
99 # Load binder and ashmem drivers
100 cfg
= tools
.config
.load(args
)
101 if cfg
["waydroid"]["vendor_type"] == "MAINLINE":
102 if helpers
.drivers
.probeBinderDriver(args
) != 0:
103 logging
.error("Failed to load Binder driver")
104 helpers
.drivers
.probeAshmemDriver(args
)
105 helpers
.drivers
.loadBinderNodes(args
)
106 set_permissions(args
, [
107 "/dev/" + args
.BINDER_DRIVER
,
108 "/dev/" + args
.VNDBINDER_DRIVER
,
109 "/dev/" + args
.HWBINDER_DRIVER
112 mainloop
= GLib
.MainLoop()
114 def sigint_handler(data
):
118 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGINT
, sigint_handler
, None)
119 GLib
.unix_signal_add(GLib
.PRIORITY_HIGH
, signal
.SIGTERM
, sigint_handler
, None)
120 service(args
, mainloop
)
122 logging
.error("WayDroid container is {}".format(status
))
124 def do_start(args
, session
):
125 if "session" in args
:
126 raise RuntimeError("Already tracking a session")
129 command
= [tools
.config
.tools_src
+
130 "/data/scripts/waydroid-net.sh", "start"]
131 tools
.helpers
.run
.user(args
, command
)
134 if which("waydroid-sensord"):
135 tools
.helpers
.run
.user(
136 args
, ["waydroid-sensord", "/dev/" + args
.HWBINDER_DRIVER
], output
="background")
139 cfg
= tools
.config
.load(args
)
140 helpers
.images
.mount_rootfs(args
, cfg
["waydroid"]["images_path"], session
)
142 helpers
.protocol
.set_aidl_version(args
)
145 helpers
.mount
.bind(args
, session
["waydroid_data"],
146 tools
.config
.defaults
["data"])
150 command
= ["start", "cgroup-lite"]
151 tools
.helpers
.run
.user(args
, command
, check
=False)
152 if os
.path
.ismount("/sys/fs/cgroup/schedtune"):
153 command
= ["umount", "-l", "/sys/fs/cgroup/schedtune"]
154 tools
.helpers
.run
.user(args
, command
, check
=False)
156 #TODO: remove NFC hacks
158 command
= ["stop", "nfcd"]
159 tools
.helpers
.run
.user(args
, command
, check
=False)
162 set_permissions(args
)
164 helpers
.lxc
.start(args
)
165 services
.hardware_manager
.start(args
)
167 args
.session
= session
171 services
.hardware_manager
.stop(args
)
172 status
= helpers
.lxc
.status(args
)
173 if status
!= "STOPPED":
174 helpers
.lxc
.stop(args
)
175 while helpers
.lxc
.status(args
) != "STOPPED":
179 command
= [tools
.config
.tools_src
+
180 "/data/scripts/waydroid-net.sh", "stop"]
181 tools
.helpers
.run
.user(args
, command
, check
=False)
183 #TODO: remove NFC hacks
185 command
= ["start", "nfcd"]
186 tools
.helpers
.run
.user(args
, command
, check
=False)
189 if which("waydroid-sensord"):
190 command
= ["pidof", "waydroid-sensord"]
191 pid
= tools
.helpers
.run
.user(args
, command
, check
=False, output_return
=True).strip()
193 command
= ["kill", "-9", pid
]
194 tools
.helpers
.run
.user(args
, command
, check
=False)
197 helpers
.images
.umount_rootfs(args
)
200 helpers
.mount
.umount_all(args
, tools
.config
.defaults
["data"])
202 if "session" in args
:
204 os
.kill(int(args
.session
["pid"]), signal
.SIGUSR1
)
212 status
= helpers
.lxc
.status(args
)
213 if status
== "RUNNING":
214 helpers
.lxc
.stop(args
)
215 helpers
.lxc
.start(args
)
217 logging
.error("WayDroid container is {}".format(status
))
220 status
= helpers
.lxc
.status(args
)
221 if status
== "RUNNING":
222 helpers
.lxc
.freeze(args
)
223 while helpers
.lxc
.status(args
) == "RUNNING":
226 logging
.error("WayDroid container is {}".format(status
))
229 status
= helpers
.lxc
.status(args
)
230 if status
== "FROZEN":
231 helpers
.lxc
.unfreeze(args
)
232 while helpers
.lxc
.status(args
) == "FROZEN":