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
Change-Id: I86151bbb637ff172d2fd5f813056eab13a7bcd3c
diff --git a/include/media/MmapStreamInterface.h b/include/media/MmapStreamInterface.h
index 7dbc19e..d689e25 100644
--- a/include/media/MmapStreamInterface.h
+++ b/include/media/MmapStreamInterface.h
@@ -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 @@
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 @@
* \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 @@
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 @@
* 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.