• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 TELEPHONY_AUDIO_PROXY_H
17 #define TELEPHONY_AUDIO_PROXY_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <mutex>
22 
23 #include "audio_manager_proxy.h"
24 #include "singleton.h"
25 #include "audio_ringtone_manager.h"
26 
27 #include "call_manager_errors.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 constexpr uint16_t VOLUME_AUDIBLE_DIVISOR = 2;
32 
33 enum AudioInterruptState {
34     INTERRUPT_STATE_UNKNOWN = 0,
35     INTERRUPT_STATE_DEACTIVATED,
36     INTERRUPT_STATE_ACTIVATED,
37     INTERRUPT_STATE_RINGING,
38 };
39 
40 class AudioDeviceChangeCallback : public AudioStandard::AudioManagerDeviceChangeCallback {
41     void OnDeviceChange(const AudioStandard::DeviceChangeAction &deviceChangeAction) override;
42 };
43 
44 class AudioProxy : public std::enable_shared_from_this<AudioProxy> {
45     DECLARE_DELAYED_SINGLETON(AudioProxy)
46 public:
47     bool SetAudioScene(AudioStandard::AudioScene audioScene);
48     int32_t ActivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt);
49     int32_t DeactivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt);
50     int32_t DeactivateAudioInterrupt();
51     void SetVolumeAudible();
52     bool IsMicrophoneMute();
53     bool SetMicrophoneMute(bool mute);
54     bool SetEarpieceDevActive();
55     bool SetSpeakerDevActive();
56     bool SetBluetoothDevActive();
57     bool SetWiredHeadsetDevActive();
58     AudioStandard::AudioRingerMode GetRingerMode() const;
59     int32_t GetVolume(AudioStandard::AudioVolumeType audioVolumeType);
60     int32_t SetVolume(AudioStandard::AudioVolumeType audioVolumeType, int32_t volume);
61     int32_t SetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType);
62     bool IsStreamActive(AudioStandard::AudioVolumeType audioVolumeType);
63     bool IsStreamMute(AudioStandard::AudioVolumeType audioVolumeType);
64     int32_t GetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType);
65     int32_t GetMinVolume(AudioStandard::AudioVolumeType audioVolumeType);
66     int32_t SetAudioDeviceChangeCallback();
67     bool IsVibrateMode() const;
68     int32_t StartVibrate();
69     int32_t CancelVibrate();
70     std::string GetSystemRingtoneUri() const;
71     std::string GetDefaultRingPath() const;
72     std::string GetDefaultTonePath() const;
73     std::string GetDefaultDtmfPath() const;
74 
75 private:
76     const std::string defaultRingPath_ = "/system/etc/telephony/rings/ring.wav";
77     const std::string defaultTonePath_ = "/system/etc/telephony/tones/tone.wav";
78     const std::string defaultDtmfPath_ = "/system/etc/telephony/dtmfs/dtmf.wav";
79     std::shared_ptr<AbilityRuntime::Context> context_;
80     std::unique_ptr<AudioStandard::RingtoneSoundManager> audioSoundManager_;
81     std::shared_ptr<AudioStandard::AudioManagerDeviceChangeCallback> deviceCallback_;
82 };
83 } // namespace Telephony
84 } // namespace OHOS
85 #endif // TELEPHONY_AUDIO_PROXY_H
86