1 /*
2 * Copyright (c) 2022-2023 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 "avsession_callback_proxy.h"
17 #include "avsession_log.h"
18
19 namespace OHOS::AVSession {
AVSessionCallbackProxy(const sptr<IRemoteObject> & impl)20 AVSessionCallbackProxy::AVSessionCallbackProxy(const sptr<IRemoteObject>& impl)
21 : IRemoteProxy<IAVSessionCallback>(impl)
22 {
23 SLOGD("construct");
24 }
25
OnAVCallAnswer()26 void AVSessionCallbackProxy::OnAVCallAnswer()
27 {
28 MessageParcel data;
29 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
30
31 auto remote = Remote();
32 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
33 MessageParcel reply;
34 MessageOption option = { MessageOption::TF_ASYNC };
35 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_AVCALL_ANSWER, data, reply, option) == 0,
36 "send request failed");
37 }
38
OnAVCallHangUp()39 void AVSessionCallbackProxy::OnAVCallHangUp()
40 {
41 MessageParcel data;
42 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
43
44 auto remote = Remote();
45 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
46 MessageParcel reply;
47 MessageOption option = { MessageOption::TF_ASYNC };
48 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_AVCALL_HANGUP, data, reply, option) == 0,
49 "send request failed");
50 }
51
OnAVCallToggleCallMute()52 void AVSessionCallbackProxy::OnAVCallToggleCallMute()
53 {
54 MessageParcel data;
55 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
56
57 auto remote = Remote();
58 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
59 MessageParcel reply;
60 MessageOption option = { MessageOption::TF_ASYNC };
61 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_AVCALL_TOGGLE_CALL_MUTE, data, reply, option) == 0,
62 "send request failed");
63 }
64
OnPlay()65 void AVSessionCallbackProxy::OnPlay()
66 {
67 MessageParcel data;
68 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
69
70 auto remote = Remote();
71 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
72 MessageParcel reply;
73 MessageOption option = { MessageOption::TF_ASYNC };
74 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY, data, reply, option) == 0,
75 "send request failed");
76 }
77
OnPause()78 void AVSessionCallbackProxy::OnPause()
79 {
80 MessageParcel data;
81 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
82
83 auto remote = Remote();
84 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
85 MessageParcel reply;
86 MessageOption option = { MessageOption::TF_ASYNC };
87 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PAUSE, data, reply, option) == 0,
88 "send request failed");
89 }
90
OnStop()91 void AVSessionCallbackProxy::OnStop()
92 {
93 MessageParcel data;
94 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
95
96 auto remote = Remote();
97 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
98 MessageParcel reply;
99 MessageOption option = { MessageOption::TF_ASYNC };
100 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_STOP, data, reply, option) == 0,
101 "send request failed");
102 }
103
OnPlayNext()104 void AVSessionCallbackProxy::OnPlayNext()
105 {
106 MessageParcel data;
107 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
108
109 auto remote = Remote();
110 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
111 MessageParcel reply;
112 MessageOption option = { MessageOption::TF_ASYNC };
113 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY_NEXT, data, reply, option) == 0,
114 "send request failed");
115 }
116
OnPlayPrevious()117 void AVSessionCallbackProxy::OnPlayPrevious()
118 {
119 MessageParcel data;
120 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
121
122 auto remote = Remote();
123 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
124 MessageParcel reply;
125 MessageOption option = { MessageOption::TF_ASYNC };
126 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY_PREVIOUS, data, reply, option) == 0,
127 "send request failed");
128 }
129
OnFastForward(int64_t time)130 void AVSessionCallbackProxy::OnFastForward(int64_t time)
131 {
132 MessageParcel data;
133 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
134 CHECK_AND_RETURN_LOG(data.WriteInt64(time), "write time failed");
135
136 auto remote = Remote();
137 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
138 MessageParcel reply;
139 MessageOption option = { MessageOption::TF_ASYNC };
140 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_FAST_FORWARD, data, reply, option) == 0,
141 "send request failed");
142 }
143
OnRewind(int64_t time)144 void AVSessionCallbackProxy::OnRewind(int64_t time)
145 {
146 MessageParcel data;
147 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
148 CHECK_AND_RETURN_LOG(data.WriteInt64(time), "write time failed");
149
150 auto remote = Remote();
151 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
152 MessageParcel reply;
153 MessageOption option = { MessageOption::TF_ASYNC };
154 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_REWIND, data, reply, option) == 0,
155 "send request failed");
156 }
157
OnSeek(int64_t time)158 void AVSessionCallbackProxy::OnSeek(int64_t time)
159 {
160 MessageParcel data;
161 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
162 CHECK_AND_RETURN_LOG(data.WriteInt64(time), "write time failed");
163
164 auto remote = Remote();
165 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
166 MessageParcel reply;
167 MessageOption option = { MessageOption::TF_ASYNC };
168 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SEEK, data, reply, option) == 0,
169 "OnSeek send request failed");
170 }
171
OnSetSpeed(double speed)172 void AVSessionCallbackProxy::OnSetSpeed(double speed)
173 {
174 MessageParcel data;
175 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
176 CHECK_AND_RETURN_LOG(data.WriteDouble(speed), "write speed failed");
177
178 auto remote = Remote();
179 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
180 MessageParcel reply;
181 MessageOption option = { MessageOption::TF_ASYNC };
182 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SET_SPEED, data, reply, option) == 0,
183 "OnSetSpeed send request failed");
184 }
185
OnSetLoopMode(int32_t loopMode)186 void AVSessionCallbackProxy::OnSetLoopMode(int32_t loopMode)
187 {
188 MessageParcel data;
189 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
190 CHECK_AND_RETURN_LOG(data.WriteInt32(loopMode), "write loopMode failed");
191
192 auto remote = Remote();
193 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
194 MessageParcel reply;
195 MessageOption option = { MessageOption::TF_ASYNC };
196 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SET_LOOPMODE, data, reply, option) == 0,
197 "send request failed");
198 }
199
OnSetTargetLoopMode(int32_t targetLoopMode)200 void AVSessionCallbackProxy::OnSetTargetLoopMode(int32_t targetLoopMode)
201 {
202 MessageParcel data;
203 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
204 CHECK_AND_RETURN_LOG(data.WriteInt32(targetLoopMode), "write targetLoopMode failed");
205
206 auto remote = Remote();
207 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
208 MessageParcel reply;
209 MessageOption option = { MessageOption::TF_ASYNC };
210 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SET_TARGET_LOOPMODE, data, reply, option) == 0,
211 "send request failed");
212 }
213
OnToggleFavorite(const std::string & mediaId)214 void AVSessionCallbackProxy::OnToggleFavorite(const std::string& mediaId)
215 {
216 MessageParcel data;
217 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
218 CHECK_AND_RETURN_LOG(data.WriteString(mediaId), "write mediaId failed");
219
220 auto remote = Remote();
221 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
222 MessageParcel reply;
223 MessageOption option = { MessageOption::TF_ASYNC };
224 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_TOGGLE_FAVORITE, data, reply, option) == 0,
225 "send request failed");
226 }
227
OnMediaKeyEvent(const MMI::KeyEvent & keyEvent)228 void AVSessionCallbackProxy::OnMediaKeyEvent(const MMI::KeyEvent& keyEvent)
229 {
230 MessageParcel data;
231 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
232 CHECK_AND_RETURN_LOG(keyEvent.WriteToParcel(data), "write keyEvent failed");
233
234 auto remote = Remote();
235 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
236 MessageParcel reply;
237 MessageOption option = { MessageOption::TF_ASYNC };
238 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_MEDIA_KEY_EVENT, data, reply, option) == 0,
239 "send request failed");
240 }
241
OnOutputDeviceChange(const int32_t connectionState,const OutputDeviceInfo & outputDeviceInfo)242 void AVSessionCallbackProxy::OnOutputDeviceChange(const int32_t connectionState,
243 const OutputDeviceInfo& outputDeviceInfo)
244 {
245 MessageParcel data;
246 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
247 CHECK_AND_RETURN_LOG(data.WriteInt32(connectionState), "write connectionState failed");
248
249 int32_t deviceInfoSize = static_cast<int32_t>(outputDeviceInfo.deviceInfos_.size());
250 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfoSize), "write deviceInfoSize failed");
251 for (DeviceInfo deviceInfo : outputDeviceInfo.deviceInfos_) {
252 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.castCategory_), "write castCategory failed");
253 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.deviceId_), "write deviceId failed");
254 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.deviceName_), "write deviceName failed");
255 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.deviceType_), "write deviceType failed");
256 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.ipAddress_), "write ipAddress failed");
257 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.networkId_), "write networkId failed");
258 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.manufacturer_), "write manufacturer failed");
259 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.modelName_), "write modelName failed");
260 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.providerId_), "write providerId failed");
261 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.supportedProtocols_),
262 "write supportedProtocols failed");
263 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.authenticationStatus_),
264 "write authenticationStatus failed");
265 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.supportedDrmCapabilities_.size()),
266 "write supportedDrmCapabilities size failed");
267 for (auto supportedDrmCapability : deviceInfo.supportedDrmCapabilities_) {
268 CHECK_AND_RETURN_LOG(data.WriteString(supportedDrmCapability),
269 "write supportedDrmCapability failed");
270 }
271 CHECK_AND_RETURN_LOG(data.WriteBool(deviceInfo.isLegacy_), "write isLegacy failed");
272 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.mediumTypes_), "write mediumTypes failed");
273 }
274
275 auto remote = Remote();
276 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
277 MessageParcel reply;
278 MessageOption option = { MessageOption::TF_ASYNC };
279 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_OUTPUT_DEVICE_CHANGE, data, reply, option) == 0,
280 "send request failed");
281 SLOGI("outputdevice change send connect state %{public}d", connectionState);
282 }
283
OnCommonCommand(const std::string & commonCommand,const AAFwk::WantParams & commandArgs)284 void AVSessionCallbackProxy::OnCommonCommand(const std::string& commonCommand,
285 const AAFwk::WantParams& commandArgs)
286 {
287 MessageParcel parcel;
288 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "Write interface token failed");
289 CHECK_AND_RETURN_LOG(parcel.WriteString(commonCommand), "Write event string failed");
290 CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&commandArgs), "Write Want failed");
291 MessageParcel reply;
292 MessageOption option = { MessageOption::TF_ASYNC };
293 auto remote = Remote();
294 CHECK_AND_RETURN_LOG(remote != nullptr, "Get remote service failed");
295 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SEND_COMMON_COMMAND, parcel, reply, option) == 0,
296 "Send request failed");
297 }
298
OnSkipToQueueItem(int32_t itemId)299 void AVSessionCallbackProxy::OnSkipToQueueItem(int32_t itemId)
300 {
301 MessageParcel data;
302 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
303 CHECK_AND_RETURN_LOG(data.WriteInt32(itemId), "write itemId failed");
304
305 auto remote = Remote();
306 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
307 MessageParcel reply;
308 MessageOption option = { MessageOption::TF_ASYNC };
309 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SKIP_TO_QUEUE_ITEM, data, reply, option) == 0,
310 "send request failed");
311 }
312
OnPlayFromAssetId(int64_t assetId)313 void AVSessionCallbackProxy::OnPlayFromAssetId(int64_t assetId)
314 {
315 MessageParcel data;
316 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
317 CHECK_AND_RETURN_LOG(data.WriteInt64(assetId), "write assetId failed");
318
319 auto remote = Remote();
320 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
321 MessageParcel reply;
322 MessageOption option = { MessageOption::TF_ASYNC };
323 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY_FROM_ASSETID, data, reply, option) == 0,
324 "OnPlayFromAssetId send request failed");
325 }
326
OnCastDisplayChange(const CastDisplayInfo & castDisplayInfo)327 void AVSessionCallbackProxy::OnCastDisplayChange(const CastDisplayInfo& castDisplayInfo)
328 {
329 MessageParcel data;
330 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
331 CHECK_AND_RETURN_LOG(data.WriteInt32(static_cast<int32_t>(castDisplayInfo.displayState)),
332 "write displayState failed");
333 CHECK_AND_RETURN_LOG(data.WriteUint64(castDisplayInfo.displayId), "write displayId failed");
334 CHECK_AND_RETURN_LOG(data.WriteString(castDisplayInfo.name), "write name failed");
335 CHECK_AND_RETURN_LOG(data.WriteInt32(castDisplayInfo.width), "write width failed");
336 CHECK_AND_RETURN_LOG(data.WriteInt32(castDisplayInfo.height), "write height failed");
337
338 auto remote = Remote();
339 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
340 MessageParcel reply;
341 MessageOption option = { MessageOption::TF_ASYNC };
342 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_CAST_DISPLAY_CHANGE, data, reply, option) == 0,
343 "OnCastDisplayChange send request failed");
344 }
345 } // namespace OHOS::AVSession
346