diff --git a/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h b/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h index ba8364bc851c67748651ec9c70f36caf9967c3a4..717a3439fdc9b6f45a10d4082a1b37a35a29027d 100644 --- a/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h +++ b/services/audio_policy/server/domain/volume/include/volume_data_maintainer.h @@ -100,6 +100,8 @@ public: int32_t GetDeviceVolume(DeviceType deviceType, AudioStreamType streamType); int32_t GetAppVolume(int32_t appUid); bool IsSetAppVolume(int32_t appUid); + void CopyVolumeLevelAndMuteStatusMap; + void CopyVolumeLevelAndMuteStatusMap other>; std::unordered_map GetVolumeMap(); bool GetMuteStatusWithDatabaseVolumeName(const std::string &databaseVolumeName, AudioStreamType streamType); diff --git a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp index a2fc2581c7f3dc856d5bde1897011d3a3698bc9a..9a5220db19d1fa3ba987eac97f3702e4548f2561 100644 --- a/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp +++ b/services/audio_policy/server/domain/volume/src/audio_adapter_manager.cpp @@ -484,7 +484,10 @@ int32_t AudioAdapterManager::SetAdjustVolumeForZone(int32_t zoneId) "zone device error"); if (volumeDataExtMaintainer_.find(devices[0]->GetKey()) == volumeDataExtMaintainer_.end()) { volumeDataExtMaintainer_[devices[0]->GetKey()] = std::make_shared(); - if (devices[0]->IsDistributedSpeaker()) { + if (devices[0]->deviceType_ == currentActiveDevice_.deviceType_ && + devices[0]->networkId_ == currentActiveDevice_.networkId_) { + volumeDataExtMaintainer_[devices[0]->GetKey()]->CopyVolumeLevelAndMuteStatusMap(volumeDataMaintainer_); + } else if (devices[0]->IsDistributedSpeaker()) { for (auto streamType : DISTRIBUTED_VOLUME_TYPE_LIST) { int32_t maxVolumeLevel = GetMaxVolumeLevel(streamType); volumeDataExtMaintainer_[devices[0]->GetKey()]->SetStreamVolume(streamType, maxVolumeLevel); @@ -494,12 +497,17 @@ int32_t AudioAdapterManager::SetAdjustVolumeForZone(int32_t zoneId) LoadMuteStatusMap(devices[0]); LoadVolumeMap(devices[0]); } - auto iter = defaultVolumeTypeList_.begin(); - while (iter != defaultVolumeTypeList_.end()) { - SetVolumeDb(devices[0], *iter); - iter++; + } else { + if (devices[0]->deviceType_ == currentActiveDevice_.deviceType_ && + devices[0]->networkId_ == currentActiveDevice_.networkId_) { + volumeDataExtMaintainer_[devices[0]->GetKey()]->CopyVolumeLevelAndMuteStatusMap(volumeDataMaintainer_); } } + auto iter = defaultVolumeTypeList_.begin(); + while (iter != defaultVolumeTypeList_.end()) { + SetVolumeDb(devices[0], *iter); + iter++; + } return SUCCESS; } @@ -611,6 +619,9 @@ int32_t AudioAdapterManager::SetSystemVolumeLevel(AudioStreamType streamType, in // Save the volume to volumeLevelMap_. volumeDataMaintainer_.SetStreamVolume(streamType, volumeLevel); + if (volumeDataExtMaintainer_.find(currentActiveDevice_.GetKey()) != volumeDataExtMaintainer.end()) { + volumeDataExtMaintainer_[currentActiveDevice_.GetKey()]->SetStreamVolume(streamType, volumeLevel); + } // Save the volume to settingsdata. if (currentActiveDevice_.volumeBehavior_.databaseVolumeName != "" && IsDistributedVolumeType(streamType)) { volumeDataMaintainer_.SaveVolumeWithDatabaseVolumeName( @@ -1312,6 +1323,9 @@ void AudioAdapterManager::SetVolumeForSwitchDevice(AudioDeviceDescriptor deviceD return; } } + if (volumeDataExtMaintainer_.find(currentActiveDevice_.GetKey()) != volumeDataExtMaintainer.end()) { + volumeDataMaintainer_.CopyVolumeLevelAndMuteStatusMap(volumeDataExtMaintainer_[currentActiveDevice_.GetKey()]); + } // The same device does not set the volume bool isSameVolumeGroup = ((GetVolumeGroupForDevice(currentActiveDevice_.deviceType_) == GetVolumeGroupForDevice(deviceDescriptor.deviceType_)) && diff --git a/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp b/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp index 5fdfb68aa66c7ce192f8f433da563fd74c33207c..5c529966040f0f083bde0384c779ddfae3c3985e 100644 --- a/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp +++ b/services/audio_policy/server/domain/volume/src/volume_data_maintainer.cpp @@ -468,6 +468,19 @@ int32_t VolumeDataMaintainer::GetAppVolume(int32_t appUid) return appVolumeLevelMap_[appUid]; } +void VolumeDataMaintainer::CopyVolumeLevelAndMuteStatusMap +{ + std::lock_guard lock(volumeMutex_); + volumeLevelMap_ = other.volumeLevelMap_; + muteStatusMap_ = other.muteStatusMap_; +} + +void VolumeDataMaintainer::CopyVolumeLevelAndMuteStatusMap other> +{ + std::lock_guard lock(volumeMutex_); + volumeLevelMap_ = other->volumeLevelMap_; + muteStatusMap_ = other->muteStatusMap_; +} int32_t VolumeDataMaintainer::GetStreamVolumeInternal(AudioStreamType streamType) {