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

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