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 AudioGroupManager {
54 public:
55     AudioGroupManager(int32_t groupId);
56     virtual ~AudioGroupManager();
57 
58     int32_t SetVolume(AudioVolumeType volumeType, int32_t volume, int32_t flag = 0);
59     AudioStreamType GetActiveVolumeType(const int32_t clientUid);
60     int32_t GetVolume(AudioVolumeType volumeType);
61     int32_t GetMaxVolume(AudioVolumeType volumeType);
62     int32_t GetMinVolume(AudioVolumeType volumeType);
63     int32_t SetMute(AudioVolumeType volumeType, bool mute);
64     int32_t IsStreamMute(AudioVolumeType volumeType, bool &isMute);
65     int32_t Init();
66     bool IsAlived();
67     int32_t GetGroupId();
68     int32_t SetRingerModeCallback(const int32_t clientId,
69         const std::shared_ptr<AudioRingerModeCallback> &callback);
70     int32_t UnsetRingerModeCallback(const int32_t clientId) const;
71     int32_t UnsetRingerModeCallback(const int32_t clientId,
72         const std::shared_ptr<AudioRingerModeCallback> &callback) const;
73     int32_t SetRingerMode(AudioRingerMode ringMode) const;
74     AudioRingerMode GetRingerMode() const;
75     int32_t SetMicrophoneMute(bool isMute);
76     int32_t SetMicrophoneMutePersistent(const bool isMute, const PolicyType type);
77     bool GetPersistentMicMuteState();
78     bool IsMicrophoneMuteLegacy();
79     bool IsMicrophoneMute();
80     int32_t SetMicStateChangeCallback(const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback);
81     int32_t UnsetMicStateChangeCallback(const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback);
82     bool IsVolumeUnadjustable();
83     int32_t AdjustVolumeByStep(VolumeAdjustType adjustType);
84     int32_t AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType);
85     float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType);
86     float GetMaxAmplitude(const int32_t deviceId);
87 private:
88     int32_t groupId_;
89     ConnectType connectType_ = CONNECT_TYPE_LOCAL;
90     std::string netWorkId_ = LOCAL_NETWORK_ID;
91     int32_t cbClientId_ = -1;
92     static constexpr int32_t MAX_VOLUME_LEVEL = 15;
93     static constexpr int32_t MIN_VOLUME_LEVEL = 0;
94     static constexpr int32_t CONST_FACTOR = 100;
95 };
96 } // namespace AudioStandard
97 } // namespace OHOS
98 #endif // ST_AUDIO_GROUP_MANAGER_H
99