No need to consider invalid tracks when checking if all active tracks are rerouted.
When a track is invalid, it will be removed later. In that case, there
is no need to consider such tracks when checking if all active tracks
will be rerouted.
Bug: 175343099
Test: connect/disconnect BT when playing music
Change-Id: I074b861af1f59affaf21b4ae5614512265464e1d
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
index 18cf0c1..fb7015b 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioOutputDescriptor.h
@@ -437,6 +437,8 @@
uint32_t getRecommendedMuteDurationMs() const override;
+ void setTracksInvalidatedStatusByStrategy(product_strategy_t strategy);
+
const sp<IOProfile> mProfile; // I/O profile this output derives from
audio_io_handle_t mIoHandle; // output handle
uint32_t mLatency; //
diff --git a/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h b/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h
index dc2403c..28c59db 100644
--- a/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h
+++ b/services/audiopolicy/common/managerdefinitions/include/ClientDescriptor.h
@@ -143,6 +143,14 @@
}
uint32_t getActivityCount() const { return mActivityCount; }
+ bool isInvalid() const {
+ return mIsInvalid;
+ }
+
+ void setIsInvalid() {
+ mIsInvalid = true;
+ }
+
private:
const audio_stream_type_t mStream;
const product_strategy_t mStrategy;
@@ -155,6 +163,7 @@
* involved in a duplication.
*/
uint32_t mActivityCount = 0;
+ bool mIsInvalid = false;
};
class RecordClientDescriptor: public ClientDescriptor
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
index 5c342a1..009fa82 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioOutputDescriptor.cpp
@@ -726,6 +726,14 @@
return mProfile->recommendedMuteDurationMs;
}
+void SwAudioOutputDescriptor::setTracksInvalidatedStatusByStrategy(product_strategy_t strategy) {
+ for (const auto &client : getClientIterable()) {
+ if (strategy == client->strategy()) {
+ client->setIsInvalid();
+ }
+ }
+}
+
// HwAudioOutputDescriptor implementation
HwAudioOutputDescriptor::HwAudioOutputDescriptor(const sp<SourceClientDescriptor>& source,
AudioPolicyClientInterface *clientInterface)
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index c3c9753..776cc0e 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -6188,6 +6188,12 @@
for (auto stream : mEngine->getStreamTypesForProductStrategy(psId)) {
mpClientInterface->invalidateStream(stream);
}
+ for (audio_io_handle_t srcOut : srcOutputs) {
+ sp<SwAudioOutputDescriptor> desc = mPreviousOutputs.valueFor(srcOut);
+ if (desc == nullptr) continue;
+
+ desc->setTracksInvalidatedStatusByStrategy(psId);
+ }
}
}
}
@@ -7509,7 +7515,10 @@
routedDevices.add(device);
}
for (const auto& client : activeClients) {
- // TODO: b/175343099 only travel the valid client
+ if (client->isInvalid()) {
+ // No need to take care about invalidated clients.
+ continue;
+ }
sp<DeviceDescriptor> preferredDevice =
mAvailableOutputDevices.getDeviceFromId(client->preferredDeviceId());
if (mEngine->getOutputDevicesForAttributes(