Add AudioAttributes and AudioFlag for use in HAL interface for engine configuration.

This requires a version bump to android.media.audio.common.types.

cc_defaults and java_defaults are used in order to avoid explicitly updating version references in several Android.bp files when we do future version bumps.

Test: m
Change-Id: I481d4b4e7b4f1302d508ab6eb2c7ed4336a8f801
diff --git a/Android.bp b/Android.bp
index 30b38d3..c0a70b9 100644
--- a/Android.bp
+++ b/Android.bp
@@ -255,7 +255,10 @@
 
 java_defaults {
     name: "framework-minus-apex-defaults",
-    defaults: ["framework-aidl-export-defaults"],
+    defaults: [
+        "framework-aidl-export-defaults",
+        "latest_android_hardware_soundtrigger3_java_static",
+    ],
     srcs: [
         ":framework-non-updatable-sources",
         "core/java/**/*.logtags",
@@ -365,8 +368,6 @@
     sdk_version: "core_platform",
     static_libs: [
         "android.hardware.common.fmq-V1-java",
-        // TODO(b/184162091)
-        "android.hardware.soundtrigger3-V1-java",
         "bouncycastle-repackaged-unbundled",
         "framework-internal-utils",
         // If MimeMap ever becomes its own APEX, then this dependency would need to be removed
diff --git a/core/jni/Android.bp b/core/jni/Android.bp
index 4bc946e..5498769 100644
--- a/core/jni/Android.bp
+++ b/core/jni/Android.bp
@@ -80,6 +80,10 @@
         "include",
     ],
 
+    defaults: [
+        "latest_android_media_audio_common_types_cpp_target_shared",
+    ],
+
     target: {
         android: {
             srcs: [
@@ -243,7 +247,6 @@
             ],
 
             shared_libs: [
-                "android.media.audio.common.types-V1-cpp",
                 "audioclient-types-aidl-cpp",
                 "audioflinger-aidl-cpp",
                 "audiopolicy-types-aidl-cpp",
diff --git a/media/Android.bp b/media/Android.bp
index d28a21c..df5c37a 100644
--- a/media/Android.bp
+++ b/media/Android.bp
@@ -35,8 +35,8 @@
         "aidl/android/media/soundtrigger_middleware/SoundTriggerModuleDescriptor.aidl",
     ],
     imports: [
-        "android.media.audio.common.types-V1",
-        "android.media.soundtrigger.types-V1",
+        "android.media.audio.common.types",
+        "android.media.soundtrigger.types",
         "media_permission-aidl",
     ],
 }
@@ -52,6 +52,7 @@
     ],
     local_include_dir: "aidl",
     srcs: [
+        "aidl/android/media/audio/common/AudioAttributes.aidl",
         "aidl/android/media/audio/common/AudioChannelLayout.aidl",
         "aidl/android/media/audio/common/AudioConfig.aidl",
         "aidl/android/media/audio/common/AudioConfigBase.aidl",
@@ -63,6 +64,7 @@
         "aidl/android/media/audio/common/AudioEncapsulationMetadataType.aidl",
         "aidl/android/media/audio/common/AudioEncapsulationMode.aidl",
         "aidl/android/media/audio/common/AudioEncapsulationType.aidl",
+        "aidl/android/media/audio/common/AudioFlag.aidl",
         "aidl/android/media/audio/common/AudioFormatDescription.aidl",
         "aidl/android/media/audio/common/AudioFormatType.aidl",
         "aidl/android/media/audio/common/AudioGain.aidl",
@@ -122,10 +124,77 @@
             version: "1",
             imports: [],
         },
+        // IMPORTANT: Update latest_android_media_audio_common_types every time
+        // you add the latest frozen version to versions_with_info
     ],
 
 }
 
