]>
glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/actions/initializer.py
1 # Copyright 2021 Erfan Abdi
2 # SPDX-License-Identifier: GPL-3.0-or-later
5 from tools
import helpers
9 def get_vendor_type(args
):
10 vndk_str
= helpers
.props
.host_get(args
, "ro.vndk.version")
15 ret
= "HALIUM_" + str(vndk
- 19)
19 def setup_config(args
):
20 cfg
= tools
.config
.load(args
)
21 args
.arch
= helpers
.arch
.host()
22 cfg
["waydroid"]["arch"] = args
.arch
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
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
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"]
41 args
.rom_type
= channels_cfg
["channels"]["rom_type"]
42 if not args
.system_type
:
43 args
.system_type
= channels_cfg
["channels"]["system_type"]
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
:
51 "Failed to get system OTA channel: {}, error: {}".format(args
.system_ota
, system_request
[0]))
53 args
.system_ota
= "None"
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
66 if not args
.vendor_type
:
67 if args
.images_path
!= preinstalled_images
:
69 "Failed to get vendor OTA channel: {}".format(vendor_ota
))
71 args
.vendor_ota
= "None"
72 args
.vendor_type
= get_vendor_type(args
)
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
)
84 if not os
.path
.isfile(args
.config
) or not os
.path
.isdir(tools
.config
.defaults
["rootfs"]) or args
.force
:
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
)
105 logging
.info("Already initialized")