1 /* 2 * Copyright (c) 2023-2025 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 POLICY_HANDLER_H 17 #define POLICY_HANDLER_H 18 19 #include <sstream> 20 #include <map> 21 #include <mutex> 22 #include <vector> 23 24 #include "i_policy_provider_ipc.h" 25 26 namespace OHOS { 27 namespace AudioStandard { 28 class PolicyHandler { 29 public: 30 static PolicyHandler& GetInstance(); 31 32 ~PolicyHandler(); 33 34 void Dump(std::string &dumpString); 35 36 // would be called only once 37 bool ConfigPolicyProvider(const sptr<IPolicyProviderIpc> policyProvider); 38 39 bool GetProcessDeviceInfo(const AudioProcessConfig &config, bool lockFlag, AudioDeviceDescriptor &deviceInfo); 40 41 bool InitVolumeMap(); 42 43 bool GetSharedVolume(AudioVolumeType streamType, DeviceType deviceType, Volume &vol); 44 45 void SetActiveOutputDevice(DeviceType deviceType); 46 47 uint32_t GenerateSessionId(int32_t uid); 48 49 DeviceType GetActiveOutPutDevice(); 50 51 int32_t SetWakeUpAudioCapturerFromAudioServer(const AudioProcessConfig &config); 52 53 int32_t NotifyCapturerAdded(AudioCapturerInfo capturerInfo, AudioStreamInfo streamInfo, uint32_t sessionId); 54 55 int32_t NotifyWakeUpCapturerRemoved(); 56 57 bool IsAbsVolumeSupported(); 58 59 int32_t OffloadGetRenderPosition(uint32_t &delayValue, uint64_t &sendDataSize, uint32_t &timeStamp); 60 61 bool GetHighResolutionExist(); 62 63 void SetHighResolutionExist(bool isHighResExist); 64 65 int32_t GetAndSaveClientType(uint32_t uid, const std::string &bundleName); 66 67 int32_t GetMaxRendererInstances(); 68 69 int32_t ActivateConcurrencyFromServer(AudioPipeType incomingPipe); 70 71 int32_t NotifyCapturerRemoved(uint64_t sessionId); 72 73 int32_t SetDefaultOutputDevice(const DeviceType defaultOutputDevice, const uint32_t sessionID, 74 const StreamUsage streamUsage, bool isRunning); 75 #ifdef HAS_FEATURE_INNERCAPTURER 76 int32_t LoadModernInnerCapSink(int32_t innerCapId); 77 78 int32_t UnloadModernInnerCapSink(int32_t innerCapId); 79 #endif 80 private: 81 PolicyHandler(); 82 sptr<IPolicyProviderIpc> iPolicyProvider_ = nullptr; 83 84 private: 85 std::shared_ptr<AudioSharedMemory> policyVolumeMap_ = nullptr; 86 volatile Volume *volumeVector_ = nullptr; 87 volatile bool *sharedAbsVolumeScene_ = nullptr; 88 DeviceType deviceType_ = DEVICE_TYPE_SPEAKER; 89 bool isHighResolutionExist_ = false; 90 }; 91 } // namespace AudioStandard 92 } // namespace OHOS 93 #endif // POLICY_HANDLER_H 94