• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef VOLUME_DATA_MAINTAINER_H
16 #define VOLUME_DATA_MAINTAINER_H
17 
18 #include <list>
19 #include <unordered_map>
20 #include <cinttypes>
21 
22 #include "ipc_skeleton.h"
23 #include "errors.h"
24 #include "mutex"
25 
26 #include "audio_setting_provider.h"
27 #include "audio_policy_log.h"
28 #include "audio_info.h"
29 
30 namespace OHOS {
31 namespace AudioStandard {
32 constexpr int32_t MAX_SAFE_STATUS = 2;
33 
34 class VolumeDataMaintainer {
35 public:
36     enum VolumeDataMaintainerStreamType {  // define with Dual framework
37         VT_STREAM_DEFAULT = -1,
38         VT_STREAM_VOICE_CALL = 0,
39         VT_STREAM_SYSTEM  = 1,
40         VT_STREAM_RING = 2,
41         VT_STREAM_MUSIC  = 3,
42         VT_STREAM_ALARM = 4,
43         VT_STREAM_NOTIFICATION = 5,
44         VT_STREAM_BLUETOOTH_SCO = 6,
45         VT_STREAM_SYSTEM_ENFORCED = 7,
46         VT_STREAM_DTMF = 8,
47         VT_STREAM_TTS = 9,
48         VT_STREAM_ACCESSIBILITY = 10,
49         VT_STREAM_ASSISTANT = 11,
50     };
51 
GetVolumeDataMaintainer()52     static VolumeDataMaintainer& GetVolumeDataMaintainer()
53     {
54         static VolumeDataMaintainer volumeDataMainTainer;
55         return volumeDataMainTainer;
56     }
57     ~VolumeDataMaintainer();
58 
59     bool SetFirstBoot(bool fristBoot);
60     bool GetFirstBoot(bool &firstBoot);
61 
62     bool SaveVolume(DeviceType type, AudioStreamType streamType, int32_t volumeLevel);
63     bool GetVolume(DeviceType deviceType, AudioStreamType streamType);
64     void SetStreamVolume(AudioStreamType streamType, int32_t volumeLevel);
65     int32_t GetStreamVolume(AudioStreamType streamType);
66     std::unordered_map<AudioStreamType, int32_t> GetVolumeMap();
67 
68     bool SaveMuteStatus(DeviceType deviceType, AudioStreamType streamType,
69         bool muteStatus);
70     bool GetMuteStatus(DeviceType deviceType, AudioStreamType streamType);
71     bool SetStreamMuteStatus(AudioStreamType streamType, bool muteStatus);
72     bool GetStreamMute(AudioStreamType streamType);
73 
74     bool GetMuteAffected(int32_t &affected);
75     bool GetMuteTransferStatus(bool &status);
76     bool SetMuteAffectedToMuteStatusDataBase(int32_t affected);
77     bool SaveMuteTransferStatus(bool status);
78 
79     bool SaveRingerMode(AudioRingerMode ringerMode);
80     bool GetRingerMode(AudioRingerMode &ringerMode);
81     bool SaveSafeStatus(DeviceType deviceType, SafeStatus safeStatus);
82     bool GetSafeStatus(DeviceType deviceType, SafeStatus &safeStatus);
83     bool SaveSafeVolumeTime(DeviceType deviceType, int64_t time);
84     bool GetSafeVolumeTime(DeviceType deviceType, int64_t &time);
85     bool SaveSystemSoundUrl(const std::string &key, const std::string &value);
86     bool GetSystemSoundUrl(const std::string &key, std::string &value);
87     void RegisterCloned();
88     bool SaveMicMuteState(bool isMute);
89     bool GetMicMuteState(bool &isMute);
90 
91 private:
92     VolumeDataMaintainer();
93     static std::string GetVolumeKeyForDataShare(DeviceType deviceType, AudioStreamType streamType);
94     static std::string GetMuteKeyForDataShare(DeviceType deviceType, AudioStreamType streamType);
95     static std::string GetDeviceTypeName(DeviceType deviceType);
96     bool GetVolumeInternal(DeviceType deviceType, AudioStreamType streamType);
97     void SetStreamVolumeInternal(AudioStreamType streamType, int32_t volumeLevel);
98     bool SaveMuteStatusInternal(DeviceType deviceType, AudioStreamType streamType, bool muteStatus);
99     bool GetMuteStatusInternal(DeviceType deviceType, AudioStreamType streamType);
100     bool GetStreamMuteInternal(AudioStreamType streamType);
101     int32_t GetStreamVolumeInternal(AudioStreamType streamType);
102 
103     std::mutex volumeMutex_;
104     std::mutex volumeForDbMutex_;
105     std::unordered_map<AudioStreamType, bool> muteStatusMap_; // save volume Mutestatus map
106     std::unordered_map<AudioStreamType, int32_t> volumeLevelMap_; // save volume map
107     bool isSettingsCloneHaveStarted_ = false;
108 };
109 } // namespace AudioStandard
110 } // namespace OHOS
111 #endif // VOLUME_DATA_MAINTAINER_H
112