From 42a4df0cb3adc2d558d1bccf177624b8965a5ed4 Mon Sep 17 00:00:00 2001 From: Abdulwahab Isam Date: Sat, 15 Mar 2025 09:40:00 +0300 Subject: [PATCH] pipa: vendorsetup: switch to LOS hw/ximi and get Dolby separately Signed-off-by: Abdulwahab Isam --- source-patches/update-switch-server-url.diff | 23 -- .../vendor-enable-split-notifications.diff | 40 --- vendorsetup.sh | 330 +++++++++++++----- 3 files changed, 243 insertions(+), 150 deletions(-) delete mode 100644 source-patches/update-switch-server-url.diff delete mode 100644 source-patches/vendor-enable-split-notifications.diff diff --git a/source-patches/update-switch-server-url.diff b/source-patches/update-switch-server-url.diff deleted file mode 100644 index 159fcf6..0000000 --- a/source-patches/update-switch-server-url.diff +++ /dev/null @@ -1,23 +0,0 @@ -From fd9fd7200814c3527e46b02e3c3232e275285312 Mon Sep 17 00:00:00 2001 -From: Abdulwahab Isam -Date: Sat, 15 Mar 2025 09:29:02 +0300 -Subject: [PATCH] official_devices: switch to my repo - -Signed-off-by: Abdulwahab Isam ---- - app/src/main/res/values/strings.xml | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml -index 48b8a95..31fedea 100644 ---- a/app/src/main/res/values/strings.xml -+++ b/app/src/main/res/values/strings.xml -@@ -31,7 +31,7 @@ - {device} - Device name - {variant} - Build variant - --> -- https://raw.githubusercontent.com/AxionAOSP/official_devices/refs/heads/main/OTA/{variant}/{device}.json -+ https://raw.githubusercontent.com/ai94iq/axion_official_devices/refs/heads/main/OTA/{variant}/{device}.json - - Verification failed - Verifying update \ No newline at end of file diff --git a/source-patches/vendor-enable-split-notifications.diff b/source-patches/vendor-enable-split-notifications.diff deleted file mode 100644 index 5bec8f8..0000000 --- a/source-patches/vendor-enable-split-notifications.diff +++ /dev/null @@ -1,40 +0,0 @@ -From 583031a436f448e519c3a6fea79ede078242e86e Mon Sep 17 00:00:00 2001 -From: Abdulwahab Isam -Date: Sat, 15 Mar 2025 09:27:30 +0300 -Subject: [PATCH] Revert "overlays: Disable split shade for tablets" - -This reverts commit decf8b582ae4daedd7e5b6a8f2369a3b48082065. ---- - .../res/values-sw600dp-land/config.xml | 23 ------------------- - 1 file changed, 23 deletions(-) - delete mode 100644 overlay/common/frameworks/base/packages/SystemUI/res/values-sw600dp-land/config.xml - -diff --git a/overlay/common/frameworks/base/packages/SystemUI/res/values-sw600dp-land/config.xml b/overlay/common/frameworks/base/packages/SystemUI/res/values-sw600dp-land/config.xml -deleted file mode 100644 -index 33b6a31319..0000000000 ---- a/overlay/common/frameworks/base/packages/SystemUI/res/values-sw600dp-land/config.xml -+++ /dev/null -@@ -1,23 +0,0 @@ -- -- -- -- -- -- -- false -- \ No newline at end of file diff --git a/vendorsetup.sh b/vendorsetup.sh index 069397e..734bc01 100644 --- a/vendorsetup.sh +++ b/vendorsetup.sh @@ -19,100 +19,256 @@ clone_if_missing "https://github.com/ai94iq/android_device_xiaomi_sm8250-common" clone_if_missing "https://github.com/ai94iq/android_kernel_xiaomi_sm8250" "axksu" "kernel/xiaomi/sm8250" clone_if_missing "https://github.com/ai94iq/proprietary_vendor_xiaomi_sm8250-common" "vic" "vendor/xiaomi/sm8250-common" clone_if_missing "https://github.com/ai94iq/proprietary_vendor_xiaomi_pipa" "vic" "vendor/xiaomi/pipa" -clone_if_missing "https://github.com/ai94iq/cr-android_hardware_xiaomi" "15.0" "hardware/xiaomi" +clone_if_missing "https://github.com/LineageOS/android_hardware_xiaomi" "lineage-22.1" "hardware/xiaomi" +clone_if_missing "https://github.com/ai94iq/android_packages_apps_XiaomiDolby" "axv" "packages/apps/XiaomiDolby" + +# Function for applying patches with enhanced handling +apply_atomic_recovery_patch() { + local root_dir=$(pwd) + local target_dir="bootable/recovery" + local patch_path="${root_dir}/device/xiaomi/pipa/source-patches/atomic-recovery.diff" + + echo "==== Applying atomic-recovery patch ====" + + # Check if patch file exists + if [ ! -f "$patch_path" ]; then + echo "Error: atomic-recovery.diff patch file not found" + echo "Please check if the file exists at: ${patch_path}" + return 1 + fi + + # Create a temporary copy of the patch file with Unix line endings + local temp_patch=$(mktemp) + echo "Normalizing patch line endings..." + tr -d '\r' < "$patch_path" > "$temp_patch" + + # Enter target directory + echo "Navigating to ${target_dir}..." + if ! cd "$target_dir"; then + echo "Error: Could not change to $target_dir directory" + rm "$temp_patch" + return 1 + fi + + echo "Applying atomic-recovery patch..." + + # Save the current state + local current_state=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || git rev-parse HEAD) + + # Try applying with git am first + echo "Trying git am with --3way option..." + if git am --3way "$temp_patch" 2>/dev/null; then + echo "✓ Patch applied successfully using git am" + rm "$temp_patch" + cd "$root_dir" + return 0 + fi + git am --abort 2>/dev/null || true + + # Try git apply + echo "Trying git apply with ignore-whitespace..." + if git apply --check --ignore-whitespace "$temp_patch" 2>/dev/null && + git apply --ignore-whitespace "$temp_patch"; then + echo "✓ Patch applied successfully using git apply" + git add . + git commit -m "Applied atomic-recovery patch" + rm "$temp_patch" + cd "$root_dir" + return 0 + fi + + # Try patch command with various strip levels + echo "Trying patch utility with various strip levels..." + for level in 1 0 2 3; do + if patch -p${level} --ignore-whitespace --no-backup-if-mismatch < "$temp_patch" 2>/dev/null; then + echo "✓ Patch applied successfully using patch -p${level}" + git add . + git commit -m "Applied atomic-recovery patch" + rm "$temp_patch" + cd "$root_dir" + return 0 + fi + done + + # Try partial application + echo "Attempting partial patch application..." + patch -p1 --forward --verbose --ignore-whitespace --no-backup-if-mismatch < "$temp_patch" || true + + # Check if any changes were made + if git diff --name-only | grep -q .; then + echo "✓ Partial application of atomic-recovery patch succeeded" + git add . + git commit -m "Applied atomic-recovery patch (partial)" + rm "$temp_patch" + cd "$root_dir" + return 0 + fi + + echo "✗ Failed to apply atomic-recovery patch after all attempts" + + # Cleanup + git reset --hard HEAD 2>/dev/null || true + rm "$temp_patch" + cd "$root_dir" + return 1 +} + +# Function to apply vendor-enable-split-notifications by removing the config file +apply_split_notifications_fix() { + local root_dir=$(pwd) + local target_dir="vendor/lineage" + local config_file="overlay/common/frameworks/base/packages/SystemUI/res/values-sw600dp-land/config.xml" + + echo "==== Applying split-notifications fix ====" + + # Enter target directory + echo "Navigating to ${target_dir}..." + if ! cd "$target_dir"; then + echo "Error: Could not change to $target_dir directory" + cd "$root_dir" + return 1 + fi + + # Check if the file exists and remove it + if [ -f "$config_file" ]; then + echo "Removing ${config_file}..." + rm -f "$config_file" + + # Commit the changes + git add . + git commit -m "Removed sw600dp-land config to enable split notifications for tablets" + echo "✓ Split-notifications fix applied successfully" + else + echo "Config file doesn't exist, no changes needed" + fi + + # Return to root directory + cd "$root_dir" + return 0 +} + +# Function to update the Updater repository URL +apply_updater_repo_fix() { + local root_dir=$(pwd) + local target_dir="packages/apps/Updater" + local strings_file="app/src/main/res/values/strings.xml" + + echo "==== Applying updater repository URL fix ====" + + # Enter target directory + echo "Navigating to ${target_dir}..." + if ! cd "$target_dir"; then + echo "Error: Could not change to $target_dir directory" + cd "$root_dir" + return 1 + fi + + # Check if the file exists + if [ -f "$strings_file" ]; then + echo "Updating repository URL in ${strings_file}..." + + # Replace the repository URL without creating a backup file + if grep -q "AxionAOSP/official_devices" "$strings_file"; then + echo "Changing AxionAOSP/official_devices to ai94iq/axion_official_devices" + sed -i 's#AxionAOSP/official_devices#ai94iq/axion_official_devices#g' "$strings_file" + + # Commit the changes + git add . + git commit -m "Updated Updater repository URL to ai94iq/axion_official_devices" + echo "✓ Updater repository URL fix applied successfully" + else + echo "Repository URL pattern not found in $strings_file" + fi + else + echo "Strings file doesn't exist at $strings_file" + fi + + # Return to root directory + cd "$root_dir" + return 0 +} + +# Function to update generate_json.sh to add IQ +modify_generate_json() { + local root_dir=$(pwd) + local target_dir="vendor/lineage" + local script_file="build/tools/generate_json.sh" + + echo "==== Modifying generate_json.sh to add IQ tag ====" + + # Enter target directory + echo "Navigating to ${target_dir}..." + if ! cd "$target_dir"; then + echo "Error: Could not change to $target_dir directory" + cd "$root_dir" + return 1 + fi + + # Check if the file exists + if [ -f "$script_file" ]; then + echo "Updating regex in ${script_file}..." + + # Check if the file contains the pattern we want to modify + if grep -q "(COMMUNITY|OFFICIAL|UNOFFICIAL)" "$script_file"; then + echo "Adding IQ tag to the build type regex..." + sed -i 's#(COMMUNITY|OFFICIAL|UNOFFICIAL)#(COMMUNITY|IQ|OFFICIAL|UNOFFICIAL)#g' "$script_file" + + # Commit the changes + git add . + git commit -m "Added IQ tag to generate_json.sh build type regex" + echo "✓ generate_json.sh modification applied successfully" + else + echo "Expected pattern not found in $script_file" + fi + else + echo "Script file doesn't exist at $script_file" + fi + + # Return to root directory + cd "$root_dir" + return 0 +} + +# Main script execution starts here +ROOT_DIR=$(pwd) +DEVICE_PATH="${ROOT_DIR}/device/xiaomi/pipa" + +# Check if the device repository exists +if [ ! -d "$DEVICE_PATH" ]; then + echo "Error: Device directory not found at ${DEVICE_PATH}" + echo "Please ensure all repositories are properly cloned" + exit 1 +fi + +# Create the patches directory if it doesn't exist +PATCHES_DIR="${DEVICE_PATH}/source-patches" +mkdir -p "$PATCHES_DIR" + +# Apply patches one by one, ensuring we return to ROOT_DIR between each +echo "==== Starting patch application process ====" # Apply atomic-recovery patch -( - # Store the root directory and device paths - ROOT_DIR="$(pwd)" - DEVICE_PATH="${ROOT_DIR}/device/xiaomi/pipa" - PATCH_PATH="${DEVICE_PATH}/source-patches/atomic-recovery.diff" +apply_atomic_recovery_patch - # Check if patch file exists - if [ ! -f "$PATCH_PATH" ]; then - echo "Error: Patch file not found at ${PATCH_PATH}" - exit 1 - fi +# Make sure we're in the root directory +cd "$ROOT_DIR" - # Enter recovery directory - cd bootable/recovery || { - echo "Error: Could not change to bootable/recovery directory" - exit 1 - } +# Apply split notifications fix (remove config file) +apply_split_notifications_fix - echo "Applying atomic-recovery patch from ${PATCH_PATH}..." - if git am "${PATCH_PATH}"; then - echo "Patch applied successfully" - else - echo "Patch failed to apply, cleaning up..." - git am --abort - exit 1 - fi +# Make sure we're in the root directory +cd "$ROOT_DIR" - # Return to original directory - cd "${ROOT_DIR}" || echo "Warning: Failed to return to original directory" -) +# Apply updater repository URL fix +apply_updater_repo_fix -# Apply update-switch-server-url patch -( - # Store the root directory and device paths - ROOT_DIR="$(pwd)" - DEVICE_PATH="${ROOT_DIR}/device/xiaomi/pipa" - PATCH_PATH="${DEVICE_PATH}/source-patches/update-switch-server-url.diff" +# Make sure we're in the root directory +cd "$ROOT_DIR" - # Check if patch file exists - if [ ! -f "$PATCH_PATH" ]; then - echo "Error: Patch file not found at ${PATCH_PATH}" - exit 1 - fi +# Apply generate_json.sh modification +modify_generate_json - # Enter Updater directory - cd packages/apps/Updater || { - echo "Error: Could not change to packages/apps/Updater directory" - exit 1 - } +# Make sure we're in the root directory +cd "$ROOT_DIR" - echo "Applying update-switch-server-url patch from ${PATCH_PATH}..." - if git am "${PATCH_PATH}"; then - echo "Patch applied successfully" - else - echo "Patch failed to apply, cleaning up..." - git am --abort - exit 1 - fi - - # Return to original directory - cd "${ROOT_DIR}" || echo "Warning: Failed to return to original directory" -) - -# Apply vendor-enable-split-notifications patch -( - # Store the root directory and device paths - ROOT_DIR="$(pwd)" - DEVICE_PATH="${ROOT_DIR}/device/xiaomi/pipa" - PATCH_PATH="${DEVICE_PATH}/source-patches/vendor-enable-split-notifications.diff" - - # Check if patch file exists - if [ ! -f "$PATCH_PATH" ]; then - echo "Error: Patch file not found at ${PATCH_PATH}" - exit 1 - fi - - # Enter vendor/lineage directory - cd vendor/lineage || { - echo "Error: Could not change to vendor/lineage directory" - exit 1 - } - - echo "Applying vendor-enable-split-notifications patch from ${PATCH_PATH}..." - if git am "${PATCH_PATH}"; then - echo "Patch applied successfully" - else - echo "Patch failed to apply, cleaning up..." - git am --abort - exit 1 - fi - - # Return to original directory - cd "${ROOT_DIR}" || echo "Warning: Failed to return to original directory" -) \ No newline at end of file +echo "==== Patch application complete ====" \ No newline at end of file