Skip to content

Commit cdf8ea8

Browse files
Treehugger RobotAndroid (Google) Code Review
authored andcommitted
Merge "[audio] Add AudioManager getNativeInterface" into main
2 parents ad55421 + 5eb8360 commit cdf8ea8

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

include/audiomanager/IAudioManager.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef ANDROID_IAUDIOMANAGER_H
1818
#define ANDROID_IAUDIOMANAGER_H
1919

20+
#include <android/media/IAudioManagerNative.h>
2021
#include <audiomanager/AudioManager.h>
2122
#include <utils/Errors.h>
2223
#include <binder/IInterface.h>
@@ -34,20 +35,23 @@ class IAudioManager : public IInterface
3435
// These transaction IDs must be kept in sync with the method order from
3536
// IAudioService.aidl.
3637
enum {
37-
TRACK_PLAYER = IBinder::FIRST_CALL_TRANSACTION,
38-
PLAYER_ATTRIBUTES = IBinder::FIRST_CALL_TRANSACTION + 1,
39-
PLAYER_EVENT = IBinder::FIRST_CALL_TRANSACTION + 2,
40-
RELEASE_PLAYER = IBinder::FIRST_CALL_TRANSACTION + 3,
41-
TRACK_RECORDER = IBinder::FIRST_CALL_TRANSACTION + 4,
42-
RECORDER_EVENT = IBinder::FIRST_CALL_TRANSACTION + 5,
43-
RELEASE_RECORDER = IBinder::FIRST_CALL_TRANSACTION + 6,
44-
PLAYER_SESSION_ID = IBinder::FIRST_CALL_TRANSACTION + 7,
45-
PORT_EVENT = IBinder::FIRST_CALL_TRANSACTION + 8,
46-
PERMISSION_UPDATE_BARRIER = IBinder::FIRST_CALL_TRANSACTION + 9,
38+
GET_NATIVE_INTERFACE = IBinder::FIRST_CALL_TRANSACTION,
39+
TRACK_PLAYER = IBinder::FIRST_CALL_TRANSACTION + 1,
40+
PLAYER_ATTRIBUTES = IBinder::FIRST_CALL_TRANSACTION + 2,
41+
PLAYER_EVENT = IBinder::FIRST_CALL_TRANSACTION + 3,
42+
RELEASE_PLAYER = IBinder::FIRST_CALL_TRANSACTION + 4,
43+
TRACK_RECORDER = IBinder::FIRST_CALL_TRANSACTION + 5,
44+
RECORDER_EVENT = IBinder::FIRST_CALL_TRANSACTION + 6,
45+
RELEASE_RECORDER = IBinder::FIRST_CALL_TRANSACTION + 7,
46+
PLAYER_SESSION_ID = IBinder::FIRST_CALL_TRANSACTION + 8,
47+
PORT_EVENT = IBinder::FIRST_CALL_TRANSACTION + 9,
48+
PERMISSION_UPDATE_BARRIER = IBinder::FIRST_CALL_TRANSACTION + 10,
4749
};
4850

4951
DECLARE_META_INTERFACE(AudioManager)
5052

53+
virtual sp<media::IAudioManagerNative> getNativeInterface() = 0;
54+
5155
// The parcels created by these methods must be kept in sync with the
5256
// corresponding methods from IAudioService.aidl and objects it imports.
5357
virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,

services/audiomanager/Android.bp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cc_library {
1515
],
1616

1717
shared_libs: [
18+
"av-types-aidl-cpp",
1819
"libutils",
1920
"libbinder",
2021
"liblog",

services/audiomanager/IAudioManager.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ class BpAudioManager : public BpInterface<IAudioManager>
3535
{
3636
}
3737

38+
// This should never fail
39+
virtual sp<media::IAudioManagerNative> getNativeInterface() {
40+
Parcel data, reply;
41+
data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
42+
const status_t res = remote()->transact(GET_NATIVE_INTERFACE, data, &reply, 0);
43+
LOG_ALWAYS_FATAL_IF(res != OK, "%s failed with result %d", __func__, res);
44+
const int ex = reply.readExceptionCode();
45+
LOG_ALWAYS_FATAL_IF(ex != binder::Status::EX_NONE, "%s failed with exception %d",
46+
__func__,
47+
ex);
48+
sp<IBinder> binder;
49+
const status_t err = reply.readNullableStrongBinder(&binder);
50+
LOG_ALWAYS_FATAL_IF(binder == nullptr, "%s failed unexpected nullptr %d", __func__, err);
51+
const auto iface = checked_interface_cast<media::IAudioManagerNative>(std::move(binder));
52+
LOG_ALWAYS_FATAL_IF(iface == nullptr, "%s failed unexpected interface", __func__);
53+
return iface;
54+
}
55+
3856
virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,
3957
audio_content_type_t content, const sp<IBinder>& player, audio_session_t sessionId) {
4058
Parcel data, reply;

0 commit comments

Comments
 (0)