audio policy: allow direct outputs for dynamic audio policies

Add support for direct outputs with RENDER audio policy mixes.
A mix of type render can be registered even if no corresponding
output is opened to reach targeted device provided a direct output
profile exist for this device.

Also:
- Fix setUidDeviceAffinities(): was not closing direct outputs
opened by checkOutputsForDevice() and was not re-evaluating routes

- Fix removeUidDeviceAffinities(): was not re-evaluating routes

- Implement consistent sanity checks on selected devices in
setUidDeviceAffinities(), setUserIdDeviceAffinities() and
setPreferredDeviceForStrategy().

- Fix onNewAudioModulesAvailableInt(): attached devices reachable only
via direct outputs were not loaded.

Bug: 130296239
Test: AudioHostTest
Test: AudioServiceHostTest
Test: audiopolicy_tests
Test: manual test: Auto projection over USB, screen mirroring
Change-Id: I54470b61b4bc7e041e3a295764d368c5ded21268
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index c142880..b588f89 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -837,7 +837,7 @@
                 audio_output_flags_t *flags,
                 audio_port_handle_t *selectedDeviceId,
                 bool *isRequestedDeviceForExclusiveUse,
-                std::vector<sp<SwAudioOutputDescriptor>> *secondaryDescs,
+                std::vector<sp<AudioPolicyMix>> *secondaryMixes,
                 output_type_t *outputType);
         // internal method to return the output handle for the given device and format
         audio_io_handle_t getOutputForDevices(
@@ -848,6 +848,16 @@
                 audio_output_flags_t *flags,
                 bool forceMutingHaptic = false);
 
+        // Internal method checking if a direct output can be opened matching the requested
+        // attributes, flags, config and devices.
+        // If NAME_NOT_FOUND is returned, an attempt can be made to open a mixed output.
+        status_t openDirectOutput(
+                audio_stream_type_t stream,
+                audio_session_t session,
+                const audio_config_t *config,
+                audio_output_flags_t flags,
+                const DeviceVector &devices,
+                audio_io_handle_t *output);
         /**
          * @brief getInputForDevice selects an input handle for a given input device and
          * requester context
@@ -926,6 +936,12 @@
                 int delayMs,
                 uid_t uid,
                 sp<AudioPatch> *patchDescPtr);
+
+        bool areAllDevicesSupported(
+                const Vector<AudioDeviceTypeAddr>& devices,
+                std::function<bool(audio_devices_t)> predicate,
+                const char* context);
+
 };
 
 };