• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2025 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 
18 #include <mutex>
19 #include "singleton.h"
20 #include "event_handler.h"
21 #include "event_runner.h"
22 
23 #include "audio_policy_log.h"
24 #include "audio_system_manager.h"
25 #include "iaudio_policy_client.h"
26 
27 namespace OHOS {
28 namespace AudioStandard {
29 using namespace std;
30 
31 class AudioAdapterManagerHandler : public AppExecFwk::EventHandler {
32 public:
33     AudioAdapterManagerHandler();
34     ~AudioAdapterManagerHandler();
35 
36     void ReleaseEventRunner();
37 
38     enum EventAdapterManagerServerCmd  {
39         DATABASE_UPDATE,
40         VOLUME_DATABASE_SAVE,
41         STREAM_MUTE_STATUS_UPDATE,
42         RINGER_MODE_UPDATE,
43         VOLUME_DEGREE_DATABASE_SAVE,
44     };
45 
46     struct VolumeDataEvent {
47         VolumeDataEvent() = delete;
VolumeDataEventVolumeDataEvent48         VolumeDataEvent(const DeviceType &deviceType, const AudioStreamType &streamType, const int32_t &volumeLevel,
49             const std::string &networkId)
50             : deviceType_(deviceType), streamType_(streamType), volumeLevel_(volumeLevel), networkId_(networkId)
51         {}
52         DeviceType deviceType_;
53         AudioStreamType streamType_;
54         int32_t volumeLevel_;
55         std::string networkId_;
56         int32_t volumeDegree_;
57     };
58 
59     struct StreamMuteStatusEvent {
60         StreamMuteStatusEvent() = delete;
StreamMuteStatusEventStreamMuteStatusEvent61         StreamMuteStatusEvent(const AudioStreamType &streamType, const bool &mute, const StreamUsage &streamUsage,
62             const DeviceType &deviceType, const std::string &networkId) : streamType_(streamType), mute_(mute),
63             streamUsage_(streamUsage), deviceType_(deviceType), networkId_(networkId)
64         {}
65         AudioStreamType streamType_;
66         bool mute_;
67         StreamUsage streamUsage_;
68         DeviceType deviceType_;
69         std::string networkId_;
70     };
71 
72     struct RingerModeEvent {
73         RingerModeEvent() = delete;
RingerModeEventRingerModeEvent74         RingerModeEvent(const AudioRingerMode &ringerMode)
75             : ringerMode_(ringerMode)
76         {}
77         AudioRingerMode ringerMode_;
78     };
79 
80     bool SendKvDataUpdate(const bool &isFirstBoot);
81     bool SendSaveVolume(const DeviceType &deviceType, const AudioStreamType &streamType, const int32_t &volumeLevel,
82         std::string networkId = "LocalDevice");
83     bool SendSaveVolumeDegree(DeviceType deviceType, AudioStreamType streamType, int32_t volumeDegree,
84         std::string networkId = "LocalDevice");
85     bool SendStreamMuteStatusUpdate(const AudioStreamType &streamType, const bool &mute,
86         const StreamUsage &streamUsage, const DeviceType &deviceType = DEVICE_TYPE_NONE,
87         std::string networkId = LOCAL_NETWORK_ID);
88     bool SendRingerModeUpdate(const AudioRingerMode &ringerMode);
89 
90 protected:
91     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
92 
93 private:
94     /* Handle Event*/
95     void HandleUpdateKvDataEvent(const AppExecFwk::InnerEvent::Pointer &event);
96     void HandleVolumeDataBaseSave(const AppExecFwk::InnerEvent::Pointer &event);
97     void HandleVolumeDegreeDataBaseSave(const AppExecFwk::InnerEvent::Pointer &event);
98     void HandleUpdateStreamMuteStatus(const AppExecFwk::InnerEvent::Pointer &event);
99     void HandleUpdateRingerMode(const AppExecFwk::InnerEvent::Pointer &event);
100 
101     std::mutex runnerMutex_;
102 };
103 } // namespace AudioStandard
104 } // namespace OHOS
105 #endif // AUDIO_ADAPTER_MANAGER_HANDLER_H
106