audio: add flag for the Ultrasound input source and content_type

Adding the AUDIO_OUTPUT_FLAG_ULTRASOUND and AUDIO_INPUT_FLAG_ULTRASOUND
for the Ultrasound playback and capture respectively.

If device supports the dedicated output or input for the Ultrasound
content or input source, then assign the Ultrasound track to the
specific Ultrasound output or input.

Bug: 200256985
Test: build pass
Signed-off-by: Carter Hsu <carterhsu@google.com>
Change-Id: I2b56b8ef72fbeed50f960fd41e6b992dbb4f8daa
diff --git a/media/utils/ServiceUtilities.cpp b/media/utils/ServiceUtilities.cpp
index 15d6d3697..1ab5bc1 100644
--- a/media/utils/ServiceUtilities.cpp
+++ b/media/utils/ServiceUtilities.cpp
@@ -220,6 +220,17 @@
     return ok;
 }
 
+bool accessUltrasoundAllowed(const AttributionSourceState& attributionSource) {
+    uid_t uid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t(attributionSource.uid));
+    uid_t pid = VALUE_OR_FATAL(aidl2legacy_int32_t_pid_t(attributionSource.pid));
+    if (isAudioServerOrRootUid(uid)) return true;
+    static const String16 sAccessUltrasound(
+        "android.permission.ACCESS_ULTRASOUND");
+    bool ok = PermissionCache::checkPermission(sAccessUltrasound, pid, uid);
+    if (!ok) ALOGE("Request requires android.permission.ACCESS_ULTRASOUND");
+    return ok;
+}
+
 bool captureHotwordAllowed(const AttributionSourceState& attributionSource) {
     // CAPTURE_AUDIO_HOTWORD permission implies RECORD_AUDIO permission
     bool ok = recordingAllowed(attributionSource);