1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ST_AUDIO_ADAPTER_MANAGER_H 17 #define ST_AUDIO_ADAPTER_MANAGER_H 18 19 #include <list> 20 #include <unordered_map> 21 #include <cinttypes> 22 23 #include "audio_adapter_manager_handler.h" 24 #include "audio_service_adapter.h" 25 #include "distributed_kv_data_manager.h" 26 #include "iaudio_policy_interface.h" 27 #include "types.h" 28 #include "audio_policy_log.h" 29 #include "audio_policy_server_handler.h" 30 #include "audio_volume_config.h" 31 #include "volume_data_maintainer.h" 32 #include "audio_utils.h" 33 #include "common/hdi_adapter_info.h" 34 #include "hdi_adapter_type.h" 35 #include "audio_device_manager.h" 36 #include "istandard_audio_service.h" 37 38 namespace OHOS { 39 namespace AudioStandard { 40 using namespace OHOS::DistributedKv; 41 42 class AudioOsAccountInfo; 43 44 struct AppConfigVolume { 45 int32_t defaultVolume; 46 int32_t maxVolume; 47 int32_t minVolume; 48 }; 49 50 const int32_t MAX_CACHE_AMOUNT = 10; 51 static constexpr int32_t MAX_VOLUME_DEGREE = 100; 52 class AudioAdapterManager : public IAudioPolicyInterface { 53 public: 54 static constexpr std::string_view SPLIT_STREAM_SINK = "libmodule-split-stream-sink.z.so"; 55 static constexpr std::string_view HDI_SINK = "libmodule-hdi-sink.z.so"; 56 static constexpr std::string_view HDI_SOURCE = "libmodule-hdi-source.z.so"; 57 static constexpr std::string_view PIPE_SINK = "libmodule-pipe-sink.z.so"; 58 static constexpr std::string_view PIPE_SOURCE = "libmodule-pipe-source.z.so"; 59 static constexpr std::string_view CLUSTER_SINK = "libmodule-cluster-sink.z.so"; 60 static constexpr std::string_view EFFECT_SINK = "libmodule-effect-sink.z.so"; 61 static constexpr std::string_view INNER_CAPTURER_SINK = "libmodule-inner-capturer-sink.z.so"; 62 static constexpr std::string_view RECEIVER_SINK = "libmodule-receiver-sink.z.so"; 63 static constexpr uint32_t KVSTORE_CONNECT_RETRY_COUNT = 5; 64 static constexpr uint32_t KVSTORE_CONNECT_RETRY_DELAY_TIME = 200000; 65 static constexpr float MIN_VOLUME = 0.0f; 66 static constexpr uint32_t NUMBER_TWO = 2; 67 static constexpr float HDI_MAX_SINK_VOLUME_LEVEL = 1.0f; 68 static constexpr uint32_t HDI_DEFAULT_MULTICHANNEL_CHANNELLAYOUT = 1551; 69 static constexpr uint32_t HDI_EC_SAME_ADAPTER = 1; 70 static constexpr std::string_view HDI_AUDIO_PORT_SINK_ROLE = "sink"; 71 static constexpr std::string_view HDI_AUDIO_PORT_SOURCE_ROLE = "source"; 72 bool Init(); 73 void Deinit(void); 74 void InitKVStore(); 75 bool ConnectServiceAdapter(); 76 GetInstance()77 static IAudioPolicyInterface& GetInstance() 78 { 79 static AudioAdapterManager audioAdapterManager; 80 return audioAdapterManager; 81 } 82 ~AudioAdapterManager()83 virtual ~AudioAdapterManager() {} 84 85 int32_t GetMaxVolumeLevel(AudioVolumeType volumeType, DeviceType deviceType = DEVICE_TYPE_NONE); 86 87 int32_t GetMinVolumeLevel(AudioVolumeType volumeType, DeviceType deviceType = DEVICE_TYPE_NONE); 88 89 int32_t SetSystemVolumeLevel(AudioStreamType streamType, int32_t volumeLevel); 90 91 int32_t SetAppVolumeLevel(int32_t appUid, int32_t volumeLevel); 92 93 int32_t SetAppVolumeMuted(int32_t appUid, bool muted); 94 95 int32_t SetAppVolumeMutedDB(int32_t appUid, bool muted); 96 97 int32_t IsAppVolumeMute(int32_t appUid, bool owned, bool &isMute); 98 99 int32_t SetAppRingMuted(int32_t appUid, bool muted); 100 101 bool IsAppRingMuted(int32_t appUid); 102 103 int32_t GetSystemVolumeLevel(AudioStreamType streamType); 104 105 int32_t GetAppVolumeLevel(int32_t appUid, int32_t &volumeLevel); 106 107 int32_t SetZoneVolumeLevel(int32_t zoneId, AudioStreamType streamType, int32_t volumeLevel); 108 109 int32_t GetZoneVolumeLevel(int32_t zoneId, AudioStreamType streamType); 110 111 int32_t SetZoneMute(int32_t zoneId, AudioStreamType streamType, bool mute, 112 StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, 113 const DeviceType &deviceType = DEVICE_TYPE_NONE); 114 115 bool GetZoneMute(int32_t zoneId, AudioStreamType streamType); 116 117 int32_t SetAdjustVolumeForZone(int32_t zoneId); 118 119 int32_t GetVolumeAdjustZoneId(); 120 121 int32_t GetSystemVolumeLevelNoMuteState(AudioStreamType streamType); 122 123 float GetSystemVolumeDb(AudioStreamType streamType); 124 125 int32_t SetStreamMute(AudioStreamType streamType, bool mute, StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, 126 const DeviceType &deviceType = DEVICE_TYPE_NONE, std::string networkId = LOCAL_NETWORK_ID); 127 128 int32_t SetInnerStreamMute(AudioStreamType streamType, bool mute, StreamUsage streamUsage = STREAM_USAGE_UNKNOWN); 129 130 int32_t SetSourceOutputStreamMute(int32_t uid, bool setMute); 131 132 bool GetStreamMute(AudioStreamType streamType); 133 134 bool GetAppMute(int32_t appUid); 135 136 std::vector<SinkInfo> GetAllSinks(); 137 138 void GetAllSinkInputs(std::vector<SinkInput> &sinkInputs); 139 140 std::vector<SourceOutput> GetAllSourceOutputs(); 141 142 AudioIOHandle OpenAudioPort(std::shared_ptr<AudioPipeInfo> pipeInfo, uint32_t &paIndex); 143 144 AudioIOHandle OpenAudioPort(const AudioModuleInfo &audioPortInfo, uint32_t &paIndex); 145 146 AudioIOHandle ReloadAudioPort(const AudioModuleInfo &audioPortInfo, uint32_t &paIndex); 147 148 int32_t CloseAudioPort(AudioIOHandle ioHandle, uint32_t paIndex = HDI_INVALID_ID); 149 150 int32_t SelectDevice(DeviceRole deviceRole, InternalDeviceType deviceType, std::string name); 151 152 int32_t SetDeviceActive(InternalDeviceType deviceType, std::string name, bool active, 153 DeviceFlag flag = ALL_DEVICES_FLAG); 154 155 void SetVolumeForSwitchDevice(AudioDeviceDescriptor deviceDescriptor); 156 157 int32_t MoveSinkInputByIndexOrName(uint32_t sinkInputId, uint32_t sinkIndex, std::string sinkName); 158 159 int32_t MoveSourceOutputByIndexOrName(uint32_t sourceOutputId, uint32_t sourceIndex, std::string sourceName); 160 161 int32_t SetRingerMode(AudioRingerMode ringerMode); 162 163 AudioRingerMode GetRingerMode(void) const; 164 165 int32_t SetAudioStreamRemovedCallback(AudioStreamRemovedCallback *callback); 166 167 int32_t SuspendAudioDevice(std::string &name, bool isSuspend); 168 169 bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false); 170 171 float CalculateVolumeDb(int32_t volumeLevel, int32_t maxDegree = MAX_VOLUME_LEVEL); 172 173 int32_t SetSystemSoundUri(const std::string &key, const std::string &uri); 174 175 std::string GetSystemSoundUri(const std::string &key); 176 177 float GetMinStreamVolume(void) const; 178 179 float GetMaxStreamVolume(void) const; 180 181 bool IsVolumeUnadjustable(); 182 183 float CalculateVolumeDbNonlinear(AudioStreamType streamType, DeviceType deviceType, int32_t volumeLevel); 184 185 void GetStreamVolumeInfoMap(StreamVolumeInfoMap &streamVolumeInfos); 186 187 DeviceVolumeType GetDeviceCategory(DeviceType deviceType); 188 189 void SetActiveDeviceDescriptor(AudioDeviceDescriptor deviceDescriptor); 190 191 DeviceType GetActiveDevice(); 192 193 DeviceCategory GetCurrentOutputDeviceCategory(); 194 195 AudioDeviceDescriptor GetActiveDeviceDescriptor(); 196 197 float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType); 198 IsUseNonlinearAlgo()199 bool IsUseNonlinearAlgo() { return useNonlinearAlgo_; } 200 201 void SetAbsVolumeScene(bool isAbsVolumeScene); 202 203 bool IsAbsVolumeScene() const; 204 205 void SetAbsVolumeMute(bool mute); 206 207 void SetDataShareReady(std::atomic<bool> isDataShareReady); 208 209 bool IsAbsVolumeMute() const; 210 211 std::string GetModuleArgs(const AudioModuleInfo &audioModuleInfo) const; 212 213 std::string GetHdiSinkIdInfo(const AudioModuleInfo &audioModuleInfo) const; 214 215 std::string GetSinkIdInfo(std::shared_ptr<AudioPipeInfo> pipeInfo) const; 216 217 std::string GetHdiSourceIdInfo(const AudioModuleInfo &audioModuleInfo) const; 218 219 IAudioSinkAttr GetAudioSinkAttr(const AudioModuleInfo &audioModuleInfo) const; 220 221 IAudioSourceAttr GetAudioSourceAttr(const AudioModuleInfo &audioModuleInfo) const; 222 223 void ResetRemoteCastDeviceVolume(); 224 225 void HandleDpConnection(); 226 227 void RefreshVolumeWhenDpReConnect(); 228 229 int32_t GetStreamVolume(AudioStreamType streamType); 230 231 void NotifyAccountsChanged(const int &id); 232 233 void SafeVolumeDump(std::string &dumpString); 234 235 int32_t DoRestoreData(); 236 SafeStatus GetCurrentDeviceSafeStatus(DeviceType deviceType); 237 238 int64_t GetCurentDeviceSafeTime(DeviceType deviceType); 239 240 int32_t SetDeviceSafeStatus(DeviceType deviceType, SafeStatus status); 241 242 int32_t SetDeviceSafeTime(DeviceType deviceType, int64_t time); 243 244 int32_t SetRestoreVolumeLevel(DeviceType deviceType, int32_t volume); 245 246 int32_t GetRestoreVolumeLevel(DeviceType deviceType); 247 248 int32_t GetSafeVolumeLevel() const; 249 250 int32_t GetSafeVolumeTimeout() const; 251 252 int32_t GetCurActivateCount(void) const; 253 254 void HandleKvData(bool isFirstBoot); 255 256 int32_t SetPersistMicMuteState(const bool isMute); 257 258 int32_t GetPersistMicMuteState(bool &isMute); 259 260 void HandleSaveVolume(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel, 261 std::string networkId); 262 263 void HandleSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, 264 int32_t volumeDegree, std::string networkId); 265 266 void HandleStreamMuteStatus(AudioStreamType streamType, bool mute, StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, 267 const DeviceType &deviceType = DEVICE_TYPE_NONE, std::string networkId = LOCAL_NETWORK_ID); 268 269 void HandleRingerMode(AudioRingerMode ringerMode); 270 271 void SetAudioServerProxy(sptr<IStandardAudioService> gsp); 272 273 void SetOffloadSessionId(uint32_t sessionId); 274 275 void ResetOffloadSessionId(); 276 277 int32_t SetDoubleRingVolumeDb(const AudioStreamType &streamType, const int32_t &volumeLevel); 278 279 void SaveRingerModeInfo(AudioRingerMode ringMode, std::string callerName, std::string invocationTime); 280 281 void GetRingerModeInfo(std::vector<RingerModeAdjustInfo> &ringerModeInfo); 282 283 std::shared_ptr<AllDeviceVolumeInfo> GetAllDeviceVolumeInfo(DeviceType deviceType, AudioStreamType streamType); 284 285 std::vector<AdjustStreamVolumeInfo> GetStreamVolumeInfo(AdjustStreamVolume volumeType); 286 287 int32_t GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray) const; 288 289 int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray) const; 290 291 int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray, 292 DeviceType deviceType = DEVICE_TYPE_NONE) const; 293 294 int32_t GetDeviceVolume(DeviceType deviceType, AudioStreamType streamType); 295 296 void UpdateSafeVolumeByS4(); 297 void SetVgsVolumeSupported(bool isVgsSupported); 298 bool IsVgsVolumeSupported() const; 299 300 int32_t SaveSpecifiedDeviceVolume(AudioStreamType streamType, int32_t volumeLevel, DeviceType deviceType); 301 int32_t UpdateCollaborativeState(bool isCollaborationEnabled); 302 void HandleDistributedVolume(AudioStreamType streamType); 303 void HandleHearingAidVolume(AudioStreamType streamType); 304 void RegisterDoNotDisturbStatus(); 305 void RegisterDoNotDisturbStatusWhiteList(); 306 int32_t SetQueryDeviceVolumeBehaviorCallback(const sptr<IRemoteObject> &object); 307 void HandleDistributedDeviceVolume(); 308 309 void SetSleVoiceStatusFlag(bool isSleVoiceStatus); 310 311 int32_t SetSystemVolumeDegree(AudioStreamType streamType, int32_t volumeDegree); 312 int32_t GetSystemVolumeDegree(AudioStreamType streamType); 313 int32_t GetMinVolumeDegree(AudioVolumeType volumeType); 314 private: 315 friend class PolicyCallbackImpl; 316 317 static constexpr int32_t MAX_VOLUME_LEVEL = 15; 318 static constexpr int32_t MIN_VOLUME_LEVEL = 0; 319 static constexpr int32_t DEFAULT_VOLUME_LEVEL = 7; 320 static constexpr int32_t DP_DEFAULT_VOLUME_LEVEL = 25; 321 static constexpr int32_t APP_MAX_VOLUME_LEVEL = 100; 322 static constexpr int32_t APP_MIN_VOLUME_LEVEL = 0; 323 static constexpr int32_t APP_DEFAULT_VOLUME_LEVEL = 25; 324 static constexpr int32_t CONST_FACTOR = 100; 325 static constexpr int32_t DEFAULT_SAFE_VOLUME_TIMEOUT = 1140; 326 static constexpr int32_t CONVERT_FROM_MS_TO_SECONDS = 1000; 327 static constexpr float MIN_STREAM_VOLUME = 0.0f; 328 static constexpr float MAX_STREAM_VOLUME = 1.0f; 329 330 struct UserData { 331 AudioAdapterManager *thiz; 332 AudioStreamType streamType; 333 float volume; 334 bool mute; 335 bool isCorked; 336 uint32_t idx; 337 }; 338 AudioAdapterManager()339 AudioAdapterManager() 340 : ringerMode_(RINGER_MODE_NORMAL), 341 audioPolicyKvStore_(nullptr), 342 audioPolicyServerHandler_(DelayedSingleton<AudioPolicyServerHandler>::GetInstance()), 343 audioDeviceManager_(AudioDeviceManager::GetAudioDeviceManager()), 344 volumeDataMaintainer_() 345 { 346 InitVolumeMapIndex(); 347 } 348 349 AudioStreamType GetStreamIDByType(std::string streamType); 350 int32_t ReInitKVStore(); 351 bool InitAudioPolicyKvStore(bool& isFirstBoot); 352 void InitVolumeMap(bool isFirstBoot); 353 bool LoadVolumeMap(void); 354 bool LoadVolumeMap(std::shared_ptr<AudioDeviceDescriptor> &device); 355 std::string GetVolumeKeyForKvStore(DeviceType deviceType, AudioStreamType streamType); 356 void InitRingerMode(bool isFirstBoot); 357 void InitMuteStatusMap(bool isFirstBoot); 358 bool LoadMuteStatusMap(void); 359 bool LoadMuteStatusMap(std::shared_ptr<AudioDeviceDescriptor> &device); 360 std::string GetMuteKeyForKvStore(DeviceType deviceType, AudioStreamType streamType); 361 std::string GetMuteKeyForDeviceType(DeviceType deviceType, std::string &type); 362 void InitSystemSoundUriMap(); 363 void InitVolumeMapIndex(); 364 void InitBootAnimationVolume(); 365 void UpdateVolumeMapIndex(); 366 void GetVolumePoints(AudioVolumeType streamType, DeviceVolumeType deviceType, 367 std::vector<VolumePoint> &volumePoints); 368 uint32_t GetPositionInVolumePoints(std::vector<VolumePoint> &volumePoints, int32_t idx); 369 void SaveRingtoneVolumeToLocal(AudioVolumeType volumeType, int32_t volumeLevel); 370 int32_t SetVolumeDb(AudioStreamType streamType); 371 int32_t SetVolumeDb(std::shared_ptr<AudioDeviceDescriptor> &device, AudioStreamType streamType); 372 int32_t SetAppVolumeDb(int32_t appUid); 373 void SetAudioVolume(AudioStreamType streamType, float volumeDb); 374 void SetAudioVolume(std::shared_ptr<AudioDeviceDescriptor> &device, AudioStreamType streamType, float volumeDb); 375 void SetAppAudioVolume(int32_t appUid, float volumeDb); 376 void SetAppAudioVolume(std::shared_ptr<AudioDeviceDescriptor> &device, int32_t appUid, float volumeDb); 377 void SetOffloadVolume(AudioStreamType streamType, float volumeDb, const std::string &deviceClass, 378 const std::string &networkId = LOCAL_NETWORK_ID); 379 int32_t SetStreamMute(std::shared_ptr<AudioDeviceDescriptor> &device, AudioStreamType streamType, 380 bool mute, StreamUsage streamUsage = STREAM_USAGE_UNKNOWN, 381 const DeviceType &deviceType = DEVICE_TYPE_NONE); 382 bool GetStreamMute(std::shared_ptr<AudioDeviceDescriptor> &device, AudioStreamType streamType); 383 int32_t GetStreamVolume(std::shared_ptr<AudioDeviceDescriptor> &device, AudioStreamType streamType); 384 bool GetStreamMuteInternal(AudioStreamType streamType); 385 bool GetStreamMuteInternal(std::shared_ptr<AudioDeviceDescriptor> &device, AudioStreamType streamType); 386 int32_t SetRingerModeInternal(AudioRingerMode ringerMode); 387 int32_t SetStreamMuteInternal(AudioStreamType streamType, bool mute, StreamUsage streamUsage, 388 const DeviceType &deviceType = DEVICE_TYPE_NONE, std::string networkId = LOCAL_NETWORK_ID); 389 int32_t SetStreamMuteInternal(std::shared_ptr<AudioDeviceDescriptor> &device, AudioStreamType streamType, bool mute, 390 StreamUsage streamUsage, const DeviceType &deviceType = DEVICE_TYPE_NONE); 391 int32_t GetDefaultVolumeLevel(std::unordered_map<AudioStreamType, int32_t> &volumeLevelMapTemp, 392 AudioVolumeType volumeType, DeviceType deviceType) const; 393 void InitKVStoreInternal(void); 394 void DeleteAudioPolicyKvStore(); 395 void TransferMuteStatus(void); 396 void CloneMuteStatusMap(void); 397 void CloneVolumeMap(void); 398 void CloneSystemSoundUrl(void); 399 void InitSafeStatus(bool isFirstBoot); 400 void InitSafeTime(bool isFirstBoot); 401 void ConvertSafeTime(void); 402 void UpdateSafeVolume(); 403 void UpdateUsbSafeVolume(); 404 void CheckAndDealMuteStatus(const DeviceType &deviceType, const AudioStreamType &streamType); 405 void SetVolumeCallbackAfterClone(); 406 void SetFirstBoot(bool isFirst); 407 void AdjustBluetoothVoiceAssistantVolume(InternalDeviceType deviceType, bool isA2dpSwitchToSco); 408 bool IsPaRoute(uint32_t routeFlag); 409 AudioIOHandle OpenPaAudioPort(std::shared_ptr<AudioPipeInfo> pipeInfo, uint32_t &paIndex, std::string moduleArgs); 410 AudioIOHandle OpenNotPaAudioPort(std::shared_ptr<AudioPipeInfo> pipeInfo, uint32_t &paIndex); 411 void GetSinkIdInfoAndIdType(std::shared_ptr<AudioPipeInfo> pipeInfo, std::string &idInfo, HdiIdType &idType); 412 void GetSourceIdInfoAndIdType(std::shared_ptr<AudioPipeInfo> pipeInfo, std::string &idInfo, HdiIdType &idType); 413 int32_t IsHandleStreamMute(AudioStreamType streamType, bool mute, StreamUsage streamUsage); 414 static void UpdateSinkArgs(const AudioModuleInfo &audioModuleInfo, std::string &args); 415 void UpdateVolumeForLowLatency(); 416 bool IsDistributedVolumeType(AudioStreamType streamType); 417 418 template<typename T> TransferTypeToByteArray(const T & t)419 std::vector<uint8_t> TransferTypeToByteArray(const T &t) 420 { 421 return std::vector<uint8_t>(reinterpret_cast<uint8_t *>(const_cast<T *>(&t)), 422 reinterpret_cast<uint8_t *>(const_cast<T *>(&t)) + sizeof(T)); 423 } 424 425 template<typename T> TransferByteArrayToType(const std::vector<uint8_t> & data)426 T TransferByteArrayToType(const std::vector<uint8_t> &data) 427 { 428 if (data.size() != sizeof(T) || data.size() == 0) { 429 constexpr int tSize = sizeof(T); 430 uint8_t tContent[tSize] = { 0 }; 431 return *reinterpret_cast<T *>(tContent); 432 } 433 return *reinterpret_cast<T *>(const_cast<uint8_t *>(&data[0])); 434 } 435 436 std::shared_ptr<AudioServiceAdapter> audioServiceAdapter_; 437 std::vector<AudioStreamType> defaultVolumeTypeList_; 438 std::unordered_map<AudioStreamType, int> minVolumeIndexMap_; 439 std::unordered_map<AudioStreamType, int> maxVolumeIndexMap_; 440 std::mutex systemSoundMutex_; 441 std::unordered_map<std::string, std::string> systemSoundUriMap_; 442 StreamVolumeInfoMap streamVolumeInfos_; 443 AudioDeviceDescriptor currentActiveDevice_; 444 AudioRingerMode ringerMode_ = RINGER_MODE_NORMAL; 445 int32_t safeVolume_ = 0; 446 SafeStatus safeStatus_ = SAFE_ACTIVE; 447 SafeStatus safeStatusBt_ = SAFE_ACTIVE; 448 int64_t safeActiveTime_ = 0; 449 int64_t safeActiveBtTime_ = 0; 450 int32_t safeVolumeTimeout_ = DEFAULT_SAFE_VOLUME_TIMEOUT; 451 int32_t safeActiveVolume_ = 0; 452 int32_t safeActiveBtVolume_ = 0; 453 bool isWiredBoot_ = true; 454 bool isBtBoot_ = true; 455 int32_t curActiveCount_ = 0; 456 int32_t volumeAdjustZoneId_ = 0; 457 bool isSafeBoot_ = true; 458 bool isVgsVolumeSupported_ = false; 459 std::shared_ptr<AudioAdapterManagerHandler> handler_ = nullptr; 460 461 std::shared_ptr<SingleKvStore> audioPolicyKvStore_; 462 std::shared_ptr<AudioPolicyServerHandler> audioPolicyServerHandler_; 463 AudioStreamRemovedCallback *sessionCallback_ = nullptr; 464 AudioDeviceManager &audioDeviceManager_; 465 VolumeDataMaintainer volumeDataMaintainer_; 466 std::unordered_map<std::string, std::shared_ptr<VolumeDataMaintainer>> volumeDataExtMaintainer_; 467 bool isVolumeUnadjustable_ = false; 468 bool testModeOn_ {false}; 469 std::atomic<float> getSystemVolumeInDb_ {0.0f}; 470 std::atomic<bool> isSleVoiceStatus_ {false}; 471 bool useNonlinearAlgo_ = false; 472 bool isAbsVolumeScene_ = false; 473 bool isAbsVolumeMute_ = false; 474 bool isNeedCopyVolumeData_ = false; 475 bool isNeedCopyMuteData_ = false; 476 bool isNeedCopyRingerModeData_ = false; 477 bool isNeedCopySystemUrlData_ = false; 478 bool isLoaded_ = false; 479 bool isAllCopyDone_ = false; 480 bool isNeedConvertSafeTime_ = false; 481 sptr<IStandardAudioService> audioServerProxy_ = nullptr; 482 std::optional<uint32_t> offloadSessionID_; 483 std::mutex audioVolumeMutex_; 484 std::mutex activeDeviceMutex_; 485 std::mutex volumeDataMapMutex_; 486 AppConfigVolume appConfigVolume_; 487 std::shared_ptr<FixedSizeList<RingerModeAdjustInfo>> saveRingerModeInfo_ = 488 std::make_shared<FixedSizeList<RingerModeAdjustInfo>>(MAX_CACHE_AMOUNT); 489 bool isDpReConnect_ = false; 490 sptr<IStandardAudioPolicyManagerListener> deviceVolumeBehaviorListener_; 491 }; 492 493 class PolicyCallbackImpl : public AudioServiceAdapterCallback { 494 public: PolicyCallbackImpl(AudioAdapterManager * audioAdapterManager)495 explicit PolicyCallbackImpl(AudioAdapterManager *audioAdapterManager) 496 { 497 audioAdapterManager_ = audioAdapterManager; 498 } 499 ~PolicyCallbackImpl()500 ~PolicyCallbackImpl() 501 { 502 AUDIO_WARNING_LOG("Destructor PolicyCallbackImpl"); 503 } 504 OnAudioStreamRemoved(const uint64_t sessionID)505 void OnAudioStreamRemoved(const uint64_t sessionID) 506 { 507 AUDIO_DEBUG_LOG("PolicyCallbackImpl OnAudioStreamRemoved: Session ID %{public}" PRIu64"", sessionID); 508 if (audioAdapterManager_->sessionCallback_ == nullptr) { 509 AUDIO_DEBUG_LOG("PolicyCallbackImpl audioAdapterManager_->sessionCallback_ == nullptr" 510 "not firing OnAudioStreamRemoved"); 511 } else { 512 audioAdapterManager_->sessionCallback_->OnAudioStreamRemoved(sessionID); 513 } 514 } 515 OnSetVolumeDbCb()516 void OnSetVolumeDbCb() 517 { 518 if (!isFirstBoot_) { 519 return; 520 } 521 isFirstBoot_ = false; 522 static const std::vector<AudioVolumeType> VOLUME_TYPE_LIST = { 523 STREAM_VOICE_CALL, 524 STREAM_RING, 525 STREAM_MUSIC, 526 STREAM_VOICE_ASSISTANT, 527 STREAM_ALARM, 528 STREAM_ACCESSIBILITY, 529 STREAM_ULTRASONIC, 530 STREAM_SYSTEM, 531 STREAM_VOICE_CALL_ASSISTANT, 532 STREAM_ALL 533 }; 534 for (auto &volumeType : VOLUME_TYPE_LIST) { 535 audioAdapterManager_->SetVolumeDb(volumeType); 536 } 537 } 538 539 private: 540 AudioAdapterManager *audioAdapterManager_; 541 bool isFirstBoot_ = true; 542 }; 543 } // namespace AudioStandard 544 } // namespace OHOS 545 #endif // ST_PULSEAUDIO_ADAPTER_MANAGER_H 546