+// Note: This should always be one version ahead of the last frozen version
+latest_android_media_audio_common_types = "android.media.audio.common.types-V2"
+
+// Modules that depend on android.media.audio.common.types directly can include
+// the following cc_defaults to avoid explicitly managing dependency versions
+// across many scattered files.
+cc_defaults {
+    name: "latest_android_media_audio_common_types_cpp_shared",
+    shared_libs: [
+        latest_android_media_audio_common_types + "-cpp",
+    ],
+}
+
+cc_defaults {
+    name: "latest_android_media_audio_common_types_cpp_export_shared",
+    defaults: [
+        "latest_android_media_audio_common_types_cpp_shared",
+    ],
+    export_shared_lib_headers: [
+        latest_android_media_audio_common_types + "-cpp",
+    ],
+}
+
+cc_defaults {
+    name: "latest_android_media_audio_common_types_cpp_static",
+    static_libs: [
+        latest_android_media_audio_common_types + "-cpp",
+    ],
+}
+
+cc_defaults {
+    name: "latest_android_media_audio_common_types_cpp_export_static",
+    defaults: [
+        "latest_android_media_audio_common_types_cpp_static",
+    ],
+    export_static_lib_headers: [
+        latest_android_media_audio_common_types + "-cpp",
+    ],
+}
+
+cc_defaults {
+    name: "latest_android_media_audio_common_types_ndk_shared",
+    shared_libs: [
+        latest_android_media_audio_common_types + "-ndk",
+    ],
+}
+
+cc_defaults {
+    name: "latest_android_media_audio_common_types_ndk_static",
+    static_libs: [
+        latest_android_media_audio_common_types + "-ndk",
+    ],
+}
+
+cc_defaults {
+    name: "latest_android_media_audio_common_types_cpp_target_shared",
+    target: {
+        android: {
+            shared_libs: [
+                latest_android_media_audio_common_types + "-cpp",
+            ],
+        },
+    },
+}
+
 aidl_interface {
     name: "android.media.soundtrigger.types",
     vendor_available: true,
diff --git a/media/aidl/android/media/audio/common/AudioAttributes.aidl b/media/aidl/android/media/audio/common/AudioAttributes.aidl
new file mode 100644
index 0000000..eb29e10
--- /dev/null
+++ b/media/aidl/android/media/audio/common/AudioAttributes.aidl
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2022 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.media.audio.common;
+
+import android.media.audio.common.AudioContentType;
+import android.media.audio.common.AudioFlag;
+import android.media.audio.common.AudioSource;
+import android.media.audio.common.AudioUsage;
+
+/**
+ * AudioAttributes give information about an audio stream that is more
+ * descriptive than stream type alone.
+ */
+@JavaDerive(equals=true, toString=true)
+@VintfStability
+parcelable AudioAttributes {
+    /**
+     * Classifies the content of the audio signal using categories such as
+     * speech or music
+     */
+    AudioContentType contentType = AudioContentType.UNKNOWN;
+    /**
+     * Classifies the intended use of the audio signal using categories such as
+     * alarm or ringtone
+     */
+    AudioUsage usage = AudioUsage.UNKNOWN;
+    /**
+     * Classifies the audio source using categories such as voice uplink or
+     * remote submix
+     */
+    AudioSource source = AudioSource.DEFAULT;
+    /**
+     * Bitmask describing how playback is to be affected.
+     */
+    int flags = AudioFlag.NONE;
+    /**
+     * Tag is an additional use case qualifier complementing AudioUsage and
+     * AudioContentType. Tags are set by vendor-specific applications and must
+     * be prefixed by "VX_". Vendors must namespace their tag names using the
+     * name of their company to avoid conflicts. The namespace must use at least
+     * three characters, and must go directly after the "VX_" prefix.
+     * For example: "VX_MYCOMPANY_VR".
+     */
+    @utf8InCpp String[] tags;
+}
\ No newline at end of file
diff --git a/media/aidl/android/media/audio/common/AudioFlag.aidl b/media/aidl/android/media/audio/common/AudioFlag.aidl
new file mode 100644
index 0000000..b9d493e
--- /dev/null
+++ b/media/aidl/android/media/audio/common/AudioFlag.aidl
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2022 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.media.audio.common;
+
+/**
+ * Defines the audio flags that are used in AudioAttributes
+ */
+@Backing(type="int")
+@VintfStability
+enum AudioFlag {
+    NONE = 0x0,
+    /**
+     * Flag defining a behavior where the audibility of the sound will be
+     * ensured by the system. To ensure sound audibility, the system only uses
+     * built-in speakers or wired headphones and specifically excludes wireless
+     * audio devices. Note this flag should only be used for sounds subject to
+     * regulatory behaviors in some countries, such as for camera shutter sound,
+     * and not for routing behaviors.
+     */
+    AUDIBILITY_ENFORCED = 0x1 << 0,
+    /**
+     * Skipping 0x1 << 1. This was previously used for SECURE flag, but because
+     * the security feature was never implemented using this flag, and the flag
+     * was never made public, this value may be used for another flag.
+     */
+    /**
+     * Flag to enable when the stream is associated with SCO usage.
+     * Internal use only for dealing with legacy STREAM_BLUETOOTH_SCO
+     */
+    SCO = 0x1 << 2,
+    /**
+     * Flag defining a behavior where the system ensures that the playback of
+     * the sound will be compatible with its use as a broadcast for surrounding
+     * people and/or devices. Ensures audibility with no or minimal
+     * post-processing applied.
+     */
+    BEACON = 0x1 << 3,
+    /**
+     * Flag requesting the use of an output stream supporting hardware A/V
+     * synchronization.
+     */
+    HW_AV_SYNC = 0x1 << 4,
+    /**
+     * Flag requesting capture from the source used for hardware hotword
+     * detection. To be used with capture preset MediaRecorder.AudioSource
+     * HOTWORD or MediaRecorder.AudioSource.VOICE_RECOGNITION.
+     */
+    HW_HOTWORD = 0x1 << 5,
+    /**
+     * Flag requesting audible playback even under limited interruptions.
+     */
+    BYPASS_INTERRUPTION_POLICY = 0x1 << 6,
+    /**
+     * Flag requesting audible playback even when the underlying stream is muted
+     */
+    BYPASS_MUTE = 0x1 << 7,
+    /**
+     * Flag requesting a low latency path when creating an AudioTrack.
+     * When using this flag, the sample rate must match the native sample rate
+     * of the device. Effects processing is also unavailable.
+     */
+    LOW_LATENCY = 0x1 << 8,
+    /**
+     * Flag requesting a deep buffer path when creating an AudioTrack.
+     *
+     * A deep buffer path, if available, may consume less power and is
+     * suitable for media playback where latency is not a concern.
+     */
+    DEEP_BUFFER = 0x1 << 9,
+    /**
+     * Flag specifying that the audio shall not be captured by third-party apps
+     * with a MediaProjection.
+     */
+    NO_MEDIA_PROJECTION = 0x1 << 10,
+    /**
+     * Flag indicating force muting haptic channels.
+     */
+    MUTE_HAPTIC = 0x1 << 11,
+    /**
+     * Flag specifying that the audio shall not be captured by any apps, not
+     * even system apps.
+     */
+    NO_SYSTEM_CAPTURE = 0x1 << 12,
+    /**
+     * Flag requesting private audio capture.
+     */
+    CAPTURE_PRIVATE = 0x1 << 13,
+    /**
+     * Flag indicating the audio content has been processed to provide a virtual
+     * multichannel audio experience.
+     */
+    CONTENT_SPATIALIZED = 0x1 << 14,
+    /**
+     * Flag indicating the audio content is never to be spatialized.
+     */
+    NEVER_SPATIALIZE = 0x1 << 15,
+    /**
+     * Flag indicating the audio is part of a call redirection.
+     * Valid for playback and capture.
+     */
+    CALL_REDIRECTION = 0x1 << 16,
+}
\ No newline at end of file
diff --git a/media/aidl_api/android.media.audio.common.types/current/android/media/audio/common/AudioAttributes.aidl b/media/aidl_api/android.media.audio.common.types/current/android/media/audio/common/AudioAttributes.aidl
new file mode 100644
index 0000000..6d5e234
--- /dev/null
+++ b/media/aidl_api/android.media.audio.common.types/current/android/media/audio/common/AudioAttributes.aidl
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+//     the interface (from the latest frozen version), the build system will
+//     prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file 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.media.audio.common;
+@JavaDerive(equals=true, toString=true) @VintfStability
+parcelable AudioAttributes {
+  android.media.audio.common.AudioContentType contentType = android.media.audio.common.AudioContentType.UNKNOWN;
+  android.media.audio.common.AudioUsage usage = android.media.audio.common.AudioUsage.UNKNOWN;
+  android.media.audio.common.AudioSource source = android.media.audio.common.AudioSource.DEFAULT;
+  int flags = 0;
+  @utf8InCpp String[] tags;
+}
diff --git a/media/aidl_api/android.media.audio.common.types/current/android/media/audio/common/AudioFlag.aidl b/media/aidl_api/android.media.audio.common.types/current/android/media/audio/common/AudioFlag.aidl
new file mode 100644
index 0000000..3138531
--- /dev/null
+++ b/media/aidl_api/android.media.audio.common.types/current/android/media/audio/common/AudioFlag.aidl
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+///////////////////////////////////////////////////////////////////////////////
+// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE.                          //
+///////////////////////////////////////////////////////////////////////////////
+
+// This file is a snapshot of an AIDL file. Do not edit it manually. There are
+// two cases:
+// 1). this is a frozen version file - do not edit this in any case.
+// 2). this is a 'current' file. If you make a backwards compatible change to
+//     the interface (from the latest frozen version), the build system will
+//     prompt you to update this file with `m <name>-update-api`.
+//
+// You must not make a backward incompatible change to any AIDL file 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.media.audio.common;
+@Backing(type="int") @VintfStability
+enum AudioFlag {
+  NONE = 0,
+  AUDIBILITY_ENFORCED = 1,
+  SCO = 4,
+  BEACON = 8,
+  HW_AV_SYNC = 16,
+  HW_HOTWORD = 32,
+  BYPASS_INTERRUPTION_POLICY = 64,
+  BYPASS_MUTE = 128,
+  LOW_LATENCY = 256,
+  DEEP_BUFFER = 512,
+  NO_MEDIA_PROJECTION = 1024,
+  MUTE_HAPTIC = 2048,
+  NO_SYSTEM_CAPTURE = 4096,
+  CAPTURE_PRIVATE = 8192,
+  CONTENT_SPATIALIZED = 16384,
+  NEVER_SPATIALIZE = 32768,
+  CALL_REDIRECTION = 65536,
+}