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
diff --git a/services/oboeservice/AAudioServiceStreamBase.h b/services/oboeservice/AAudioServiceStreamBase.h
index c7df6f3..93a522e 100644
--- a/services/oboeservice/AAudioServiceStreamBase.h
+++ b/services/oboeservice/AAudioServiceStreamBase.h
@@ -27,6 +27,7 @@
#include "binding/AudioEndpointParcelable.h"
#include "binding/AAudioServiceMessage.h"
#include "utility/AAudioUtilities.h"
+#include <media/AudioClient.h>
#include "SharedRingBuffer.h"
#include "AAudioThread.h"
@@ -85,9 +86,19 @@
*/
virtual aaudio_result_t flush();
+ virtual aaudio_result_t startClient(const android::AudioClient& client __unused,
+ audio_port_handle_t *clientHandle __unused) {
+ return AAUDIO_ERROR_UNAVAILABLE;
+ }
+
+ virtual aaudio_result_t stopClient(audio_port_handle_t clientHandle __unused) {
+ return AAUDIO_ERROR_UNAVAILABLE;
+ }
+
bool isRunning() const {
return mState == AAUDIO_STREAM_STATE_STARTED;
}
+
// -------------------------------------------------------------------
/**
@@ -124,17 +135,11 @@
void disconnect();
uid_t getOwnerUserId() const {
- return mOwnerUserId;
- }
- void setOwnerUserId(uid_t uid) {
- mOwnerUserId = uid;
+ return mMmapClient.clientUid;
}
pid_t getOwnerProcessId() const {
- return mOwnerProcessId;
- }
- void setOwnerProcessId(pid_t pid) {
- mOwnerProcessId = pid;
+ return mMmapClient.clientPid;
}
aaudio_handle_t getHandle() const {
@@ -164,24 +169,25 @@
aaudio_stream_state_t mState = AAUDIO_STREAM_STATE_UNINITIALIZED;
- pid_t mRegisteredClientThread = ILLEGAL_THREAD_ID;
+ pid_t mRegisteredClientThread = ILLEGAL_THREAD_ID;
- SharedRingBuffer* mUpMessageQueue;
- std::mutex mLockUpMessageQueue;
+ SharedRingBuffer* mUpMessageQueue;
+ std::mutex mLockUpMessageQueue;
- AAudioThread mAAudioThread;
+ AAudioThread mAAudioThread;
// This is used by one thread to tell another thread to exit. So it must be atomic.
- std::atomic<bool> mThreadEnabled;
+ std::atomic<bool> mThreadEnabled;
- aaudio_format_t mAudioFormat = AAUDIO_FORMAT_UNSPECIFIED;
- int32_t mFramesPerBurst = 0;
- int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED;
- int32_t mSampleRate = AAUDIO_UNSPECIFIED;
- int32_t mCapacityInFrames = AAUDIO_UNSPECIFIED;
- uid_t mOwnerUserId = -1;
- pid_t mOwnerProcessId = -1;
+ aaudio_format_t mAudioFormat = AAUDIO_FORMAT_UNSPECIFIED;
+ int32_t mFramesPerBurst = 0;
+ int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED;
+ int32_t mSampleRate = AAUDIO_UNSPECIFIED;
+ int32_t mCapacityInFrames = AAUDIO_UNSPECIFIED;
+ android::AudioClient mMmapClient;
+ audio_port_handle_t mClientHandle = AUDIO_PORT_HANDLE_NONE;
+
private:
- aaudio_handle_t mHandle = -1;
+ aaudio_handle_t mHandle = -1;
};
} /* namespace aaudio */