#!/usr/bin/env bash
set -euo pipefail

if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/interfaces/automotive/ivn_android_device/aidl/android.hardware.automotive.ivn_interface/has_development )" = "1" ]; then mkdir -p hardware/interfaces/automotive/ivn_android_device/aidl/aidl_api/android.hardware.automotive.ivn/2 &&  cp -rf out_adevtool_deps/soong/.intermediates/hardware/interfaces/automotive/ivn_android_device/aidl/android.hardware.automotive.ivn_interface/dump/. hardware/interfaces/automotive/ivn_android_device/aidl/aidl_api/android.hardware.automotive.ivn/2 ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/interfaces/automotive/ivn_android_device/aidl/android.hardware.automotive.ivn_interface/has_development )" = "1" ]; then echo "There is change between ToT version and the latest stable version. Freezing android.hardware.automotive.ivn-V2." ; else echo "There is no change from the latest stable version of android.hardware.automotive.ivn. Nothing happened." ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/interfaces/automotive/ivn_android_device/aidl/android.hardware.automotive.ivn_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m android.hardware.automotive.ivn -parameter versions -remove-property hardware/interfaces/automotive/ivn_android_device/aidl/Android.bp ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/interfaces/automotive/ivn_android_device/aidl/android.hardware.automotive.ivn_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m android.hardware.automotive.ivn -parameter versions_with_info -add-literal '{version: "2", imports: []}'  hardware/interfaces/automotive/ivn_android_device/aidl/Android.bp && out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m android.hardware.automotive.ivn -parameter frozen -set-bool true hardware/interfaces/automotive/ivn_android_device/aidl/Android.bp ; fi
