APM: Reject attempts to use DEEP_BUFFER in openDirectOutput

Expand the existing rejection logic in openDirectOutput
to cover the case of sampling rates > SAMPLE_RATE_HZ_MAX (192 kHz).
For example, an explicit request for DEEP_BUFFER music with high
SR, or finding an output for music with 'audio.deep_buffer.media'
enabled could end up selecting a matching profile from
a mix port with DIRECT flag, and that would yield an invalid
DIRECT | DEEP_BUFFER flag combination sent to the HAL.

Added new tests AudioPolicyManagerOutputMixPort*Selection
to verify two thing:
  1. Which output stream gets created / selected for various
     combinations of attributes.
  2. Whether APM passes the set of flags which corresponds
     to the actual flags declared by a mix port.

Flag: EXEMPT bugfix
Bug: 357522537
Test: atest audiopolicy_tests
Change-Id: I819b03946a88e8013d4c1dea50f14af3688e7cbc
Merged-In: I819b03946a88e8013d4c1dea50f14af3688e7cbc
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index f36d8d5..2897db8 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -1153,8 +1153,7 @@
 
     SortedVector<audio_io_handle_t> outputs = getOutputsForDevices(devices, mOutputs);
     audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE;
-    if (stream == AUDIO_STREAM_MUSIC &&
-        property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
+    if (stream == AUDIO_STREAM_MUSIC && mConfig->useDeepBufferForMedia()) {
         flags = AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
     }
     const audio_io_handle_t output = selectOutput(outputs, flags);
@@ -1527,6 +1526,13 @@
         return NAME_NOT_FOUND;
     }
 
+    // Reject flag combinations that do not make sense. Note that the requested flags might not
+    // have the 'DIRECT' flag set, however once a direct-capable profile is found, it will
+    // combine the requested flags with its own flags, yielding an unsupported combination.
+    if ((flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) != 0) {
+        return NAME_NOT_FOUND;
+    }
+
     // Do not allow offloading if one non offloadable effect is enabled or MasterMono is enabled.
     // This prevents creating an offloaded track and tearing it down immediately after start
     // when audioflinger detects there is an active non offloadable effect.
@@ -1675,8 +1681,7 @@
     if (stream != AUDIO_STREAM_MUSIC) {
         *flags = (audio_output_flags_t)(*flags &~AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
     } else if (/* stream == AUDIO_STREAM_MUSIC && */
-            *flags == AUDIO_OUTPUT_FLAG_NONE &&
-            property_get_bool("audio.deep_buffer.media", false /* default_value */)) {
+            *flags == AUDIO_OUTPUT_FLAG_NONE && mConfig->useDeepBufferForMedia()) {
         // use DEEP_BUFFER as default output for music stream type
         *flags = (audio_output_flags_t)AUDIO_OUTPUT_FLAG_DEEP_BUFFER;
     }