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 AUDIO_ADAPTER_MANAGER_HANDLER_H
16 #define AUDIO_ADAPTER_MANAGER_HANDLER_H
17 #include <mutex>
18 
19 #include "singleton.h"
20 #include "event_handler.h"
21 #include "event_runner.h"
22 
23 #include "audio_policy_log.h"
24 #include "audio_info.h"
25 #include "audio_system_manager.h"
26 #include "audio_policy_client.h"
27 
28 namespace OHOS {
29 namespace AudioStandard {
30 using namespace std;
31 
32 class AudioAdapterManagerHandler : public AppExecFwk::EventHandler {
33 public:
34     enum EventAdapterManagerServerCmd  {
35         DATABASE_UPDATE,
36         VOLUME_DATABASE_SAVE,
37         STREAM_MUTE_STATUS_UPDATE,
38         RINGER_MODE_UPDATE,
39     };
40     AudioAdapterManagerHandler();
41     ~AudioAdapterManagerHandler();
42 
43     void ReleaseEventRunner();
44 
45     struct VolumeDataEvent {
46         VolumeDataEvent() = delete;
VolumeDataEventVolumeDataEvent47         VolumeDataEvent(const DeviceType &deviceType, const AudioStreamType &streamType, const int32_t &volumeLevel)
48             : deviceType_(deviceType), streamType_(streamType), volumeLevel_(volumeLevel)
49         {}
50         DeviceType deviceType_;
51         AudioStreamType streamType_;
52         int32_t volumeLevel_;
53     };
54 
55     struct StreamMuteStatusEvent {
56         StreamMuteStatusEvent() = delete;
StreamMuteStatusEventStreamMuteStatusEvent57         StreamMuteStatusEvent(const AudioStreamType &streamType, const bool &mute, const StreamUsage &streamUsage)
58             : streamType_(streamType), mute_(mute), streamUsage_(streamUsage)
59         {}
60         AudioStreamType streamType_;
61         bool mute_;
62         StreamUsage streamUsage_;
63     };
64 
65     struct RingerModeEvent {
66         RingerModeEvent() = delete;
RingerModeEventRingerModeEvent67         RingerModeEvent(const AudioRingerMode &ringerMode)
68             : ringerMode_(ringerMode)
69         {}
70         AudioRingerMode ringerMode_;
71     };
72 
73     bool SendKvDataUpdate(const bool &isFirstBoot);
74     bool SendSaveVolume(const DeviceType &deviceType, const AudioStreamType &streamType, const int32_t &volumeLevel);
75     bool SendStreamMuteStatusUpdate(const AudioStreamType &streamType, const bool &mute,
76         const StreamUsage &streamUsage);
77     bool SendRingerModeUpdate(const AudioRingerMode &ringerMode);
78 
79 protected:
80     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
81 
82 private:
83     /* Handle Event*/
84     void HandleUpdateKvDataEvent(const AppExecFwk::InnerEvent::Pointer &event);
85     void HandleVolumeDataBaseSave(const AppExecFwk::InnerEvent::Pointer &event);
86     void HandleUpdateStreamMuteStatus(const AppExecFwk::InnerEvent::Pointer &event);
87     void HandleUpdateRingerMode(const AppExecFwk::InnerEvent::Pointer &event);
88 
89     std::mutex runnerMutex_;
90 };
91 } // namespace AudioStandard
92 } // namespace OHOS
93 #endif // AUDIO_ADAPTER_MANAGER_HANDLER_H
94