Added IAudioControl#onDevicesToMuteChange

Added new API and parceable for informing the HAL when to mute and
unmute audio for automotive targets. Also added default implementation
to log information passed on.

Bug: 173141906
Test: atest VtsAidlHalAudioControlTest
Change-Id: I4c20320d33417616eef7a980a375ab9303b43eab
diff --git a/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/current/android/hardware/automotive/audiocontrol/IAudioControl.aidl b/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/current/android/hardware/automotive/audiocontrol/IAudioControl.aidl
index e5a0451..bc4162b 100644
--- a/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/current/android/hardware/automotive/audiocontrol/IAudioControl.aidl
+++ b/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/current/android/hardware/automotive/audiocontrol/IAudioControl.aidl
@@ -20,6 +20,7 @@
 interface IAudioControl {
   oneway void onAudioFocusChange(in String usage, in int zoneId, in android.hardware.automotive.audiocontrol.AudioFocusChange focusChange);
   oneway void onDevicesToDuckChange(in android.hardware.automotive.audiocontrol.DuckingInfo[] duckingInfos);
+  oneway void onDevicesToMuteChange(in android.hardware.automotive.audiocontrol.MutingInfo[] mutingInfos);
   oneway void registerFocusListener(in android.hardware.automotive.audiocontrol.IFocusListener listener);
   oneway void setBalanceTowardRight(in float value);
   oneway void setFadeTowardFront(in float value);
diff --git a/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/current/android/hardware/automotive/audiocontrol/MutingInfo.aidl b/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/current/android/hardware/automotive/audiocontrol/MutingInfo.aidl
new file mode 100644
index 0000000..ab902ec
--- /dev/null
+++ b/automotive/audiocontrol/aidl/aidl_api/android.hardware.automotive.audiocontrol/current/android/hardware/automotive/audiocontrol/MutingInfo.aidl
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL interface (or parcelable). Do not try to
+// edit this file. It looks like you are doing that because you have modified
+// an AIDL interface in a backward-incompatible way, e.g., deleting a function
+// from an interface or a field from a parcelable and it broke the build. That
+// breakage is intended.
+//
+// You must not make a backward incompatible changes to the AIDL files built
+// with the aidl_interface module type with versions property set. The module
+// type is used to build AIDL files in a way that they can be used across
+// independently updatable components of the system. If a device is shipped
+// with such a backward incompatible change, it has a high risk of breaking
+// later when a module using the interface is updated, e.g., Mainline modules.
+
+package android.hardware.automotive.audiocontrol;
+@VintfStability
+parcelable MutingInfo {
+  int zoneId;
+  String[] deviceAddressesToMute;
+  String[] deviceAddressesToUnmute;
+}
diff --git a/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl b/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl
index 4b03af1..3a02245 100644
--- a/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl
+++ b/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/IAudioControl.aidl
@@ -18,6 +18,7 @@
 
 import android.hardware.automotive.audiocontrol.AudioFocusChange;
 import android.hardware.automotive.audiocontrol.DuckingInfo;
+import android.hardware.automotive.audiocontrol.MutingInfo;
 import android.hardware.automotive.audiocontrol.IFocusListener;
 
 /**
@@ -53,6 +54,18 @@
      */
      oneway void onDevicesToDuckChange(in DuckingInfo[] duckingInfos);
 
+     /**
+      * Notifies HAL of changes in output devices that the HAL should apply muting to.
+      *
+      * This will be called in response to changes in audio mute state for each volume group
+      * and will include a {@link MutingInfo} object per audio zone that experienced a mute state
+      * event.
+      *
+      * @param mutingInfos an array of {@link MutingInfo} objects for the audio zones where audio
+      * mute state has changed.
+      */
+     oneway void onDevicesToMuteChange(in MutingInfo[] mutingInfos);
+
     /**
      * Registers focus listener to be used by HAL for requesting and abandoning audio focus.
      *
diff --git a/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/MutingInfo.aidl b/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/MutingInfo.aidl
new file mode 100644
index 0000000..783640f
--- /dev/null
+++ b/automotive/audiocontrol/aidl/android/hardware/automotive/audiocontrol/MutingInfo.aidl
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package android.hardware.automotive.audiocontrol;
+
+ /**
+  * The current muting information for a single audio zone.
+  *
+  * <p>This includes devices to mute, as well as mute based on the contents of a previous
+  * {@link MutingInfo}.
+  */
+ @VintfStability
+ parcelable MutingInfo {
+     /**
+      * ID of the associated audio zone
+      */
+     int zoneId;
+
+     /**
+      * List of addresses for audio output devices that should be muted.
+      *
+      * <p>The provided address strings are defined in audio_policy_configuration.xml.
+      */
+     String[] deviceAddressesToMute;
+
+     /**
+      * List of addresses for audio output devices that were previously be muted and should now be
+      * unmuted.
+      *
+      * <p>The provided address strings are defined in audio_policy_configuration.xml.
+      */
+     String[] deviceAddressesToUnmute;
+ }
\ No newline at end of file
diff --git a/automotive/audiocontrol/aidl/default/AudioControl.cpp b/automotive/audiocontrol/aidl/default/AudioControl.cpp
index 748947c..b076d01 100644
--- a/automotive/audiocontrol/aidl/default/AudioControl.cpp
+++ b/automotive/audiocontrol/aidl/default/AudioControl.cpp
@@ -109,21 +109,38 @@
     for (const DuckingInfo& duckingInfo : in_duckingInfos) {
         LOG(INFO) << "zone: " << duckingInfo.zoneId;
         LOG(INFO) << "Devices to duck:";
-        for (auto& addressToDuck : duckingInfo.deviceAddressesToDuck) {
+        for (const auto& addressToDuck : duckingInfo.deviceAddressesToDuck) {
             LOG(INFO) << addressToDuck;
         }
         LOG(INFO) << "Devices to unduck:";
-        for (auto& addressToUnduck : duckingInfo.deviceAddressesToUnduck) {
+        for (const auto& addressToUnduck : duckingInfo.deviceAddressesToUnduck) {
             LOG(INFO) << addressToUnduck;
         }
         LOG(INFO) << "Usages holding focus:";
-        for (auto& usage : duckingInfo.usagesHoldingFocus) {
+        for (const auto& usage : duckingInfo.usagesHoldingFocus) {
             LOG(INFO) << usage;
         }
     }
     return ndk::ScopedAStatus::ok();
 }
 
+ndk::ScopedAStatus AudioControl::onDevicesToMuteChange(
+        const std::vector<MutingInfo>& in_mutingInfos) {
+    LOG(INFO) << "AudioControl::onDevicesToMuteChange";
+    for (const MutingInfo& mutingInfo : in_mutingInfos) {
+        LOG(INFO) << "zone: " << mutingInfo.zoneId;
+        LOG(INFO) << "Devices to mute:";
+        for (const auto& addressToMute : mutingInfo.deviceAddressesToMute) {
+            LOG(INFO) << addressToMute;
+        }
+        LOG(INFO) << "Devices to unmute:";
+        for (const auto& addressToUnmute : mutingInfo.deviceAddressesToUnmute) {
+            LOG(INFO) << addressToUnmute;
+        }
+    }
+    return ndk::ScopedAStatus::ok();
+}
+
 binder_status_t AudioControl::dump(int fd, const char** args, uint32_t numArgs) {
     if (numArgs == 0) {
         return dumpsys(fd);
diff --git a/automotive/audiocontrol/aidl/default/AudioControl.h b/automotive/audiocontrol/aidl/default/AudioControl.h
index cf56947..ab0b1b3 100644
--- a/automotive/audiocontrol/aidl/default/AudioControl.h
+++ b/automotive/audiocontrol/aidl/default/AudioControl.h
@@ -19,6 +19,7 @@
 #include <aidl/android/hardware/automotive/audiocontrol/AudioFocusChange.h>
 #include <aidl/android/hardware/automotive/audiocontrol/BnAudioControl.h>
 #include <aidl/android/hardware/automotive/audiocontrol/DuckingInfo.h>
+#include <aidl/android/hardware/automotive/audiocontrol/MutingInfo.h>
 
 namespace aidl::android::hardware::automotive::audiocontrol {
 
@@ -30,6 +31,8 @@
                                           AudioFocusChange in_focusChange) override;
     ndk::ScopedAStatus onDevicesToDuckChange(
             const std::vector<DuckingInfo>& in_duckingInfos) override;
+    ndk::ScopedAStatus onDevicesToMuteChange(
+            const std::vector<MutingInfo>& in_mutingInfos) override;
     ndk::ScopedAStatus registerFocusListener(
             const shared_ptr<IFocusListener>& in_listener) override;
     ndk::ScopedAStatus setBalanceTowardRight(float in_value) override;
diff --git a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
index f23280d..ae53c68 100644
--- a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
+++ b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp
@@ -33,6 +33,7 @@
 using android::hardware::automotive::audiocontrol::BnFocusListener;
 using android::hardware::automotive::audiocontrol::DuckingInfo;
 using android::hardware::automotive::audiocontrol::IAudioControl;
+using android::hardware::automotive::audiocontrol::MutingInfo;
 
 #include "android_audio_policy_configuration_V7_0.h"
 
@@ -130,6 +131,18 @@
             audioControl->onAudioFocusChange(usage, 0, AudioFocusChange::GAIN_TRANSIENT).isOk());
 };
 
+TEST_P(AudioControlAidl, MuteChangeExercise) {
+    ALOGI("Mute change test");
+
+    MutingInfo mutingInfo;
+    mutingInfo.zoneId = 0;
+    mutingInfo.deviceAddressesToMute = {String16("address 1"), String16("address 2")};
+    mutingInfo.deviceAddressesToUnmute = {String16("address 3"), String16("address 4")};
+    std::vector<MutingInfo> mutingInfos = {mutingInfo};
+    ALOGI("Mute change test start");
+    ASSERT_TRUE(audioControl->onDevicesToMuteChange(mutingInfos).isOk());
+}
+
 TEST_P(AudioControlAidl, DuckChangeExercise) {
     ALOGI("Duck change test");