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

Commit cb4dae21 authored by Eric Laurent's avatar Eric Laurent
Browse files

aaudio: indicate client UID and PID to audio flinger

Implement correct indication of client UID and PID to audio flinger
for AAudio MMAP streams in both exclusive mode and shared mode.
- Add start/stop client methods on MMAP streams used only when the MMAP
stream is in AAudio service and carries a mix of shared streams.
- Add "In Service'" indication from "client" side to AAudioServiceStreamMMAP
so that the behavior can be adapted accordingly.
- Modify logic on audio flinger side with regard to mmap tracks and
audio HAL stream activity:
  - use same audio session for all clients on a same stream to match
  audio policy logic to share same direct output stream for clients on same
  session. This is also more consistent with current volume and effect
  handling as all MMAP  clients sharing the same output stream have the
  same volume and use case.
  - start/stop the HAL when the stream is started/stopped with the initial client
  handle (returned when the stream is opened) but do not create a track.
  AAudioService implementation will always send an additional start command before
  first client starts and a stop command after last client stops,
  in both shared and exclusive mode.
  - start/stop a track only if the start/stop stream command is received
  with a handle different from the initial handle.
- Allow more than one active client from the same UID on a MMAP input in audio policy.

Bug: 62950008
Test: verify playback and capture in mmap mode
Merged-In: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
parent 0acb3209
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
../../media/libaudioclient/include/media/AudioClient.h
 No newline at end of file
+8 −11
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define ANDROID_AUDIO_MMAP_STREAM_INTERFACE_H

#include <system/audio.h>
#include <media/AudioClient.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>

@@ -37,12 +38,6 @@ class MmapStreamInterface : public virtual RefBase
        DIRECTION_INPUT,       /**< open a capture mmap stream */
    } stream_direction_t;

    class Client {
     public:
        uid_t clientUid;
        pid_t clientPid;
        String16 packageName;
    };
    /**
     * Open a playback or capture stream in MMAP mode at the audio HAL.
     *
@@ -53,13 +48,14 @@ class MmapStreamInterface : public virtual RefBase
     * \param[in,out] config audio parameters (sampling rate, format ...) for the stream.
     *                       Requested parameters as input,
     *                       Actual parameters as output
     * \param[in] client a Client struct describing the first client using this stream.
     * \param[in] client a AudioClient struct describing the first client using this stream.
     * \param[in,out] deviceId audio device the stream should preferably be routed to/from
     *                       Requested as input,
     *                       Actual as output
     * \param[in] callback the MmapStreamCallback interface used by AudioFlinger to notify
     *                     condition changes affecting the stream operation
     * \param[out] interface the MmapStreamInterface interface controlling the created stream
     * \param[out] same unique handle as the one used for the first client stream started.
     * \return OK if the stream was successfully created.
     *         NO_INIT if AudioFlinger is not properly initialized
     *         BAD_VALUE if the stream cannot be opened because of invalid arguments
@@ -68,10 +64,11 @@ class MmapStreamInterface : public virtual RefBase
    static status_t openMmapStream(stream_direction_t direction,
                                           const audio_attributes_t *attr,
                                           audio_config_base_t *config,
                                           const Client& client,
                                           const AudioClient& client,
                                           audio_port_handle_t *deviceId,
                                           const sp<MmapStreamCallback>& callback,
                                           sp<MmapStreamInterface>& interface);
                                           sp<MmapStreamInterface>& interface,
                                           audio_port_handle_t *handle);

    /**
     * Retrieve information on the mmap buffer used for audio samples transfer.
@@ -105,13 +102,13 @@ class MmapStreamInterface : public virtual RefBase
     * Start a stream operating in mmap mode.
     * createMmapBuffer() must be called before calling start()
     *
     * \param[in] client a Client struct describing the client starting on this stream.
     * \param[in] client a AudioClient struct describing the client starting on this stream.
     * \param[out] handle unique handle for this instance. Used with stop().
     * \return OK in case of success.
     *         NO_INIT in case of initialization error
     *         INVALID_OPERATION if called out of sequence
     */
    virtual status_t start(const Client& client, audio_port_handle_t *handle) = 0;
    virtual status_t start(const AudioClient& client, audio_port_handle_t *handle) = 0;

    /**
     * Stop a stream operating in mmap mode.
+11 −0
Original line number Diff line number Diff line
@@ -97,6 +97,17 @@ public:
    aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
                                                  pid_t clientThreadId) override;

    aaudio_result_t startClient(aaudio_handle_t streamHandle __unused,
                                      const android::AudioClient& client __unused,
                                      audio_port_handle_t *clientHandle) override {
        return AAUDIO_ERROR_UNAVAILABLE;
    }

    aaudio_result_t stopClient(aaudio_handle_t streamHandle __unused,
                               audio_port_handle_t clientHandle __unused)  override {
        return AAUDIO_ERROR_UNAVAILABLE;
    }

    void onStreamChange(aaudio_handle_t handle, int32_t opcode, int32_t value) {
        // TODO This is just a stub so we can have a client Binder to pass to the service.
        // TODO Implemented in a later CL.
+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define ANDROID_AAUDIO_BINDING_AAUDIO_SERVICE_INTERFACE_H

#include <utils/StrongPointer.h>
#include <media/AudioClient.h>

#include "binding/AAudioServiceDefinitions.h"
#include "binding/AAudioStreamRequest.h"
@@ -86,6 +87,13 @@ public:

    virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
                                                  pid_t clientThreadId) = 0;

    virtual aaudio_result_t startClient(aaudio_handle_t streamHandle,
                                      const android::AudioClient& client,
                                      audio_port_handle_t *clientHandle) = 0;

    virtual aaudio_result_t stopClient(aaudio_handle_t streamHandle,
                                       audio_port_handle_t clientHandle) = 0;
};

} /* namespace aaudio */
+10 −0
Original line number Diff line number Diff line
@@ -52,8 +52,12 @@ status_t AAudioStreamRequest::writeToParcel(Parcel* parcel) const {
    status = parcel->writeBool(mSharingModeMatchRequired);
    if (status != NO_ERROR) goto error;

    status = parcel->writeBool(mInService);
    if (status != NO_ERROR) goto error;

    status = mConfiguration.writeToParcel(parcel);
    if (status != NO_ERROR) goto error;

    return NO_ERROR;

error:
@@ -74,8 +78,12 @@ status_t AAudioStreamRequest::readFromParcel(const Parcel* parcel) {
    status = parcel->readBool(&mSharingModeMatchRequired);
    if (status != NO_ERROR) goto error;

    status = parcel->readBool(&mInService);
    if (status != NO_ERROR) goto error;

    status = mConfiguration.readFromParcel(parcel);
    if (status != NO_ERROR) goto error;

    return NO_ERROR;

error:
@@ -91,5 +99,7 @@ void AAudioStreamRequest::dump() const {
    ALOGD("AAudioStreamRequest mUserId    = %d", mUserId);
    ALOGD("AAudioStreamRequest mProcessId = %d", mProcessId);
    ALOGD("AAudioStreamRequest mDirection = %d", mDirection);
    ALOGD("AAudioStreamRequest mSharingModeMatchRequired = %d", mSharingModeMatchRequired);
    ALOGD("AAudioStreamRequest mInService = %d", mInService);
    mConfiguration.dump();
}
Loading