+def do_start(args, session):
+ if "session" in args:
+ raise RuntimeError("Already tracking a session")
+
+ logging.info("Starting up container for a new session")
+
+ # Networking
+ command = [tools.config.tools_src +
+ "/data/scripts/waydroid-net.sh", "start"]
+ tools.helpers.run.user(args, command)
+
+ # Sensors
+ if which("waydroid-sensord"):
+ tools.helpers.run.user(
+ args, ["waydroid-sensord", "/dev/" + args.HWBINDER_DRIVER], output="background")
+
+ # Cgroup hacks
+ if which("start"):
+ command = ["start", "cgroup-lite"]
+ tools.helpers.run.user(args, command, check=False)
+
+ # Keep schedtune around in case nesting is supported
+ if os.path.ismount("/sys/fs/cgroup/schedtune"):
+ try:
+ os.mkdir("/sys/fs/cgroup/schedtune/probe0")
+ os.mkdir("/sys/fs/cgroup/schedtune/probe0/probe1")
+ except:
+ command = ["umount", "-l", "/sys/fs/cgroup/schedtune"]
+ tools.helpers.run.user(args, command, check=False)
+ finally:
+ if os.path.exists("/sys/fs/cgroup/schedtune/probe0/probe1"):
+ os.rmdir("/sys/fs/cgroup/schedtune/probe0/probe1")
+ if os.path.exists("/sys/fs/cgroup/schedtune/probe0"):
+ os.rmdir("/sys/fs/cgroup/schedtune/probe0")
+
+ #TODO: remove NFC hacks
+ if which("stop"):
+ command = ["stop", "nfcd"]
+ tools.helpers.run.user(args, command, check=False)
+ elif which("systemctl") and (tools.helpers.run.user(args, ["systemctl", "is-active", "-q", "nfcd"], check=False) == 0):
+ command = ["systemctl", "stop", "nfcd"]
+ tools.helpers.run.user(args, command, check=False)
+
+ # Set permissions
+ set_permissions(args)
+
+ # Create session-specific LXC config file
+ helpers.lxc.generate_session_lxc_config(args, session)
+ # Backwards compatibility
+ with open(tools.config.defaults["lxc"] + "/waydroid/config") as f:
+ if "config_session" not in f.read():
+ helpers.mount.bind(args, session["waydroid_data"],
+ tools.config.defaults["data"])
+
+ # Mount rootfs
+ cfg = tools.config.load(args)
+ helpers.images.mount_rootfs(args, cfg["waydroid"]["images_path"], session)
+
+ helpers.protocol.set_aidl_version(args)
+
+ helpers.lxc.start(args)
+ services.hardware_manager.start(args)
+
+ args.session = session
+
+def stop(args, quit_session=True):
+ logging.info("Stopping container")
+
+ try:
+ services.hardware_manager.stop(args)
+ status = helpers.lxc.status(args)
+ if status != "STOPPED":
+ helpers.lxc.stop(args)
+ while helpers.lxc.status(args) != "STOPPED":
+ pass