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
OnToggleFavorite(const std::string & mediaId)200 void AVSessionCallbackProxy::OnToggleFavorite(const std::string& mediaId)
201 {
202 MessageParcel data;
203 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
204 CHECK_AND_RETURN_LOG(data.WriteString(mediaId), "write mediaId 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_TOGGLE_FAVORITE, data, reply, option) == 0,
211 "send request failed");
212 }
213
OnMediaKeyEvent(const MMI::KeyEvent & keyEvent)214 void AVSessionCallbackProxy::OnMediaKeyEvent(const MMI::KeyEvent& keyEvent)
215 {
216 MessageParcel data;
217 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
218 CHECK_AND_RETURN_LOG(keyEvent.WriteToParcel(data), "write keyEvent 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_MEDIA_KEY_EVENT, data, reply, option) == 0,
225 "send request failed");
226 }
227
OnOutputDeviceChange(const int32_t connectionState,const OutputDeviceInfo & outputDeviceInfo)228 void AVSessionCallbackProxy::OnOutputDeviceChange(const int32_t connectionState,
229 const OutputDeviceInfo& outputDeviceInfo)
230 {
231 MessageParcel data;
232 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
233 CHECK_AND_RETURN_LOG(data.WriteInt32(connectionState), "write connectionState failed");
234
235 int32_t deviceInfoSize = static_cast<int32_t>(outputDeviceInfo.deviceInfos_.size());
236 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfoSize), "write deviceInfoSize failed");
237 for (DeviceInfo deviceInfo : outputDeviceInfo.deviceInfos_) {
238 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.castCategory_), "write castCategory failed");
239 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.deviceId_), "write deviceId failed");
240 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.deviceName_), "write deviceName failed");
241 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.deviceType_), "write deviceType failed");
242 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.ipAddress_), "write ipAddress failed");
243 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.providerId_), "write providerId failed");
244 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.supportedProtocols_),
245 "write supportedProtocols failed");
246 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.authenticationStatus_),
247 "write authenticationStatus failed");
248 }
249
250 auto remote = Remote();
251 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
252 MessageParcel reply;
253 MessageOption option = { MessageOption::TF_ASYNC };
254 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_OUTPUT_DEVICE_CHANGE, data, reply, option) == 0,
255 "send request failed");
256 SLOGI("outputdevice change send connect state %{public}d", connectionState);
257 }
258
OnCommonCommand(const std::string & commonCommand,const AAFwk::WantParams & commandArgs)259 void AVSessionCallbackProxy::OnCommonCommand(const std::string& commonCommand,
260 const AAFwk::WantParams& commandArgs)
261 {
262 MessageParcel parcel;
263 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "Write interface token failed");
264 CHECK_AND_RETURN_LOG(parcel.WriteString(commonCommand), "Write event string failed");
265 CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&commandArgs), "Write Want failed");
266 MessageParcel reply;
267 MessageOption option = { MessageOption::TF_ASYNC };
268 auto remote = Remote();
269 CHECK_AND_RETURN_LOG(remote != nullptr, "Get remote service failed");
270 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SEND_COMMON_COMMAND, parcel, reply, option) == 0,
271 "Send request failed");
272 }
273
OnSkipToQueueItem(int32_t itemId)274 void AVSessionCallbackProxy::OnSkipToQueueItem(int32_t itemId)
275 {
276 MessageParcel data;
277 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
278 CHECK_AND_RETURN_LOG(data.WriteInt32(itemId), "write itemId failed");
279
280 auto remote = Remote();
281 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
282 MessageParcel reply;
283 MessageOption option = { MessageOption::TF_ASYNC };
284 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SKIP_TO_QUEUE_ITEM, data, reply, option) == 0,
285 "send request failed");
286 }
287
OnPlayFromAssetId(int64_t assetId)288 void AVSessionCallbackProxy::OnPlayFromAssetId(int64_t assetId)
289 {
290 MessageParcel data;
291 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
292 CHECK_AND_RETURN_LOG(data.WriteInt64(assetId), "write assetId failed");
293
294 auto remote = Remote();
295 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
296 MessageParcel reply;
297 MessageOption option = { MessageOption::TF_ASYNC };
298 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_PLAY_FROM_ASSETID, data, reply, option) == 0,
299 "OnPlayFromAssetId send request failed");
300 }
301
302 } // namespace OHOS::AVSession
303