audio: Add offload reconfiguration event to IBluetoothLe

Since BT LE can also have offloaded codecs, it might need
a reconfiguration event similar to the one that BT A2DP
receives.

Bug: 272658632
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I04fb7c99f0457f87e1f4aaf7e77165317163387b
diff --git a/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/IBluetoothLe.aidl b/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/IBluetoothLe.aidl
index f29e1fd..2068daf 100644
--- a/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/IBluetoothLe.aidl
+++ b/audio/aidl/aidl_api/android.hardware.audio.core/current/android/hardware/audio/core/IBluetoothLe.aidl
@@ -36,4 +36,6 @@
 interface IBluetoothLe {
   boolean isEnabled();
   void setEnabled(boolean enabled);
+  boolean supportsOffloadReconfiguration();
+  void reconfigureOffload(in android.hardware.audio.core.VendorParameter[] parameters);
 }
diff --git a/audio/aidl/android/hardware/audio/core/IBluetoothA2dp.aidl b/audio/aidl/android/hardware/audio/core/IBluetoothA2dp.aidl
index c4dd738..a690ca4 100644
--- a/audio/aidl/android/hardware/audio/core/IBluetoothA2dp.aidl
+++ b/audio/aidl/android/hardware/audio/core/IBluetoothA2dp.aidl
@@ -55,7 +55,7 @@
     /**
      * Indicates whether the module supports reconfiguration of offloaded codecs.
      *
-     * Offloaded coded implementations may need to be reconfigured when the
+     * Offloaded codec implementations may need to be reconfigured when the
      * active A2DP device changes. This method indicates whether the HAL module
      * supports the reconfiguration event. The result returned from this method
      * must not change over time.
@@ -67,11 +67,11 @@
     /**
      * Instructs the HAL module to reconfigure offloaded codec.
      *
-     * Offloaded coded implementations may need to be reconfigured when the
+     * Offloaded codec implementations may need to be reconfigured when the
      * active A2DP device changes. This method is a notification for the HAL
      * module to commence reconfiguration.
      *
-     * Note that 'EX_UNSUPPORTED_OPERATION' may only be thrown when
+     * Note that 'EX_UNSUPPORTED_OPERATION' must be thrown if and only if
      * 'supportsOffloadReconfiguration' returns 'false'.
      *
      * @param parameter Optional vendor-specific parameters, can be left empty.
diff --git a/audio/aidl/android/hardware/audio/core/IBluetoothLe.aidl b/audio/aidl/android/hardware/audio/core/IBluetoothLe.aidl
index 272f862..444ff68 100644
--- a/audio/aidl/android/hardware/audio/core/IBluetoothLe.aidl
+++ b/audio/aidl/android/hardware/audio/core/IBluetoothLe.aidl
@@ -16,6 +16,8 @@
 
 package android.hardware.audio.core;
 
+import android.hardware.audio.core.VendorParameter;
+
 /**
  * An instance of IBluetoothLe manages settings for the LE (Low Energy)
  * profiles. This interface is optional to implement by the vendor. It needs to
@@ -48,4 +50,33 @@
      * @throws EX_ILLEGAL_STATE If there was an error performing the operation.
      */
     void setEnabled(boolean enabled);
+
+    /**
+     * Indicates whether the module supports reconfiguration of offloaded codecs.
+     *
+     * Offloaded codec implementations may need to be reconfigured when the
+     * active LE device changes. This method indicates whether the HAL module
+     * supports the reconfiguration event. The result returned from this method
+     * must not change over time.
+     *
+     * @return Whether reconfiguration offload of offloaded codecs is supported.
+     */
+    boolean supportsOffloadReconfiguration();
+
+    /**
+     * Instructs the HAL module to reconfigure offloaded codec.
+     *
+     * Offloaded codec implementations may need to be reconfigured when the
+     * active LE device changes. This method is a notification for the HAL
+     * module to commence reconfiguration.
+     *
+     * Note that 'EX_UNSUPPORTED_OPERATION' must be thrown if and only if
+     * 'supportsOffloadReconfiguration' returns 'false'.
+     *
+     * @param parameter Optional vendor-specific parameters, can be left empty.
+     * @throws EX_ILLEGAL_STATE If there was an error performing the operation,
+     *                          or the operation can not be commenced in the current state.
+     * @throws EX_UNSUPPORTED_OPERATION If the module does not support codec reconfiguration.
+     */
+    void reconfigureOffload(in VendorParameter[] parameters);
 }
diff --git a/audio/aidl/default/Bluetooth.cpp b/audio/aidl/default/Bluetooth.cpp
index 8115e7b..c32b538 100644
--- a/audio/aidl/default/Bluetooth.cpp
+++ b/audio/aidl/default/Bluetooth.cpp
@@ -117,4 +117,17 @@
     return ndk::ScopedAStatus::ok();
 }
 
+ndk::ScopedAStatus BluetoothLe::supportsOffloadReconfiguration(bool* _aidl_return) {
+    *_aidl_return = true;
+    LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
+    return ndk::ScopedAStatus::ok();
+}
+
+ndk::ScopedAStatus BluetoothLe::reconfigureOffload(
+        const std::vector<::aidl::android::hardware::audio::core::VendorParameter>& in_parameters
+                __unused) {
+    LOG(DEBUG) << __func__ << ": " << ::android::internal::ToString(in_parameters);
+    return ndk::ScopedAStatus::ok();
+}
+
 }  // namespace aidl::android::hardware::audio::core
diff --git a/audio/aidl/default/include/core-impl/Bluetooth.h b/audio/aidl/default/include/core-impl/Bluetooth.h
index 1cd0355..10e9045 100644
--- a/audio/aidl/default/include/core-impl/Bluetooth.h
+++ b/audio/aidl/default/include/core-impl/Bluetooth.h
@@ -56,6 +56,10 @@
   private:
     ndk::ScopedAStatus isEnabled(bool* _aidl_return) override;
     ndk::ScopedAStatus setEnabled(bool in_enabled) override;
+    ndk::ScopedAStatus supportsOffloadReconfiguration(bool* _aidl_return) override;
+    ndk::ScopedAStatus reconfigureOffload(
+            const std::vector<::aidl::android::hardware::audio::core::VendorParameter>&
+                    in_parameters) override;
 
     bool mEnabled = false;
 };
diff --git a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp
index 650a543..387ee8d 100644
--- a/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp
+++ b/audio/aidl/vts/VtsHalAudioCoreModuleTargetTest.cpp
@@ -2148,6 +2148,23 @@
             << "setEnabled without actual state change must not fail";
 }
 
+TEST_P(AudioCoreBluetoothLe, OffloadReconfiguration) {
+    if (bluetooth == nullptr) {
+        GTEST_SKIP() << "BluetoothLe is not supported";
+    }
+    bool isSupported;
+    ASSERT_IS_OK(bluetooth->supportsOffloadReconfiguration(&isSupported));
+    bool isSupported2;
+    ASSERT_IS_OK(bluetooth->supportsOffloadReconfiguration(&isSupported2));
+    EXPECT_EQ(isSupported, isSupported2);
+    if (isSupported) {
+        static const auto kStatuses = {EX_NONE, EX_ILLEGAL_STATE};
+        EXPECT_STATUS(kStatuses, bluetooth->reconfigureOffload({}));
+    } else {
+        EXPECT_STATUS(EX_UNSUPPORTED_OPERATION, bluetooth->reconfigureOffload({}));
+    }
+}
+
 class AudioCoreTelephony : public AudioCoreModuleBase, public testing::TestWithParam<std::string> {
   public:
     void SetUp() override {