1 /* 2 * Copyright (c) 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_GROUP_MANAGER_H 17 #define ST_AUDIO_GROUP_MANAGER_H 18 19 #include <cstdlib> 20 #include <map> 21 #include <mutex> 22 #include <vector> 23 #include <unordered_map> 24 25 #include "parcel.h" 26 #include "audio_info.h" 27 28 namespace OHOS { 29 namespace AudioStandard { 30 class AudioRingerModeCallback { 31 public: 32 virtual ~AudioRingerModeCallback() = default; 33 /** 34 * Called when ringer mode is updated. 35 * 36 * @param ringerMode Indicates the updated ringer mode value. 37 * For details, refer RingerMode enum in audio_info.h 38 */ 39 virtual void OnRingerModeUpdated(const AudioRingerMode &ringerMode) = 0; 40 }; 41 42 class AudioManagerMicStateChangeCallback { 43 public: 44 virtual ~AudioManagerMicStateChangeCallback() = default; 45 /** 46 * Called when the microphone state changes 47 * 48 * @param micStateChangeEvent Microphone Status Information. 49 */ 50 virtual void OnMicStateUpdated(const MicStateChangeEvent &micStateChangeEvent) = 0; 51 }; 52 53 class AudioManagerAppVolumeChangeCallback { 54 public: 55 virtual ~AudioManagerAppVolumeChangeCallback() = default; 56 /** 57 * Called when the App volume changes 58 * 59 * @param event volume change Information. 60 */ 61 virtual void OnAppVolumeChangedForUid(int32_t appUid, const VolumeEvent &event) = 0; 62 /** 63 * Called when self App volume changes 64 * 65 * @param event volume change Information. 66 */ 67 virtual void OnSelfAppVolumeChanged(const VolumeEvent &event) = 0; 68 }; 69 70 class AudioManagerActiveVolumeTypeChangeCallback { 71 public: 72 virtual ~AudioManagerActiveVolumeTypeChangeCallback() = default; 73 /** 74 * Called when the active volume type changes 75 * 76 * @param event active volume type change Information. 77 */ 78 virtual void OnActiveVolumeTypeChanged(const AudioVolumeType &event) = 0; 79 }; 80 81 class AudioGroupManager { 82 public: 83 AudioGroupManager(int32_t groupId); 84 virtual ~AudioGroupManager(); 85 86 int32_t SetVolume(AudioVolumeType volumeType, int32_t volume, int32_t flag = 0, int32_t uid = 0); 87 AudioStreamType GetActiveVolumeType(const int32_t clientUid); 88 int32_t GetVolume(AudioVolumeType volumeType, int32_t uid = 0); 89 int32_t GetMaxVolume(AudioVolumeType volumeType); 90 int32_t GetMinVolume(AudioVolumeType volumeType); 91 int32_t SetMute(AudioVolumeType volumeType, bool mute, const DeviceType &deviceType = DEVICE_TYPE_NONE); 92 int32_t IsStreamMute(AudioVolumeType volumeType, bool &isMute); 93 int32_t Init(); 94 bool IsAlived(); 95 int32_t GetGroupId(); 96 int32_t SetRingerModeCallback(const int32_t clientId, 97 const std::shared_ptr<AudioRingerModeCallback> &callback); 98 int32_t UnsetRingerModeCallback(const int32_t clientId) const; 99 int32_t UnsetRingerModeCallback(const int32_t clientId, 100 const std::shared_ptr<AudioRingerModeCallback> &callback) const; 101 int32_t SetRingerMode(AudioRingerMode ringMode) const; 102 AudioRingerMode GetRingerMode() const; 103 int32_t SetMicrophoneMute(bool isMute); 104 int32_t SetMicrophoneMutePersistent(const bool isMute, const PolicyType type); 105 bool GetPersistentMicMuteState(); 106 bool IsMicrophoneMuteLegacy(); 107 bool IsMicrophoneMute(); 108 int32_t SetMicStateChangeCallback(const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback); 109 int32_t UnsetMicStateChangeCallback(const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback); 110 bool IsVolumeUnadjustable(); 111 int32_t AdjustVolumeByStep(VolumeAdjustType adjustType); 112 int32_t AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType); 113 float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType); 114 float GetMaxAmplitude(const int32_t deviceId); 115 int32_t SetVolumeDegree(AudioVolumeType volumeType, int32_t degree, int32_t flag = 0, int32_t uid = 0); 116 int32_t GetVolumeDegree(AudioVolumeType volumeType, int32_t uid = 0); 117 int32_t GetMinVolumeDegree(AudioVolumeType volumeType); 118 private: 119 int32_t groupId_; 120 ConnectType connectType_ = CONNECT_TYPE_LOCAL; 121 std::string netWorkId_ = LOCAL_NETWORK_ID; 122 int32_t cbClientId_ = -1; 123 static constexpr int32_t MAX_VOLUME_LEVEL = 15; 124 static constexpr int32_t MIN_VOLUME_LEVEL = 0; 125 static constexpr int32_t CONST_FACTOR = 100; 126 }; 127 } // namespace AudioStandard 128 } // namespace OHOS 129 #endif // ST_AUDIO_GROUP_MANAGER_H 130