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

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