audio: Fix after aosp/2908743 (exit command handling)
In aosp/2908743, the intended behavior of the "halReservedExit"
command (stream exit) was inadventedly changed. Instead of
exiting from the thread's loop only when the cookie has
the expected value, it was actually exiting when the cookie
value is any but zero. The intended behavior is as follows:
- the cookie has expected value: do not send reply, exit loop;
- the cookie has unexpected but non-zero value: ignore,
do not send reply (that's the point of using the cookie);
- the cookie has a zero value: ignore, send a reply (this is
for VTS testing).
Bug: 300181540
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I9945eb0ba9042993adac8599b18f241c4f69ca7a
diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp
index a70c12d..31b0645 100644
--- a/audio/aidl/default/Stream.cpp
+++ b/audio/aidl/default/Stream.cpp
@@ -183,17 +183,19 @@
switch (command.getTag()) {
case Tag::halReservedExit: {
const int32_t cookie = command.get<Tag::halReservedExit>();
+ StreamInWorkerLogic::Status status = Status::CONTINUE;
if (cookie == (mContext->getInternalCommandCookie() ^ getTid())) {
mDriver->shutdown();
setClosed();
+ status = Status::EXIT;
} else {
LOG(WARNING) << __func__ << ": EXIT command has a bad cookie: " << cookie;
}
if (cookie != 0) { // This is an internal command, no need to reply.
- return Status::EXIT;
- } else {
- break;
+ return status;
}
+ // `cookie == 0` can only occur in the context of a VTS test, need to reply.
+ break;
}
case Tag::getStatus:
populateReply(&reply, mIsConnected);
@@ -411,17 +413,19 @@
switch (command.getTag()) {
case Tag::halReservedExit: {
const int32_t cookie = command.get<Tag::halReservedExit>();
+ StreamOutWorkerLogic::Status status = Status::CONTINUE;
if (cookie == (mContext->getInternalCommandCookie() ^ getTid())) {
mDriver->shutdown();
setClosed();
+ status = Status::EXIT;
} else {
LOG(WARNING) << __func__ << ": EXIT command has a bad cookie: " << cookie;
}
if (cookie != 0) { // This is an internal command, no need to reply.
- return Status::EXIT;
- } else {
- break;
+ return status;
}
+ // `cookie == 0` can only occur in the context of a VTS test, need to reply.
+ break;
}
case Tag::getStatus:
populateReply(&reply, mIsConnected);