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

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