Add IAudioManagerNative

Add AIDL interface for structured AIDL subset of AudioService APIs to
enable native access without manual interface implementation.

Test: compiles
Test: atest AudioRecordTest
Bug: 376481063
Flag: EXEMPT refactor
Change-Id: I503891943e59d773d030a31c4c07d16dae0bb311
diff --git a/Android.bp b/Android.bp
index c716a06..aa71786 100644
--- a/Android.bp
+++ b/Android.bp
@@ -60,6 +60,7 @@
     double_loadable: true,
     local_include_dir: "aidl",
     srcs: [
+        "aidl/android/media/IAudioManagerNative.aidl",
         "aidl/android/media/InterpolatorConfig.aidl",
         "aidl/android/media/InterpolatorType.aidl",
         "aidl/android/media/MicrophoneInfoFw.aidl",
diff --git a/aidl/android/media/IAudioManagerNative.aidl b/aidl/android/media/IAudioManagerNative.aidl
new file mode 100644
index 0000000..59d2648
--- /dev/null
+++ b/aidl/android/media/IAudioManagerNative.aidl
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2024 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;
+
+/**
+ * Native accessible interface for AudioService.
+ * Note this interface has a mix of oneway and non-oneway methods. This is intentional for certain
+ * calls intended to come from audioserver.
+ * {@hide}
+ */
+interface IAudioManagerNative {
+    enum HardeningType {
+        // Restricted due to OP_CONTROL_AUDIO_PARTIAL
+        // This OP is more permissive than OP_CONTROL_AUDIO, which allows apps in a foreground state
+        // not associated with FGS to access audio
+        PARTIAL,
+        // Restricted due to OP_CONTROL_AUDIO
+        FULL,
+    }
+
+    /**
+     * audioserver is muting playback due to hardening.
+     * Calls which aren't from uid 1041 are dropped.
+     * @param uid - the uid whose playback is restricted
+     * @param type - the level of playback restriction which was hit (full or partial)
+     * @param bypassed - true if the client should be muted but was exempted (for example due to a
+     * certain audio usage to prevent regressions)
+     */
+    oneway void playbackHardeningEvent(in int uid, in HardeningType type, in boolean bypassed);
+
+    /**
+     * Block until AudioService synchronizes pending permission state with audioserver.
+     */
+    void permissionUpdateBarrier();
+}
diff --git a/media/libaudioclient/AudioRecord.cpp b/media/libaudioclient/AudioRecord.cpp
index a261379..af390c1 100644
--- a/media/libaudioclient/AudioRecord.cpp
+++ b/media/libaudioclient/AudioRecord.cpp
@@ -286,7 +286,7 @@
     if (binder != nullptr) {
         // Barrier to ensure runtime permission update propagates to audioflinger
         // Must be client-side
-        interface_cast<IAudioManager>(binder)->permissionUpdateBarrier();
+        interface_cast<IAudioManager>(binder)->getNativeInterface()->permissionUpdateBarrier();
     }
 
     mSelectedDeviceId = selectedDeviceId;