From 6a5748a02ed43486b47c48128dee1775ebb92126 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Mon, 13 May 2024 16:38:11 -0700 Subject: [PATCH] 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 --- audio/aidl/default/Stream.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/audio/aidl/default/Stream.cpp b/audio/aidl/default/Stream.cpp index a70c12d57d..31b064590d 100644 --- a/audio/aidl/default/Stream.cpp +++ b/audio/aidl/default/Stream.cpp @@ -183,17 +183,19 @@ StreamInWorkerLogic::Status StreamInWorkerLogic::cycle() { switch (command.getTag()) { case Tag::halReservedExit: { const int32_t cookie = command.get(); + 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 @@ StreamOutWorkerLogic::Status StreamOutWorkerLogic::cycle() { switch (command.getTag()) { case Tag::halReservedExit: { const int32_t cookie = command.get(); + 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);