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