]>
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
6 from tools
import helpers
10 def get_vendor_type(args
):
11 vndk_str
= helpers
.props
.host_get(args
, "ro.vndk.version")
16 ret
= "HALIUM_" + str(vndk
- 19)
20 def setup_config(args
):
21 cfg
= tools
.config
.load(args
)
22 args
.arch
= helpers
.arch
.host()
23 cfg
["waydroid"]["arch"] = args
.arch
25 preinstalled_images
= tools
.config
.defaults
["preinstalled_images_path"]
26 if not args
.images_path
:
27 if os
.path
.isdir(preinstalled_images
):
28 if os
.path
.isfile(preinstalled_images
+ "/system.img") and os
.path
.isfile(preinstalled_images
+ "/vendor.img"):
29 args
.images_path
= preinstalled_images
31 logging
.error("Missing system or vendor on preinstalled images dir, fallback to default")
32 if not args
.images_path
:
33 args
.images_path
= tools
.config
.defaults
["images_path"]
34 cfg
["waydroid"]["images_path"] = args
.images_path
36 channels_cfg
= tools
.config
.load_channels()
37 if not args
.system_channel
:
38 args
.system_channel
= channels_cfg
["channels"]["system_channel"]
39 if not args
.vendor_channel
:
40 args
.vendor_channel
= channels_cfg
["channels"]["vendor_channel"]
42 args
.rom_type
= channels_cfg
["channels"]["rom_type"]
43 if not args
.system_type
:
44 args
.system_type
= channels_cfg
["channels"]["system_type"]
46 args
.system_ota
= args
.system_channel
+ "/" + args
.rom_type
+ \
47 "/waydroid_" + args
.arch
+ "/" + args
.system_type
+ ".json"
48 system_request
= requests
.get(args
.system_ota
)
49 if system_request
.status_code
!= 200:
50 if args
.images_path
!= preinstalled_images
:
52 "Failed to get system OTA channel: {}".format(args
.system_ota
))
54 args
.system_ota
= "None"
56 device_codename
= helpers
.props
.host_get(args
, "ro.product.device")
57 args
.vendor_type
= None
58 for vendor
in [device_codename
, get_vendor_type(args
)]:
59 vendor_ota
= args
.vendor_channel
+ "/waydroid_" + \
60 args
.arch
+ "/" + vendor
+ ".json"
61 vendor_request
= requests
.get(vendor_ota
)
62 if vendor_request
.status_code
== 200:
63 args
.vendor_type
= vendor
64 args
.vendor_ota
= vendor_ota
67 if not args
.vendor_type
:
68 if args
.images_path
!= preinstalled_images
:
70 "Failed to get vendor OTA channel: {}".format(vendor_ota
))
72 args
.vendor_ota
= "None"
73 args
.vendor_type
= get_vendor_type(args
)
75 cfg
["waydroid"]["vendor_type"] = args
.vendor_type
76 cfg
["waydroid"]["system_ota"] = args
.system_ota
77 cfg
["waydroid"]["vendor_ota"] = args
.vendor_ota
78 helpers
.drivers
.setupBinderNodes(args
)
79 cfg
["waydroid"]["binder"] = args
.BINDER_DRIVER
80 cfg
["waydroid"]["vndbinder"] = args
.VNDBINDER_DRIVER
81 cfg
["waydroid"]["hwbinder"] = args
.HWBINDER_DRIVER
82 tools
.config
.save(args
, cfg
)
85 if not os
.path
.isfile(args
.config
) or args
.force
:
88 if os
.path
.exists(tools
.config
.defaults
["lxc"] + "/waydroid"):
89 status
= helpers
.lxc
.status(args
)
90 if status
!= "STOPPED":
91 logging
.info("Stopping container")
92 helpers
.lxc
.stop(args
)
93 helpers
.images
.umount_rootfs(args
)
94 if args
.images_path
!= tools
.config
.defaults
["preinstalled_images_path"]:
95 helpers
.images
.get(args
)
96 if not os
.path
.isdir(tools
.config
.defaults
["rootfs"]):
97 os
.mkdir(tools
.config
.defaults
["rootfs"])
98 helpers
.lxc
.setup_host_perms(args
)
99 helpers
.lxc
.set_lxc_config(args
)
100 helpers
.lxc
.make_base_props(args
)
101 if status
!= "STOPPED":
102 logging
.info("Starting container")
103 helpers
.images
.mount_rootfs(args
, args
.images_path
)
104 helpers
.lxc
.start(args
)
106 logging
.info("Already initialized")