• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "audio_manager_listener_proxy.h"
17 #include "audio_system_manager.h"
18 #include "audio_log.h"
19 
20 namespace OHOS {
21 namespace AudioStandard {
AudioManagerListenerProxy(const sptr<IRemoteObject> & impl)22 AudioManagerListenerProxy::AudioManagerListenerProxy(const sptr<IRemoteObject> &impl)
23     : IRemoteProxy<IStandardAudioServerManagerListener>(impl)
24 {
25     AUDIO_DEBUG_LOG("Instances create");
26 }
27 
~AudioManagerListenerProxy()28 AudioManagerListenerProxy::~AudioManagerListenerProxy()
29 {
30     AUDIO_DEBUG_LOG("~AudioPolicyManagerListenerProxy: Instance destroy");
31 }
32 
WriteParameterEventParams(MessageParcel & data,const std::string networkId,const AudioParamKey key,const std::string & condition,const std::string & value)33 void AudioManagerListenerProxy::WriteParameterEventParams(MessageParcel& data, const std::string networkId,
34     const AudioParamKey key, const std::string& condition, const std::string& value)
35 {
36     data.WriteString(static_cast<std::string>(networkId));
37     data.WriteInt32(static_cast<std::int32_t>(key));
38     data.WriteString(static_cast<std::string>(condition));
39     data.WriteString(static_cast<std::string>(value));
40 }
41 
OnAudioParameterChange(const std::string networkId,const AudioParamKey key,const std::string & condition,const std::string & value)42 void AudioManagerListenerProxy::OnAudioParameterChange(const std::string networkId, const AudioParamKey key,
43     const std::string& condition, const std::string& value)
44 {
45     AUDIO_DEBUG_LOG("AudioManagerListenerProxy: ON_PARAMETER_CHANGED at listener proxy");
46 
47     MessageParcel data;
48     MessageParcel reply;
49     MessageOption option(MessageOption::TF_ASYNC);
50     if (!data.WriteInterfaceToken(GetDescriptor())) {
51         AUDIO_ERR_LOG("AudioPolicyManagerListenerProxy: WriteInterfaceToken failed");
52         return;
53     }
54 
55     data.WriteString(static_cast<std::string>(networkId));
56     data.WriteInt32(static_cast<std::int32_t>(key));
57     data.WriteString(static_cast<std::string>(condition));
58     data.WriteString(static_cast<std::string>(value));
59 
60     int error = Remote()->SendRequest(ON_PARAMETER_CHANGED, data, reply, option);
61     if (error != ERR_NONE) {
62         AUDIO_ERR_LOG("ON_PARAMETER_CHANGED failed, error: %{public}d", error);
63     }
64 }
65 
OnCapturerState(bool isActive)66 void AudioManagerListenerProxy::OnCapturerState(bool isActive)
67 {
68     AUDIO_DEBUG_LOG("AudioManagerListenerProxy: OnCapturerState at listener proxy");
69 
70     MessageParcel data;
71     MessageParcel reply;
72     MessageOption option;
73     if (!data.WriteInterfaceToken(GetDescriptor())) {
74         AUDIO_ERR_LOG("AudioPolicyManagerListenerProxy: WriteInterfaceToken failed");
75         return;
76     }
77 
78     data.WriteBool(isActive);
79 
80     int error = Remote()->SendRequest(ON_CAPTURER_STATE, data, reply, option);
81     if (error != ERR_NONE) {
82         AUDIO_ERR_LOG("ON_CAPTURER_STATE failed, error: %{public}d", error);
83     }
84 }
85 
OnWakeupClose()86 void AudioManagerListenerProxy::OnWakeupClose()
87 {
88     AUDIO_DEBUG_LOG("AudioManagerListenerProxy: OnWakeupClose at listener proxy");
89 
90     MessageParcel data;
91     MessageParcel reply;
92     MessageOption option;
93     if (!data.WriteInterfaceToken(GetDescriptor())) {
94         AUDIO_ERR_LOG("AudioPolicyManagerListenerProxy: WriteInterfaceToken failed");
95         return;
96     }
97 
98     int error = Remote()->SendRequest(ON_WAKEUP_CLOSE, data, reply, option);
99     if (error != ERR_NONE) {
100         AUDIO_ERR_LOG("ON_WAKEUP_CLOSE failed, error: %{public}d", error);
101     }
102 }
103 
AudioManagerListenerCallback(const sptr<IStandardAudioServerManagerListener> & listener)104 AudioManagerListenerCallback::AudioManagerListenerCallback(const sptr<IStandardAudioServerManagerListener>& listener)
105     : listener_(listener)
106 {
107     AUDIO_DEBUG_LOG("AudioManagerListenerCallback: Instance create");
108 }
109 
~AudioManagerListenerCallback()110 AudioManagerListenerCallback::~AudioManagerListenerCallback()
111 {
112     AUDIO_DEBUG_LOG("AudioManagerListenerCallback: Instance destroy");
113 }
114 
OnAudioParameterChange(const std::string networkId,const AudioParamKey key,const std::string & condition,const std::string & value)115 void AudioManagerListenerCallback::OnAudioParameterChange(const std::string networkId, const AudioParamKey key,
116     const std::string& condition, const std::string& value)
117 {
118     if (listener_ != nullptr) {
119         listener_->OnAudioParameterChange(networkId, key, condition, value);
120     }
121 }
122 
OnCapturerState(bool isActive)123 void AudioManagerListenerCallback::OnCapturerState(bool isActive)
124 {
125     if (listener_ != nullptr) {
126         listener_->OnCapturerState(isActive);
127     }
128 }
129 
OnWakeupClose()130 void AudioManagerListenerCallback::OnWakeupClose()
131 {
132     if (listener_ != nullptr) {
133         listener_->OnWakeupClose();
134     }
135 }
136 } // namespace AudioStandard
137 } // namespace OHOS
138