]>
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 logging
.info("Already tracking a session")
129 args
.session
= session
132 command
= [tools
.config
.tools_src
+
133 "/data/scripts/waydroid-net.sh", "start"]
134 tools
.helpers
.run
.user(args
, command
, check
=False)
137 if which("waydroid-sensord"):
138 tools
.helpers
.run
.user(
139 args
, ["waydroid-sensord", "/dev/" + args
.HWBINDER_DRIVER
], output
="background")
142 cfg
= tools
.config
.load(args
)
143 helpers
.images
.mount_rootfs(args
, cfg
["waydroid"]["images_path"], args
.session
)
145 helpers
.protocol
.set_aidl_version(args
)
148 helpers
.mount
.bind(args
, args
.session
["waydroid_data"],
149 tools
.config
.defaults
["data"])
153 command
= ["start", "cgroup-lite"]
154 tools
.helpers
.run
.user(args
, command
, check
=False)
155 if os
.path
.ismount("/sys/fs/cgroup/schedtune"):
156 command
= ["umount", "-l", "/sys/fs/cgroup/schedtune"]
157 tools
.helpers
.run
.user(args
, command
, check
=False)
159 #TODO: remove NFC hacks
161 command
= ["stop", "nfcd"]
162 tools
.helpers
.run
.user(args
, command
, check
=False)
165 set_permissions(args
)
167 helpers
.lxc
.start(args
)
168 services
.hardware_manager
.start(args
)
172 services
.hardware_manager
.stop(args
)
173 status
= helpers
.lxc
.status(args
)
174 if status
!= "STOPPED":
175 helpers
.lxc
.stop(args
)
176 while helpers
.lxc
.status(args
) != "STOPPED":
180 command
= [tools
.config
.tools_src
+
181 "/data/scripts/waydroid-net.sh", "stop"]
182 tools
.helpers
.run
.user(args
, command
, check
=False)
184 #TODO: remove NFC hacks
186 command
= ["start", "nfcd"]
187 tools
.helpers
.run
.user(args
, command
, check
=False)
190 if which("waydroid-sensord"):
191 command
= ["pidof", "waydroid-sensord"]
192 pid
= tools
.helpers
.run
.user(args
, command
, check
=False, output_return
=True).strip()
194 command
= ["kill", "-9", pid
]
195 tools
.helpers
.run
.user(args
, command
, check
=False)
198 helpers
.images
.umount_rootfs(args
)
201 helpers
.mount
.umount_all(args
, tools
.config
.defaults
["data"])
203 if "session" in args
:
205 os
.kill(int(args
.session
["pid"]), signal
.SIGUSR1
)
213 status
= helpers
.lxc
.status(args
)
214 if status
== "RUNNING":
215 helpers
.lxc
.stop(args
)
216 helpers
.lxc
.start(args
)
218 logging
.error("WayDroid container is {}".format(status
))
221 status
= helpers
.lxc
.status(args
)
222 if status
== "RUNNING":
223 helpers
.lxc
.freeze(args
)
224 while helpers
.lxc
.status(args
) == "RUNNING":
227 logging
.error("WayDroid container is {}".format(status
))
230 status
= helpers
.lxc
.status(args
)
231 if status
== "FROZEN":
232 helpers
.lxc
.unfreeze(args
)
233 while helpers
.lxc
.status(args
) == "FROZEN":