• 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 #ifndef LOG_TAG
16 #define LOG_TAG "AudioClientTrackerCallbackProxy"
17 #endif
18 
19 #include "audio_policy_log.h"
20 #include "audio_client_tracker_callback_proxy.h"
21 
22 namespace OHOS {
23 namespace AudioStandard {
AudioClientTrackerCallbackProxy(const sptr<IRemoteObject> & impl)24 AudioClientTrackerCallbackProxy::AudioClientTrackerCallbackProxy(const sptr<IRemoteObject> &impl)
25     : IRemoteProxy<IStandardClientTracker>(impl) { }
26 
MuteStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)27 void AudioClientTrackerCallbackProxy::MuteStreamImpl(
28     const StreamSetStateEventInternal &streamSetStateEventInternal)
29 {
30     MessageParcel data;
31     MessageParcel reply;
32     MessageOption option(MessageOption::TF_ASYNC);
33     bool ret = data.WriteInterfaceToken(GetDescriptor());
34     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
35 
36     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
37     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamUsage));
38     int error = Remote()->SendRequest(MUTESTREAM, data, reply, option);
39     if (error != ERR_NONE) {
40         AUDIO_WARNING_LOG("MuteStreamImpl failed, error: %{public}d", error);
41     }
42 }
43 
UnmuteStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)44 void AudioClientTrackerCallbackProxy::UnmuteStreamImpl(
45     const StreamSetStateEventInternal &streamSetStateEventInternal)
46 {
47     MessageParcel data;
48     MessageParcel reply;
49     MessageOption option(MessageOption::TF_ASYNC);
50     bool ret = data.WriteInterfaceToken(GetDescriptor());
51     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
52 
53     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
54     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamUsage));
55     int error = Remote()->SendRequest(UNMUTESTREAM, data, reply, option);
56     if (error != ERR_NONE) {
57         AUDIO_WARNING_LOG("UnmuteStreamImpl failed, error: %{public}d", error);
58     }
59 }
60 
PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)61 void AudioClientTrackerCallbackProxy::PausedStreamImpl(
62     const StreamSetStateEventInternal &streamSetStateEventInternal)
63 {
64     MessageParcel data;
65     MessageParcel reply;
66     MessageOption option(MessageOption::TF_ASYNC);
67     bool ret = data.WriteInterfaceToken(GetDescriptor());
68     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
69 
70     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
71     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamUsage));
72     int error = Remote()->SendRequest(PAUSEDSTREAM, data, reply, option);
73     if (error != ERR_NONE) {
74         AUDIO_WARNING_LOG("PausedStreamImpl failed, error: %{public}d", error);
75     }
76 }
77 
ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)78 void AudioClientTrackerCallbackProxy::ResumeStreamImpl(
79     const StreamSetStateEventInternal &streamSetStateEventInternal)
80 {
81     MessageParcel data;
82     MessageParcel reply;
83     MessageOption option(MessageOption::TF_ASYNC);
84     bool ret = data.WriteInterfaceToken(GetDescriptor());
85     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
86 
87     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamSetState));
88     data.WriteInt32(static_cast<int32_t>(streamSetStateEventInternal.streamUsage));
89     int error = Remote()->SendRequest(RESUMESTREAM, data, reply, option);
90     if (error != ERR_NONE) {
91         AUDIO_WARNING_LOG("ResumeStreamImpl failed, error: %{public}d", error);
92     }
93 }
94 
SetLowPowerVolumeImpl(float volume)95 void AudioClientTrackerCallbackProxy::SetLowPowerVolumeImpl(float volume)
96 {
97     MessageParcel data;
98     MessageParcel reply;
99     MessageOption option(MessageOption::TF_ASYNC);
100     bool ret = data.WriteInterfaceToken(GetDescriptor());
101     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
102 
103     data.WriteFloat(static_cast<float>(volume));
104     int error = Remote()->SendRequest(SETLOWPOWERVOL, data, reply, option);
105     if (error != ERR_NONE) {
106         AUDIO_WARNING_LOG("SETLOWPOWERVOL failed, error: %{public}d", error);
107     }
108 }
109 
GetLowPowerVolumeImpl(float & volume)110 void AudioClientTrackerCallbackProxy::GetLowPowerVolumeImpl(float &volume)
111 {
112     MessageParcel data;
113     MessageParcel reply;
114     MessageOption option;
115     bool ret = data.WriteInterfaceToken(GetDescriptor());
116     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
117 
118     int error = Remote()->SendRequest(GETLOWPOWERVOL, data, reply, option);
119     if (error != ERR_NONE) {
120         AUDIO_WARNING_LOG("GETLOWPOWERVOL failed, error: %{public}d", error);
121     }
122 
123     volume = reply.ReadFloat();
124 }
125 
GetSingleStreamVolumeImpl(float & volume)126 void AudioClientTrackerCallbackProxy::GetSingleStreamVolumeImpl(float &volume)
127 {
128     MessageParcel data;
129     MessageParcel reply;
130     MessageOption option;
131     bool ret = data.WriteInterfaceToken(GetDescriptor());
132     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
133 
134     int error = Remote()->SendRequest(GETSINGLESTREAMVOL, data, reply, option);
135     if (error != ERR_NONE) {
136         AUDIO_WARNING_LOG("GETSINGLESTREAMVOL failed, error: %{public}d", error);
137     }
138 
139     volume = reply.ReadFloat();
140 }
141 
SetOffloadModeImpl(int32_t state,bool isAppBack)142 void AudioClientTrackerCallbackProxy::SetOffloadModeImpl(int32_t state, bool isAppBack)
143 {
144     MessageParcel data;
145     MessageParcel reply;
146     MessageOption option;
147     bool ret = data.WriteInterfaceToken(GetDescriptor());
148     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
149 
150     data.WriteInt32(static_cast<int32_t>(state));
151     data.WriteBool(static_cast<bool>(isAppBack));
152 
153     int error = Remote()->SendRequest(SETOFFLOADMODE, data, reply, option);
154     if (error != ERR_NONE) {
155         AUDIO_WARNING_LOG("SETOFFLOADMODE failed, error: %{public}d", error);
156     }
157 }
158 
UnsetOffloadModeImpl()159 void AudioClientTrackerCallbackProxy::UnsetOffloadModeImpl()
160 {
161     MessageParcel data;
162     MessageParcel reply;
163     MessageOption option;
164     bool ret = data.WriteInterfaceToken(GetDescriptor());
165     CHECK_AND_RETURN_LOG(ret, "WriteInterfaceToken failed");
166 
167     int error = Remote()->SendRequest(UNSETOFFLOADMODE, data, reply, option);
168     if (error != ERR_NONE) {
169         AUDIO_WARNING_LOG("UNSETOFFLOADMODE failed, error: %{public}d", error);
170     }
171 }
172 
ClientTrackerCallbackListener(const sptr<IStandardClientTracker> & listener)173 ClientTrackerCallbackListener::ClientTrackerCallbackListener(const sptr<IStandardClientTracker> &listener)
174     : listener_(listener)
175 {
176 }
177 
~ClientTrackerCallbackListener()178 ClientTrackerCallbackListener::~ClientTrackerCallbackListener()
179 {
180 }
181 
MuteStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)182 void ClientTrackerCallbackListener::MuteStreamImpl(
183     const StreamSetStateEventInternal &streamSetStateEventInternal)
184 {
185     if (listener_ != nullptr) {
186         listener_->MuteStreamImpl(streamSetStateEventInternal);
187     }
188 }
189 
UnmuteStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)190 void ClientTrackerCallbackListener::UnmuteStreamImpl(
191     const StreamSetStateEventInternal &streamSetStateEventInternal)
192 {
193     if (listener_ != nullptr) {
194         listener_->UnmuteStreamImpl(streamSetStateEventInternal);
195     }
196 }
197 
PausedStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)198 void ClientTrackerCallbackListener::PausedStreamImpl(
199     const StreamSetStateEventInternal &streamSetStateEventInternal)
200 {
201     if (listener_ != nullptr) {
202         listener_->PausedStreamImpl(streamSetStateEventInternal);
203     }
204 }
205 
ResumeStreamImpl(const StreamSetStateEventInternal & streamSetStateEventInternal)206 void ClientTrackerCallbackListener::ResumeStreamImpl(
207     const StreamSetStateEventInternal &streamSetStateEventInternal)
208 {
209     if (listener_ != nullptr) {
210         listener_->ResumeStreamImpl(streamSetStateEventInternal);
211     }
212 }
213 
SetLowPowerVolumeImpl(float volume)214 void ClientTrackerCallbackListener::SetLowPowerVolumeImpl(float volume)
215 {
216     if (listener_ != nullptr) {
217         listener_->SetLowPowerVolumeImpl(volume);
218     }
219 }
220 
GetLowPowerVolumeImpl(float & volume)221 void ClientTrackerCallbackListener::GetLowPowerVolumeImpl(float &volume)
222 {
223     if (listener_ != nullptr) {
224         listener_->GetLowPowerVolumeImpl(volume);
225     }
226 }
227 
GetSingleStreamVolumeImpl(float & volume)228 void ClientTrackerCallbackListener::GetSingleStreamVolumeImpl(float &volume)
229 {
230     if (listener_ != nullptr) {
231         listener_->GetSingleStreamVolumeImpl(volume);
232     }
233 }
234 
SetOffloadModeImpl(int32_t state,bool isAppBack)235 void ClientTrackerCallbackListener::SetOffloadModeImpl(int32_t state, bool isAppBack)
236 {
237     if (listener_ != nullptr) {
238         listener_->SetOffloadModeImpl(state, isAppBack);
239     }
240 }
241 
UnsetOffloadModeImpl()242 void ClientTrackerCallbackListener::UnsetOffloadModeImpl()
243 {
244     if (listener_ != nullptr) {
245         listener_->UnsetOffloadModeImpl();
246     }
247 }
248 } // namespace AudioStandard
249 } // namespace OHOS
250