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

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