]>
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
17 def set_permissions(perm_list
=None, mode
="777"):
18 def chmod(path
, mode
):
19 if os
.path
.exists(path
):
20 command
= ["chmod", mode
, "-R", path
]
21 tools
.helpers
.run
.user(args
, command
, check
=False)
30 "/sys/kernel/debug/sync/sw_sync",
46 perm_list
.extend(glob
.glob("/dev/fb*"))
48 perm_list
.extend(glob
.glob("/dev/video*"))
50 for path
in perm_list
:
53 def signal_handler(sig
, frame
):
54 services
.hardware_manager
.stop(args
)
58 status
= helpers
.lxc
.status(args
)
59 if status
== "STOPPED":
60 # Load binder and ashmem drivers
61 cfg
= tools
.config
.load(args
)
62 if cfg
["waydroid"]["vendor_type"] == "MAINLINE":
63 if helpers
.drivers
.probeBinderDriver(args
) != 0:
64 logging
.error("Failed to load Binder driver")
65 helpers
.drivers
.probeAshmemDriver(args
)
66 helpers
.drivers
.loadBinderNodes(args
)
68 "/dev/" + args
.BINDER_DRIVER
,
69 "/dev/" + args
.VNDBINDER_DRIVER
,
70 "/dev/" + args
.HWBINDER_DRIVER
73 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
74 session_cfg
= tools
.config
.load_session()
75 if session_cfg
["session"]["state"] != "STOPPED":
76 logging
.warning("Found session config on state: {}, restart session".format(
77 session_cfg
["session"]["state"]))
78 os
.remove(tools
.config
.session_defaults
["config_path"])
79 logging
.debug("Container manager is waiting for session to load")
80 while not os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
83 # Load session configs
84 session_cfg
= tools
.config
.load_session()
87 command
= [tools
.config
.tools_src
+
88 "/data/scripts/waydroid-net.sh", "start"]
89 tools
.helpers
.run
.user(args
, command
, check
=False)
92 if which("waydroid-sensord"):
93 tools
.helpers
.run
.user(
94 args
, ["waydroid-sensord", "/dev/" + args
.HWBINDER_DRIVER
], output
="background")
97 helpers
.images
.mount_rootfs(args
, cfg
["waydroid"]["images_path"])
99 helpers
.protocol
.set_aidl_version(args
)
102 helpers
.mount
.bind(args
, session_cfg
["session"]["waydroid_data"],
103 tools
.config
.defaults
["data"])
107 command
= ["start", "cgroup-lite"]
108 tools
.helpers
.run
.user(args
, command
, check
=False)
109 if os
.path
.ismount("/sys/fs/cgroup/schedtune"):
110 command
= ["umount", "-l", "/sys/fs/cgroup/schedtune"]
111 tools
.helpers
.run
.user(args
, command
, check
=False)
113 #TODO: remove NFC hacks
115 command
= ["stop", "nfcd"]
116 tools
.helpers
.run
.user(args
, command
, check
=False)
121 helpers
.lxc
.start(args
)
122 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
124 while session_cfg
["session"]["state"] != "RUNNING" and timeout
> 0:
125 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
127 "waiting {} seconds for container to start...".format(timeout
))
128 timeout
= timeout
- 1
130 if session_cfg
["session"]["state"] != "RUNNING":
131 raise OSError("container failed to start")
132 tools
.config
.save_session(session_cfg
)
134 services
.hardware_manager
.start(args
)
136 signal
.signal(signal
.SIGINT
, signal_handler
)
137 while os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
138 session_cfg
= tools
.config
.load_session()
139 if session_cfg
["session"]["state"] == "STOPPED":
140 services
.hardware_manager
.stop(args
)
142 elif session_cfg
["session"]["state"] == "UNFREEZE":
143 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
144 tools
.config
.save_session(session_cfg
)
148 logging
.warning("session manager stopped, stopping container and waiting...")
150 services
.hardware_manager
.stop(args
)
153 logging
.error("WayDroid container is {}".format(status
))
156 status
= helpers
.lxc
.status(args
)
157 if status
!= "STOPPED":
158 helpers
.lxc
.stop(args
)
159 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
160 session_cfg
= tools
.config
.load_session()
161 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
162 tools
.config
.save_session(session_cfg
)
165 command
= [tools
.config
.tools_src
+
166 "/data/scripts/waydroid-net.sh", "stop"]
167 tools
.helpers
.run
.user(args
, command
, check
=False)
169 #TODO: remove NFC hacks
171 command
= ["start", "nfcd"]
172 tools
.helpers
.run
.user(args
, command
, check
=False)
175 if which("waydroid-sensord"):
176 command
= ["pidof", "waydroid-sensord"]
177 pid
= tools
.helpers
.run
.user(args
, command
, check
=False, output_return
=True).strip()
179 command
= ["kill", "-9", pid
]
180 tools
.helpers
.run
.user(args
, command
, check
=False)
183 helpers
.images
.umount_rootfs(args
)
186 helpers
.mount
.umount_all(args
, tools
.config
.defaults
["data"])
189 logging
.error("WayDroid container is {}".format(status
))
192 status
= helpers
.lxc
.status(args
)
193 if status
== "RUNNING":
194 helpers
.lxc
.stop(args
)
195 helpers
.lxc
.start(args
)
197 logging
.error("WayDroid container is {}".format(status
))
200 status
= helpers
.lxc
.status(args
)
201 if status
== "RUNNING":
202 helpers
.lxc
.freeze(args
)
203 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
204 session_cfg
= tools
.config
.load_session()
205 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
206 tools
.config
.save_session(session_cfg
)
208 logging
.error("WayDroid container is {}".format(status
))
211 status
= helpers
.lxc
.status(args
)
212 if status
== "FROZEN":
213 helpers
.lxc
.unfreeze(args
)
214 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
215 session_cfg
= tools
.config
.load_session()
216 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
217 tools
.config
.save_session(session_cfg
)
219 logging
.error("WayDroid container is {}".format(status
))