]>
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
11 from tools
import helpers
12 from tools
import services
16 def make_prop(full_props_path
):
17 def add_prop(key
, cfg_key
):
18 value
= session_cfg
["session"][cfg_key
]
20 props
.append(key
+ "=" + session_cfg
["session"][cfg_key
])
22 if not os
.path
.isfile(args
.work
+ "/waydroid_base.prop"):
23 raise RuntimeError("waydroid_base.prop Not found")
24 with open(args
.work
+ "/waydroid_base.prop") as f
:
25 props
= f
.read().splitlines()
27 raise RuntimeError("waydroid_base.prop is broken!!?")
29 add_prop("waydroid.host.user", "user_name")
30 add_prop("waydroid.host.uid", "user_id")
31 add_prop("waydroid.host.gid", "group_id")
32 add_prop("waydroid.xdg_runtime_dir", "xdg_runtime_dir")
33 add_prop("waydroid.pulse_runtime_path", "pulse_runtime_path")
34 add_prop("waydroid.wayland_display", "wayland_display")
35 if which("waydroid-sensord") is None:
36 props
.append("waydroid.stub_sensors_hal=1")
37 dpi
= session_cfg
["session"]["lcd_density"]
39 props
.append("ro.sf.lcd_density=" + dpi
)
41 final_props
= open(full_props_path
, "w")
43 final_props
.write(prop
+ "\n")
45 os
.chmod(full_props_path
, 0o644)
47 def set_permissions(perm_list
=None, mode
="777"):
48 def chmod(path
, mode
):
49 if os
.path
.exists(path
):
50 command
= ["chmod", mode
, "-R", path
]
51 tools
.helpers
.run
.root(args
, command
, check
=False)
60 "/sys/kernel/debug/sync/sw_sync",
74 # Wayland and pulse socket permissions
75 session_cfg
["session"]["pulse_runtime_path"],
76 session_cfg
["session"]["xdg_runtime_dir"]
80 perm_list
.extend(glob
.glob("/dev/fb*"))
82 for path
in perm_list
:
85 def signal_handler(sig
, frame
):
86 services
.hardware_manager
.stop(args
)
90 status
= helpers
.lxc
.status(args
)
91 if status
== "STOPPED":
92 # Load binder and ashmem drivers
93 cfg
= tools
.config
.load(args
)
94 if cfg
["waydroid"]["vendor_type"] == "MAINLINE":
95 if helpers
.drivers
.probeBinderDriver(args
) != 0:
96 logging
.error("Failed to load Binder driver")
97 if helpers
.drivers
.probeAshmemDriver(args
) != 0:
98 logging
.error("Failed to load Ashmem driver")
99 helpers
.drivers
.loadBinderNodes(args
)
101 "/dev/" + args
.BINDER_DRIVER
,
102 "/dev/" + args
.VNDBINDER_DRIVER
,
103 "/dev/" + args
.HWBINDER_DRIVER
106 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
107 session_cfg
= tools
.config
.load_session()
108 if session_cfg
["session"]["state"] != "STOPPED":
109 logging
.warning("Found session config on state: {}, restart session".format(
110 session_cfg
["session"]["state"]))
111 os
.remove(tools
.config
.session_defaults
["config_path"])
112 logging
.debug("Container manager is waiting for session to load")
113 while not os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
116 # Load session configs
117 session_cfg
= tools
.config
.load_session()
120 make_prop(args
.work
+ "/waydroid.prop")
123 command
= [tools
.config
.tools_src
+
124 "/data/scripts/waydroid-net.sh", "start"]
125 tools
.helpers
.run
.root(args
, command
, check
=False)
128 tools
.helpers
.run
.root(
129 args
, ["waydroid-sensord", "/dev/" + args
.HWBINDER_DRIVER
], output
="background")
132 helpers
.images
.mount_rootfs(args
, cfg
["waydroid"]["images_path"])
135 helpers
.mount
.bind(args
, session_cfg
["session"]["waydroid_data"],
136 tools
.config
.defaults
["data"])
140 command
= ["start", "cgroup-lite"]
141 tools
.helpers
.run
.root(args
, command
, check
=False)
142 helpers
.mount
.umount_all(args
, "/sys/fs/cgroup/schedtune")
144 #TODO: remove NFC hacks
146 command
= ["stop", "nfcd"]
147 tools
.helpers
.run
.root(args
, command
, check
=False)
152 helpers
.lxc
.start(args
)
153 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
154 tools
.config
.save_session(session_cfg
)
156 if not hasattr(args
, 'hardwareLoop'):
157 services
.hardware_manager
.start(args
)
159 signal
.signal(signal
.SIGINT
, signal_handler
)
160 while os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
161 session_cfg
= tools
.config
.load_session()
162 if session_cfg
["session"]["state"] == "STOPPED":
163 services
.hardware_manager
.stop(args
)
165 elif session_cfg
["session"]["state"] == "UNFREEZE":
166 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
167 tools
.config
.save_session(session_cfg
)
171 logging
.warning("session manager stopped, stopping container and waiting...")
175 logging
.error("WayDroid container is {}".format(status
))
178 status
= helpers
.lxc
.status(args
)
179 if status
!= "STOPPED":
180 helpers
.lxc
.stop(args
)
181 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
182 session_cfg
= tools
.config
.load_session()
183 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
184 tools
.config
.save_session(session_cfg
)
187 command
= [tools
.config
.tools_src
+
188 "/data/scripts/waydroid-net.sh", "stop"]
189 tools
.helpers
.run
.root(args
, command
, check
=False)
191 #TODO: remove NFC hacks
193 command
= ["start", "nfcd"]
194 tools
.helpers
.run
.root(args
, command
, check
=False)
197 if which("waydroid-sensord"):
198 command
= ["pidof", "waydroid-sensord"]
199 pid
= tools
.helpers
.run
.root(args
, command
, check
=False, output_return
=True)
201 command
= ["killall", pid
]
202 tools
.helpers
.run
.root(args
, command
, check
=False)
205 logging
.error("WayDroid container is {}".format(status
))
208 status
= helpers
.lxc
.status(args
)
209 if status
== "RUNNING":
210 helpers
.lxc
.freeze(args
)
211 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
212 session_cfg
= tools
.config
.load_session()
213 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
214 tools
.config
.save_session(session_cfg
)
216 logging
.error("WayDroid container is {}".format(status
))
219 status
= helpers
.lxc
.status(args
)
220 if status
== "FROZEN":
221 helpers
.lxc
.unfreeze(args
)
222 if os
.path
.exists(tools
.config
.session_defaults
["config_path"]):
223 session_cfg
= tools
.config
.load_session()
224 session_cfg
["session"]["state"] = helpers
.lxc
.status(args
)
225 tools
.config
.save_session(session_cfg
)
227 logging
.error("WayDroid container is {}".format(status
))