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

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