]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/initializer.py
container: Umount on stop
[waydroid.git] / tools / actions / initializer.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 import logging
4 import os
5 from tools import helpers
6 import tools.config
7
8
9 def get_vendor_type(args):
10 vndk_str = helpers.props.host_get(args, "ro.vndk.version")
11 ret = "MAINLINE"
12 if vndk_str != "":
13 vndk = int(vndk_str)
14 if vndk > 19:
15 ret = "HALIUM_" + str(vndk - 19)
16
17 return ret
18
19 def setup_config(args):
20 cfg = tools.config.load(args)
21 args.arch = helpers.arch.host()
22 cfg["waydroid"]["arch"] = args.arch
23
24 preinstalled_images = tools.config.defaults["preinstalled_images_path"]
25 if not args.images_path:
26 if os.path.isdir(preinstalled_images):
27 if os.path.isfile(preinstalled_images + "/system.img") and os.path.isfile(preinstalled_images + "/vendor.img"):
28 args.images_path = preinstalled_images
29 else:
30 logging.error("Missing system or vendor on preinstalled images dir, fallback to default")
31 if not args.images_path:
32 args.images_path = tools.config.defaults["images_path"]
33 cfg["waydroid"]["images_path"] = args.images_path
34
35 channels_cfg = tools.config.load_channels()
36 if not args.system_channel:
37 args.system_channel = channels_cfg["channels"]["system_channel"]
38 if not args.vendor_channel:
39 args.vendor_channel = channels_cfg["channels"]["vendor_channel"]
40 if not args.rom_type:
41 args.rom_type = channels_cfg["channels"]["rom_type"]
42 if not args.system_type:
43 args.system_type = channels_cfg["channels"]["system_type"]
44
45 args.system_ota = args.system_channel + "/" + args.rom_type + \
46 "/waydroid_" + args.arch + "/" + args.system_type + ".json"
47 system_request = helpers.http.retrieve(args.system_ota)
48 if system_request[0] != 200:
49 if args.images_path != preinstalled_images:
50 raise ValueError(
51 "Failed to get system OTA channel: {}, error: {}".format(args.system_ota, system_request[0]))
52 else:
53 args.system_ota = "None"
54
55 device_codename = helpers.props.host_get(args, "ro.product.device")
56 args.vendor_type = None
57 for vendor in [device_codename, get_vendor_type(args)]:
58 vendor_ota = args.vendor_channel + "/waydroid_" + \
59 args.arch + "/" + vendor + ".json"
60 vendor_request = helpers.http.retrieve(vendor_ota)
61 if vendor_request[0] == 200:
62 args.vendor_type = vendor
63 args.vendor_ota = vendor_ota
64 break
65
66 if not args.vendor_type:
67 if args.images_path != preinstalled_images:
68 raise ValueError(
69 "Failed to get vendor OTA channel: {}".format(vendor_ota))
70 else:
71 args.vendor_ota = "None"
72 args.vendor_type = get_vendor_type(args)
73
74 cfg["waydroid"]["vendor_type"] = args.vendor_type
75 cfg["waydroid"]["system_ota"] = args.system_ota
76 cfg["waydroid"]["vendor_ota"] = args.vendor_ota
77 helpers.drivers.setupBinderNodes(args)
78 cfg["waydroid"]["binder"] = args.BINDER_DRIVER
79 cfg["waydroid"]["vndbinder"] = args.VNDBINDER_DRIVER
80 cfg["waydroid"]["hwbinder"] = args.HWBINDER_DRIVER
81 tools.config.save(args, cfg)
82
83 def init(args):
84 if not os.path.isfile(args.config) or args.force:
85 setup_config(args)
86 status = "STOPPED"
87 if os.path.exists(tools.config.defaults["lxc"] + "/waydroid"):
88 status = helpers.lxc.status(args)
89 if status != "STOPPED":
90 logging.info("Stopping container")
91 helpers.lxc.stop(args)
92 helpers.images.umount_rootfs(args)
93 if args.images_path != tools.config.defaults["preinstalled_images_path"]:
94 helpers.images.get(args)
95 if not os.path.isdir(tools.config.defaults["rootfs"]):
96 os.mkdir(tools.config.defaults["rootfs"])
97 helpers.lxc.setup_host_perms(args)
98 helpers.lxc.set_lxc_config(args)
99 helpers.lxc.make_base_props(args)
100 if status != "STOPPED":
101 logging.info("Starting container")
102 helpers.images.mount_rootfs(args, args.images_path)
103 helpers.lxc.start(args)
104 else:
105 logging.info("Already initialized")