]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/helpers/images.py
debian/control: add Depends on pipewire-pulse | pulseaudio
[waydroid.git] / tools / helpers / images.py
index ac85f4faca001109157047239dc5894256343295..8a88f2970dd3b53f3ca59bb46498260b7a97d56f 100644 (file)
@@ -4,6 +4,7 @@ import logging
 import zipfile
 import json
 import hashlib
+import shutil
 import os
 import tools.config
 from tools import helpers
@@ -78,6 +79,21 @@ def get(args):
             tools.config.save(args, cfg)
             os.remove(images_zip)
             break
+    remove_overlay(args)
+
+def validate(args, channel, image_zip):
+    # Verify that the zip comes from the channel
+    cfg = tools.config.load(args)
+    channel_url = cfg["waydroid"][channel]
+    channel_request = helpers.http.retrieve(channel_url)
+    if channel_request[0] != 200:
+        return False
+    channel_responses = json.loads(channel_request[1].decode('utf8'))["response"]
+    for build in channel_responses:
+        if sha256sum(image_zip) == build['id']:
+            return True
+    logging.warning(f"Could not verify the image {image_zip} against {channel_url}")
+    return False
 
 def replace(args, system_zip, system_time, vendor_zip, vendor_time):
     cfg = tools.config.load(args)
@@ -85,15 +101,24 @@ def replace(args, system_zip, system_time, vendor_zip, vendor_time):
     if os.path.exists(system_zip):
         with zipfile.ZipFile(system_zip, 'r') as zip_ref:
             zip_ref.extractall(args.images_path)
+        os.remove(system_zip)
         cfg["waydroid"]["system_datetime"] = str(system_time)
         tools.config.save(args, cfg)
     if os.path.exists(vendor_zip):
         with zipfile.ZipFile(vendor_zip, 'r') as zip_ref:
             zip_ref.extractall(args.images_path)
+        os.remove(vendor_zip)
         cfg["waydroid"]["vendor_datetime"] = str(vendor_time)
         tools.config.save(args, cfg)
+    remove_overlay(args)
 
-def make_prop(args, full_props_path):
+def remove_overlay(args):
+    if os.path.isdir(tools.config.defaults["overlay_rw"]):
+        shutil.rmtree(tools.config.defaults["overlay_rw"])
+    if os.path.isdir(tools.config.defaults["overlay_work"]):
+        shutil.rmtree(tools.config.defaults["overlay_work"])
+
+def make_prop(args, cfg, full_props_path):
     if not os.path.isfile(args.work + "/waydroid_base.prop"):
         raise RuntimeError("waydroid_base.prop Not found")
     with open(args.work + "/waydroid_base.prop") as f:
@@ -101,10 +126,8 @@ def make_prop(args, full_props_path):
     if not props:
         raise RuntimeError("waydroid_base.prop is broken!!?")
 
-    session_cfg = tools.config.load_session()
-
     def add_prop(key, cfg_key):
-        value = session_cfg["session"][cfg_key]
+        value = cfg[cfg_key]
         if value != "None":
             value = value.replace("/mnt/", "/mnt_extra/")
             props.append(key + "=" + value)
@@ -112,12 +135,14 @@ def make_prop(args, full_props_path):
     add_prop("waydroid.host.user", "user_name")
     add_prop("waydroid.host.uid", "user_id")
     add_prop("waydroid.host.gid", "group_id")
-    add_prop("waydroid.xdg_runtime_dir", "xdg_runtime_dir")
-    add_prop("waydroid.pulse_runtime_path", "pulse_runtime_path")
-    add_prop("waydroid.wayland_display", "wayland_display")
+    add_prop("waydroid.host_data_path", "waydroid_data")
+    add_prop("waydroid.background_start", "background_start")
+    props.append("waydroid.xdg_runtime_dir=" + tools.config.defaults["container_xdg_runtime_dir"])
+    props.append("waydroid.pulse_runtime_path=" + tools.config.defaults["container_pulse_runtime_path"])
+    props.append("waydroid.wayland_display=" + tools.config.defaults["container_wayland_display"])
     if which("waydroid-sensord") is None:
         props.append("waydroid.stub_sensors_hal=1")
-    dpi = session_cfg["session"]["lcd_density"]
+    dpi = cfg["lcd_density"]
     if dpi != "0":
         props.append("ro.sf.lcd_density=" + dpi)
 
@@ -127,11 +152,31 @@ def make_prop(args, full_props_path):
     final_props.close()
     os.chmod(full_props_path, 0o644)
 
-def mount_rootfs(args, images_dir):
+def mount_rootfs(args, images_dir, session):
+    cfg = tools.config.load(args)
     helpers.mount.mount(args, images_dir + "/system.img",
                         tools.config.defaults["rootfs"], umount=True)
+    if cfg["waydroid"]["mount_overlays"] == "True":
+        try:
+            helpers.mount.mount_overlay(args, [tools.config.defaults["overlay"],
+                                               tools.config.defaults["rootfs"]],
+                                    tools.config.defaults["rootfs"],
+                                    upper_dir=tools.config.defaults["overlay_rw"] + "/system",
+                                    work_dir=tools.config.defaults["overlay_work"] + "/system")
+        except RuntimeError:
+            cfg["waydroid"]["mount_overlays"] = "False"
+            tools.config.save(args, cfg)
+            logging.warning("Mounting overlays failed. The feature has been disabled.")
+
     helpers.mount.mount(args, images_dir + "/vendor.img",
                            tools.config.defaults["rootfs"] + "/vendor")
+    if cfg["waydroid"]["mount_overlays"] == "True":
+        helpers.mount.mount_overlay(args, [tools.config.defaults["overlay"] + "/vendor",
+                                           tools.config.defaults["rootfs"] + "/vendor"],
+                                    tools.config.defaults["rootfs"] + "/vendor",
+                                    upper_dir=tools.config.defaults["overlay_rw"] + "/vendor",
+                                    work_dir=tools.config.defaults["overlay_work"] + "/vendor")
+
     for egl_path in ["/vendor/lib/egl", "/vendor/lib64/egl"]:
         if os.path.isdir(egl_path):
             helpers.mount.bind(
@@ -144,7 +189,7 @@ def mount_rootfs(args, images_dir):
             helpers.mount.bind(
                 args, "/vendor/odm", tools.config.defaults["rootfs"] + "/odm_extra")
 
-    make_prop(args, args.work + "/waydroid.prop")
+    make_prop(args, session, args.work + "/waydroid.prop")
     helpers.mount.bind_file(args, args.work + "/waydroid.prop",
                             tools.config.defaults["rootfs"] + "/vendor/waydroid.prop")