Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cdf8ea87 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[audio] Add AudioManager getNativeInterface" into main

parents ad554215 5eb83603
Loading
Loading
Loading
Loading
+14 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#ifndef ANDROID_IAUDIOMANAGER_H
#define ANDROID_IAUDIOMANAGER_H

#include <android/media/IAudioManagerNative.h>
#include <audiomanager/AudioManager.h>
#include <utils/Errors.h>
#include <binder/IInterface.h>
@@ -34,20 +35,23 @@ public:
    // These transaction IDs must be kept in sync with the method order from
    // IAudioService.aidl.
    enum {
        TRACK_PLAYER                          = IBinder::FIRST_CALL_TRANSACTION,
        PLAYER_ATTRIBUTES                     = IBinder::FIRST_CALL_TRANSACTION + 1,
        PLAYER_EVENT                          = IBinder::FIRST_CALL_TRANSACTION + 2,
        RELEASE_PLAYER                        = IBinder::FIRST_CALL_TRANSACTION + 3,
        TRACK_RECORDER                        = IBinder::FIRST_CALL_TRANSACTION + 4,
        RECORDER_EVENT                        = IBinder::FIRST_CALL_TRANSACTION + 5,
        RELEASE_RECORDER                      = IBinder::FIRST_CALL_TRANSACTION + 6,
        PLAYER_SESSION_ID                     = IBinder::FIRST_CALL_TRANSACTION + 7,
        PORT_EVENT                            = IBinder::FIRST_CALL_TRANSACTION + 8,
        PERMISSION_UPDATE_BARRIER             = IBinder::FIRST_CALL_TRANSACTION + 9,
        GET_NATIVE_INTERFACE                  = IBinder::FIRST_CALL_TRANSACTION,
        TRACK_PLAYER                          = IBinder::FIRST_CALL_TRANSACTION + 1,
        PLAYER_ATTRIBUTES                     = IBinder::FIRST_CALL_TRANSACTION + 2,
        PLAYER_EVENT                          = IBinder::FIRST_CALL_TRANSACTION + 3,
        RELEASE_PLAYER                        = IBinder::FIRST_CALL_TRANSACTION + 4,
        TRACK_RECORDER                        = IBinder::FIRST_CALL_TRANSACTION + 5,
        RECORDER_EVENT                        = IBinder::FIRST_CALL_TRANSACTION + 6,
        RELEASE_RECORDER                      = IBinder::FIRST_CALL_TRANSACTION + 7,
        PLAYER_SESSION_ID                     = IBinder::FIRST_CALL_TRANSACTION + 8,
        PORT_EVENT                            = IBinder::FIRST_CALL_TRANSACTION + 9,
        PERMISSION_UPDATE_BARRIER             = IBinder::FIRST_CALL_TRANSACTION + 10,
    };

    DECLARE_META_INTERFACE(AudioManager)

    virtual sp<media::IAudioManagerNative> getNativeInterface() = 0;

    // The parcels created by these methods must be kept in sync with the
    // corresponding methods from IAudioService.aidl and objects it imports.
    virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,
+1 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ cc_library {
    ],

    shared_libs: [
        "av-types-aidl-cpp",
        "libutils",
        "libbinder",
        "liblog",
+18 −0
Original line number Diff line number Diff line
@@ -35,6 +35,24 @@ public:
    {
    }

    // This should never fail
    virtual sp<media::IAudioManagerNative> getNativeInterface() {
        Parcel data, reply;
        data.writeInterfaceToken(IAudioManager::getInterfaceDescriptor());
        const status_t res = remote()->transact(GET_NATIVE_INTERFACE, data, &reply, 0);
        LOG_ALWAYS_FATAL_IF(res != OK, "%s failed with result %d", __func__, res);
        const int ex = reply.readExceptionCode();
        LOG_ALWAYS_FATAL_IF(ex != binder::Status::EX_NONE, "%s failed with exception %d",
                            __func__,
                            ex);
        sp<IBinder> binder;
        const status_t err = reply.readNullableStrongBinder(&binder);
        LOG_ALWAYS_FATAL_IF(binder == nullptr, "%s failed unexpected nullptr %d", __func__, err);
        const auto iface = checked_interface_cast<media::IAudioManagerNative>(std::move(binder));
        LOG_ALWAYS_FATAL_IF(iface == nullptr, "%s failed unexpected interface", __func__);
        return iface;
    }

    virtual audio_unique_id_t trackPlayer(player_type_t playerType, audio_usage_t usage,
            audio_content_type_t content, const sp<IBinder>& player, audio_session_t sessionId) {
        Parcel data, reply;