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

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