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 I_AUDIO_POLICY_INTERFACE_H
17 #define I_AUDIO_POLICY_INTERFACE_H
18 
19 #include "audio_adapter_info.h"
20 #include "audio_info.h"
21 #include "audio_policy_manager.h"
22 #include "audio_policy_ipc_interface_code.h"
23 #include "audio_stream_removed_callback.h"
24 #include "audio_volume_config.h"
25 #include "volume_data_maintainer.h"
26 #include "audio_manager_base.h"
27 
28 #include <memory>
29 #include <string>
30 
31 namespace OHOS {
32 namespace AudioStandard {
33 class IAudioPolicyInterface {
34 public:
~IAudioPolicyInterface()35     virtual ~IAudioPolicyInterface() {}
36 
37     virtual bool Init() = 0;
38 
39     virtual void Deinit(void) = 0;
40 
41     virtual void InitKVStore() = 0;
42 
43     virtual bool ConnectServiceAdapter() = 0;
44 
45     virtual int32_t GetMaxVolumeLevel(AudioVolumeType volumeType) = 0;
46 
47     virtual int32_t GetMinVolumeLevel(AudioVolumeType volumeType) = 0;
48 
49     virtual int32_t SetSystemVolumeLevel(AudioStreamType streamType, int32_t volumeLevel) = 0;
50 
51     virtual int32_t GetSystemVolumeLevel(AudioStreamType streamType) = 0;
52 
53     virtual int32_t GetSystemVolumeLevelNoMuteState(AudioStreamType streamType) = 0;
54 
55     virtual float GetSystemVolumeDb(AudioStreamType streamType) = 0;
56 
57     virtual int32_t SetStreamMute(AudioStreamType streamType, bool mute,
58         StreamUsage streamUsage = STREAM_USAGE_UNKNOWN) = 0;
59 
60     virtual int32_t SetSourceOutputStreamMute(int32_t uid, bool setMute) = 0;
61 
62     virtual bool GetStreamMute(AudioStreamType streamType) = 0;
63 
64     virtual std::vector<SinkInfo> GetAllSinks() = 0;
65 
66     virtual std::vector<SinkInput> GetAllSinkInputs() = 0;
67 
68     virtual std::vector<SourceOutput> GetAllSourceOutputs() = 0;
69 
70     virtual AudioIOHandle OpenAudioPort(const AudioModuleInfo &audioPortInfo) = 0;
71 
72     virtual int32_t CloseAudioPort(AudioIOHandle ioHandle) = 0;
73 
74     virtual int32_t SelectDevice(DeviceRole deviceRole, InternalDeviceType deviceType, std::string name);
75 
76     virtual int32_t SetDeviceActive(InternalDeviceType deviceType,
77                                     std::string name, bool active, DeviceFlag flag = ALL_DEVICES_FLAG) = 0;
78 
79     virtual int32_t MoveSinkInputByIndexOrName(uint32_t sinkInputId, uint32_t sinkIndex, std::string sinkName) = 0;
80 
81     virtual int32_t MoveSourceOutputByIndexOrName(uint32_t sourceOutputId,
82         uint32_t sourceIndex, std::string sourceName) = 0;
83 
84     virtual int32_t SetRingerMode(AudioRingerMode ringerMode) = 0;
85 
86     virtual AudioRingerMode GetRingerMode() const = 0;
87 
88     virtual int32_t SetAudioStreamRemovedCallback(AudioStreamRemovedCallback *callback) = 0;
89 
90     virtual int32_t SuspendAudioDevice(std::string &name, bool isSuspend) = 0;
91 
92     virtual void SetVolumeForSwitchDevice(InternalDeviceType deviceType) = 0;
93 
94     virtual bool SetSinkMute(const std::string &sinkName, bool isMute, bool isSync = false) = 0;
95 
96     virtual float CalculateVolumeDb(int32_t volumeLevel) = 0;
97 
98     virtual int32_t SetSystemSoundUri(const std::string &key, const std::string &uri) = 0;
99 
100     virtual std::string GetSystemSoundUri(const std::string &key) = 0;
101 
102     virtual float GetMinStreamVolume() const = 0;
103 
104     virtual float GetMaxStreamVolume() const = 0;
105 
106     virtual bool IsVolumeUnadjustable() = 0;
107 
108     virtual void GetStreamVolumeInfoMap(StreamVolumeInfoMap &streamVolumeInfos);
109 
110     virtual void SetAbsVolumeScene(bool isAbsVolumeScene) = 0;
111 
112     virtual bool IsAbsVolumeScene() const = 0;
113 
114     virtual void SetAbsVolumeMute(bool mute) = 0;
115 
116     virtual void SetDataShareReady(std::atomic<bool> isDataShareReady) = 0;
117 
118     virtual bool IsAbsVolumeMute() const = 0;
119 
120     virtual void SetVgsVolumeSupported(bool isVgsVolumeSupported) = 0;
121 
122     virtual bool IsVgsVolumeSupported() const = 0;
123 
124     virtual float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType) = 0;
125 
126     virtual void SetActiveDevice(DeviceType deviceType) = 0;
127 
128     virtual DeviceType GetActiveDevice() = 0;
129 
130     virtual std::string GetModuleArgs(const AudioModuleInfo &audioModuleInfo) const = 0;
131 
132     virtual void ResetRemoteCastDeviceVolume();
133 
134     virtual int32_t DoRestoreData() = 0;
135 
136     virtual SafeStatus GetCurrentDeviceSafeStatus(DeviceType deviceType) = 0;
137 
138     virtual int64_t GetCurentDeviceSafeTime(DeviceType deviceType) = 0;
139 
140     virtual int32_t SetDeviceSafeStatus(DeviceType deviceType, SafeStatus status) = 0;
141 
142     virtual int32_t SetDeviceSafeTime(DeviceType deviceType, int64_t time) = 0;
143 
144     virtual int32_t GetSafeVolumeLevel() const = 0;
145 
146     virtual int32_t GetSafeVolumeTimeout() const = 0;
147 
148     virtual void NotifyAccountsChanged(const int &id) = 0;
149 
150     virtual void SafeVolumeDump(std::string &dumpString) = 0;
151 
152     virtual int32_t GetCurActivateCount() const = 0;
153 
154     virtual void HandleKvData(bool isFirstBoot) = 0;
155 
156     virtual int32_t SetPersistMicMuteState(const bool isMute) = 0;
157 
158     virtual int32_t GetPersistMicMuteState(bool &isMute) const = 0;
159 
160     virtual void HandleSaveVolume(DeviceType deviceType, AudioStreamType streamType, int32_t volumeLevel) = 0;
161 
162     virtual void HandleStreamMuteStatus(AudioStreamType streamType, bool mute,
163         StreamUsage streamUsage = STREAM_USAGE_UNKNOWN) = 0;
164 
165     virtual void HandleRingerMode(AudioRingerMode ringerMode) = 0;
166 
167     virtual void SetAudioServerProxy(sptr<IStandardAudioService> gsp) = 0;
168 
169     virtual void SetOffloadSessionId(uint32_t sessionId) = 0;
170 
171     virtual void ResetOffloadSessionId() = 0;
172 
173     virtual int32_t SetDoubleRingVolumeDb(const AudioStreamType &streamType, const int32_t &volumeLevel) = 0;
174 };
175 } // namespace AudioStandard
176 } // namespace OHOS
177 
178 #endif // I_AUDIO_POLICY_INTERFACE_H
179