mount("ext4", "EMMC", add_slot_suffix("/dev/block/oem"), "/oem", "ro");
file_getprop("/oem/oem.prop", "ro.product.name") == "t982_ar31a8" || abort("E3000: This package expects the value \"t982_ar31a8\" for \"ro.product.name\"; this has value \"" + file_getprop("/oem/oem.prop", "ro.product.name") + "\".");
file_getprop("/oem/oem.prop", "ro.product.brand") == "Droidlogic" || abort("E3000: This package expects the value \"Droidlogic\" for \"ro.product.brand\"; this has value \"" + file_getprop("/oem/oem.prop", "ro.product.brand") + "\".");
file_getprop("/oem/oem.prop", "ro.product.device") == "t982_ar31a8" || abort("E3000: This package expects the value \"t982_ar31a8\" for \"ro.product.device\"; this has value \"" + file_getprop("/oem/oem.prop", "ro.product.device") + "\".");
ui_print("Target: Droidlogic/t982_ar31a8/t982_ar31a8:11/RQ3A.210705.001/2025120401:userdebug/release-keys");
if get_update_stage() == "2" then
ui_print("DTB changed => writing super_empty_all.img to super block...");
package_extract_file("super_empty_all.img", "/dev/block/super");
else
ui_print("DTB NOT changed...");
endif;
delete_file("/cache/recovery/dynamic_partition_metadata.UPDATED");

# --- Start patching dynamic partitions ---


# Update dynamic partition metadata

assert(update_dynamic_partitions(package_extract_file("dynamic_partitions_op_list")));

# Patch partition system

ui_print("Patching system image unconditionally...");
show_progress(0.500000, 0);
block_image_update(map_partition("system"), package_extract_file("system.transfer.list"), "system.new.dat.br", "system.patch.dat") ||
  abort("E1001: Failed to update system image.");

# Patch partition vendor

ui_print("Patching vendor image unconditionally...");
show_progress(0.100000, 0);
block_image_update(map_partition("vendor"), package_extract_file("vendor.transfer.list"), "vendor.new.dat.br", "vendor.patch.dat") ||
  abort("E2001: Failed to update vendor image.");

# Patch partition product

ui_print("Patching product image unconditionally...");
show_progress(0.100000, 0);
block_image_update(map_partition("product"), package_extract_file("product.transfer.list"), "product.new.dat.br", "product.patch.dat") ||
  abort("E2001: Failed to update product image.");

# Patch partition odm

ui_print("Patching odm image unconditionally...");
show_progress(0.100000, 0);
block_image_update(map_partition("odm"), package_extract_file("odm.transfer.list"), "odm.new.dat.br", "odm.patch.dat") ||
  abort("E2001: Failed to update odm image.");

# Patch partition system_ext

ui_print("Patching system_ext image unconditionally...");
show_progress(0.100000, 0);
block_image_update(map_partition("system_ext"), package_extract_file("system_ext.transfer.list"), "system_ext.new.dat.br", "system_ext.patch.dat") ||
  abort("E2001: Failed to update system_ext image.");

# --- End patching dynamic partitions ---

package_extract_file("boot.img", add_slot_suffix("/dev/block/boot"));
show_progress(0.100000, 10);
ui_print("Patching odm_ext image unconditionally...");
block_image_update(add_slot_suffix("/dev/block/odm_ext"), package_extract_file("odm_ext.transfer.list"), "odm_ext.new.dat.br", "odm_ext.patch.dat") ||
  abort("E2001: Failed to update odm_ext image.");
ui_print("update logo.img...");
package_extract_file("logo.img", add_slot_suffix("/dev/block/logo"));
ui_print("update dtbo.img...");
package_extract_file("dtbo.img", add_slot_suffix("/dev/block/dtbo"));
ui_print("update tclconfig.img...");
package_extract_file("tclconfig.img", add_slot_suffix("/dev/block/tclconfig"));
ui_print("update vendor_boot.img...");
package_extract_file("vendor_boot.img", "/cache/recovery/vendor_boot.img");
set_bootloader_env("backup_vendor_boot", "1");
package_extract_file("vendor_boot.img", add_slot_suffix("/dev/block/vendor_boot"));
set_bootloader_env("backup_vendor_boot", "0");
delete_file("/cache/recovery/vendor_boot.img");
if recovery_backup_exist() == "0" then
backup_data_cache(dtb, /cache/recovery/);
backup_data_cache(recovery, /cache/recovery/);
endif;
ui_print("update dtb.img...");
write_dtb_image(package_extract_file("dt.img"));
ui_print("update vbmeta.img...");
package_extract_file("vbmeta.img", add_slot_suffix("/dev/block/vbmeta"));
delete_file("/cache/recovery/dtb.img");
delete_file("/cache/recovery/recovery.img");
ui_print("update bootloader.img...");
write_bootloader_image(package_extract_file("bootloader.img"));
if get_update_stage() == "2" then
set_update_stage("0");
endif;
set_bootloader_env("force_auto_update", "false");
unmount("/oem");
set_progress(1.000000);
