• 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 "audio_system_manager.h"
25 #include "call_manager_errors.h"
26 #include "call_manager_inner_type.h"
27 #include "singleton.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 AudioPreferDeviceChangeCallback : public AudioStandard::AudioPreferredOutputDeviceChangeCallback {
45 public:
46     void OnPreferredOutputDeviceUpdated(const std::vector<sptr<AudioStandard::AudioDeviceDescriptor>> &desc) override;
47 };
48 
49 class AudioProxy : public std::enable_shared_from_this<AudioProxy> {
50     DECLARE_DELAYED_SINGLETON(AudioProxy)
51 public:
52     bool SetAudioScene(AudioStandard::AudioScene audioScene);
53     int32_t ActivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt);
54     int32_t DeactivateAudioInterrupt(const AudioStandard::AudioInterrupt &audioInterrupt);
55     int32_t DeactivateAudioInterrupt();
56     void SetVolumeAudible();
57     bool IsMicrophoneMute();
58     bool SetMicrophoneMute(bool mute);
59     bool SetEarpieceDevActive();
60     bool SetSpeakerDevActive();
61     bool SetBluetoothDevActive();
62     bool SetWiredHeadsetDevActive();
63     AudioStandard::AudioRingerMode GetRingerMode() const;
64     int32_t GetVolume(AudioStandard::AudioVolumeType audioVolumeType);
65     int32_t SetVolume(AudioStandard::AudioVolumeType audioVolumeType, int32_t volume);
66     int32_t SetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType);
67     bool IsStreamActive(AudioStandard::AudioVolumeType audioVolumeType);
68     bool IsStreamMute(AudioStandard::AudioVolumeType audioVolumeType);
69     int32_t GetMaxVolume(AudioStandard::AudioVolumeType audioVolumeType);
70     int32_t GetMinVolume(AudioStandard::AudioVolumeType audioVolumeType);
71     int32_t SetAudioDeviceChangeCallback();
72     bool IsVibrateMode() const;
73     int32_t StartVibrate();
74     int32_t CancelVibrate();
75     std::string GetDefaultRingPath() const;
76     std::string GetDefaultTonePath() const;
77     std::string GetDefaultDtmfPath() const;
78     int32_t UnsetDeviceChangeCallback();
79     void SetWiredHeadsetState(bool isConnected);
80     int32_t GetPreferredOutputAudioDevice(AudioDevice &device);
81     int32_t SetAudioPreferDeviceChangeCallback();
82     int32_t UnsetAudioPreferDeviceChangeCallback();
83 
84 private:
85     const std::string defaultRingPath_ = "/system/etc/telephony/rings/ring.wav";
86     const std::string defaultTonePath_ = "/system/etc/telephony/tones/tone.wav";
87     const std::string defaultDtmfPath_ = "/system/etc/telephony/dtmfs/dtmf.wav";
88     std::shared_ptr<AudioStandard::AudioManagerDeviceChangeCallback> deviceCallback_;
89     std::shared_ptr<AudioStandard::AudioPreferredOutputDeviceChangeCallback> preferredDeviceCallback_;
90     bool isWiredHeadsetConnected_ = false;
91 };
92 } // namespace Telephony
93 } // namespace OHOS
94 #endif // TELEPHONY_AUDIO_PROXY_H
95