]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/initializer.py
config: Edit system_channel (systems -> system)
[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 import requests
6 from tools import helpers
7 import tools.config
8
9
10 def get_vendor_type(args):
11 vndk_str = helpers.props.host_get(args, "ro.vndk.version")
12 ret = "MAINLINE"
13 if vndk_str != "":
14 vndk = int(vndk_str)
15 if vndk > 19:
16 ret = "HALIUM_" + str(vndk - 19)
17
18 return ret
19
20 def setup_config(args):
21 cfg = tools.config.load(args)
22 args.arch = helpers.arch.host()
23 cfg["waydroid"]["arch"] = args.arch
24 cfg["waydroid"]["images_path"] = args.images_path
25
26 channels_cfg = tools.config.load_channels()
27 if not args.system_channel:
28 args.system_channel = channels_cfg["channels"]["system_channel"]
29 if not args.vendor_channel:
30 args.vendor_channel = channels_cfg["channels"]["vendor_channel"]
31 if not args.rom_type:
32 args.rom_type = channels_cfg["channels"]["rom_type"]
33 if not args.system_type:
34 args.system_type = channels_cfg["channels"]["system_type"]
35
36 args.system_ota = args.system_channel + "/" + args.rom_type + \
37 "/waydroid_" + args.arch + "/" + args.system_type + ".json"
38 system_request = requests.get(args.system_ota)
39 if system_request.status_code != 200:
40 raise ValueError(
41 "Failed to get system OTA channel: {}".format(args.system_ota))
42
43 device_codename = helpers.props.host_get(args, "ro.product.device")
44 args.vendor_type = None
45 for vendor in [device_codename, get_vendor_type(args)]:
46 vendor_ota = args.vendor_channel + "/waydroid_" + \
47 args.arch + "/" + vendor + ".json"
48 vendor_request = requests.get(vendor_ota)
49 if vendor_request.status_code == 200:
50 args.vendor_type = vendor
51 args.vendor_ota = vendor_ota
52 break
53
54 if not args.vendor_type:
55 raise ValueError(
56 "Failed to get vendor OTA channel: {}".format(vendor_ota))
57
58 cfg["waydroid"]["vendor_type"] = args.vendor_type
59 cfg["waydroid"]["system_ota"] = args.system_ota
60 cfg["waydroid"]["vendor_ota"] = args.vendor_ota
61 helpers.drivers.setupBinderNodes(args)
62 cfg["waydroid"]["binder"] = args.BINDER_DRIVER
63 cfg["waydroid"]["vndbinder"] = args.VNDBINDER_DRIVER
64 cfg["waydroid"]["hwbinder"] = args.HWBINDER_DRIVER
65 tools.config.save(args, cfg)
66
67 def init(args):
68 if not os.path.isfile(args.config) or args.force:
69 setup_config(args)
70 status = "STOPPED"
71 if os.path.exists(tools.config.defaults["lxc"] + "/waydroid"):
72 status = helpers.lxc.status(args)
73 if status != "STOPPED":
74 logging.info("Stopping container")
75 helpers.lxc.stop(args)
76 helpers.images.umount_rootfs(args)
77 helpers.images.get(args)
78 if not os.path.isdir(tools.config.defaults["rootfs"]):
79 os.mkdir(tools.config.defaults["rootfs"])
80 helpers.lxc.setup_host_perms(args)
81 helpers.lxc.set_lxc_config(args)
82 helpers.lxc.make_base_props(args)
83 if status != "STOPPED":
84 logging.info("Starting container")
85 helpers.images.mount_rootfs(args, args.images_path)
86 helpers.lxc.start(args)
87 else:
88 logging.info("Already initialized")