AAudio: do not call to aaudio service when the binder has dead.
When aaudio service has dead, the client should not call to service as
its stream handle may be reassigned to a new stream. Instead, when there
is binder death, the stream should be in disconnected state, there
should be an error callback fired.
In AAudioBinderAdapter, it takes a service lifetime id as a reference to
current aaudio service. When there is binder death, the service id will
be increased by 1. When AAudioBinderAdapter finds the service id provided
by the client is different from its own service id, it should reject the
request.
When a MMAP stream is open, it receives a service lifetime id to
recognize the service that it connects to. When processing data, the
client will return AAUDIO_ERROR_DISCONNECTED if current service lifetime
id is different from the one it cached.
Bug: 269531552
Test: repo steps in the bug
Test: atest AAudioTests
Test: oboeservice_fuzzer
Change-Id: Ieddd89fa2e23ad56d34a7fbccb8fb9a70917330e
diff --git a/media/libaaudio/src/binding/AAudioServiceInterface.h b/media/libaaudio/src/binding/AAudioServiceInterface.h
index e901767..79f498b 100644
--- a/media/libaaudio/src/binding/AAudioServiceInterface.h
+++ b/media/libaaudio/src/binding/AAudioServiceInterface.h
@@ -45,55 +45,58 @@
/**
* @param request info needed to create the stream
* @param configuration contains information about the created stream
- * @return handle to the stream or a negative error
+ * @return an object for aaudio handle information, which includes the connected
+ * aaudio service lifetime id to recognize the connected aaudio service
+ * and aaudio handle to recognize the stream. If an error occurs, the
+ * aaudio handle will be set as the negative error.
*/
- virtual aaudio_handle_t openStream(const AAudioStreamRequest &request,
- AAudioStreamConfiguration &configuration) = 0;
+ virtual AAudioHandleInfo openStream(const AAudioStreamRequest &request,
+ AAudioStreamConfiguration &configuration) = 0;
- virtual aaudio_result_t closeStream(aaudio_handle_t streamHandle) = 0;
+ virtual aaudio_result_t closeStream(const AAudioHandleInfo& streamHandleInfo) = 0;
/* Get an immutable description of the in-memory queues
* used to communicate with the underlying HAL or Service.
*/
- virtual aaudio_result_t getStreamDescription(aaudio_handle_t streamHandle,
+ virtual aaudio_result_t getStreamDescription(const AAudioHandleInfo& streamHandleInfo,
AudioEndpointParcelable &parcelable) = 0;
/**
* Start the flow of data.
*/
- virtual aaudio_result_t startStream(aaudio_handle_t streamHandle) = 0;
+ virtual aaudio_result_t startStream(const AAudioHandleInfo& streamHandleInfo) = 0;
/**
* Stop the flow of data such that start() can resume without loss of data.
*/
- virtual aaudio_result_t pauseStream(aaudio_handle_t streamHandle) = 0;
+ virtual aaudio_result_t pauseStream(const AAudioHandleInfo& streamHandleInfo) = 0;
/**
- * Stop the flow of data after data currently inthe buffer has played.
+ * Stop the flow of data after data currently in the buffer has played.
*/
- virtual aaudio_result_t stopStream(aaudio_handle_t streamHandle) = 0;
+ virtual aaudio_result_t stopStream(const AAudioHandleInfo& streamHandleInfo) = 0;
/**
* Discard any data held by the underlying HAL or Service.
*/
- virtual aaudio_result_t flushStream(aaudio_handle_t streamHandle) = 0;
+ virtual aaudio_result_t flushStream(const AAudioHandleInfo& streamHandleInfo) = 0;
/**
* Manage the specified thread as a low latency audio thread.
*/
- virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
+ virtual aaudio_result_t registerAudioThread(const AAudioHandleInfo& streamHandleInfo,
pid_t clientThreadId,
int64_t periodNanoseconds) = 0;
- virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
+ virtual aaudio_result_t unregisterAudioThread(const AAudioHandleInfo& streamHandleInfo,
pid_t clientThreadId) = 0;
- virtual aaudio_result_t startClient(aaudio_handle_t streamHandle,
+ virtual aaudio_result_t startClient(const AAudioHandleInfo& streamHandleInfo,
const android::AudioClient& client,
const audio_attributes_t *attr,
audio_port_handle_t *clientHandle) = 0;
- virtual aaudio_result_t stopClient(aaudio_handle_t streamHandle,
+ virtual aaudio_result_t stopClient(const AAudioHandleInfo& streamHandleInfo,
audio_port_handle_t clientHandle) = 0;
/**
@@ -103,7 +106,7 @@
* @param parcelable contains new data queue information
* @return the result of the execution
*/
- virtual aaudio_result_t exitStandby(aaudio_handle_t streamHandle,
+ virtual aaudio_result_t exitStandby(const AAudioHandleInfo& streamHandleInfo,
AudioEndpointParcelable &parcelable) = 0;
};