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
OnPlay()26 void AVSessionCallbackProxy::OnPlay()
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_PLAY, data, reply, option) == 0,
36 "send request failed");
37 }
38
OnPause()39 void AVSessionCallbackProxy::OnPause()
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_PAUSE, data, reply, option) == 0,
49 "send request failed");
50 }
51
OnStop()52 void AVSessionCallbackProxy::OnStop()
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_STOP, data, reply, option) == 0,
62 "send request failed");
63 }
64
OnPlayNext()65 void AVSessionCallbackProxy::OnPlayNext()
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_NEXT, data, reply, option) == 0,
75 "send request failed");
76 }
77
OnPlayPrevious()78 void AVSessionCallbackProxy::OnPlayPrevious()
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_PLAY_PREVIOUS, data, reply, option) == 0,
88 "send request failed");
89 }
90
OnFastForward()91 void AVSessionCallbackProxy::OnFastForward()
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_FAST_FORWARD, data, reply, option) == 0,
101 "send request failed");
102 }
103
OnRewind()104 void AVSessionCallbackProxy::OnRewind()
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_REWIND, data, reply, option) == 0,
114 "send request failed");
115 }
116
OnSeek(int64_t time)117 void AVSessionCallbackProxy::OnSeek(int64_t time)
118 {
119 MessageParcel data;
120 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
121 CHECK_AND_RETURN_LOG(data.WriteInt64(time), "write time failed");
122
123 auto remote = Remote();
124 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
125 MessageParcel reply;
126 MessageOption option = { MessageOption::TF_ASYNC };
127 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SEEK, data, reply, option) == 0,
128 "OnSeek send request failed");
129 }
130
OnSetSpeed(double speed)131 void AVSessionCallbackProxy::OnSetSpeed(double speed)
132 {
133 MessageParcel data;
134 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
135 CHECK_AND_RETURN_LOG(data.WriteDouble(speed), "write speed failed");
136
137 auto remote = Remote();
138 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
139 MessageParcel reply;
140 MessageOption option = { MessageOption::TF_ASYNC };
141 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SET_SPEED, data, reply, option) == 0,
142 "OnSetSpeed send request failed");
143 }
144
OnSetLoopMode(int32_t loopMode)145 void AVSessionCallbackProxy::OnSetLoopMode(int32_t loopMode)
146 {
147 MessageParcel data;
148 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
149 CHECK_AND_RETURN_LOG(data.WriteInt32(loopMode), "write loopMode failed");
150
151 auto remote = Remote();
152 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
153 MessageParcel reply;
154 MessageOption option = { MessageOption::TF_ASYNC };
155 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SET_LOOPMODE, data, reply, option) == 0,
156 "send request failed");
157 }
158
OnToggleFavorite(const std::string & mediaId)159 void AVSessionCallbackProxy::OnToggleFavorite(const std::string& mediaId)
160 {
161 MessageParcel data;
162 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
163 CHECK_AND_RETURN_LOG(data.WriteString(mediaId), "write mediaId failed");
164
165 auto remote = Remote();
166 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
167 MessageParcel reply;
168 MessageOption option = { MessageOption::TF_ASYNC };
169 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_TOGGLE_FAVORITE, data, reply, option) == 0,
170 "send request failed");
171 }
172
OnMediaKeyEvent(const MMI::KeyEvent & keyEvent)173 void AVSessionCallbackProxy::OnMediaKeyEvent(const MMI::KeyEvent& keyEvent)
174 {
175 MessageParcel data;
176 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
177 CHECK_AND_RETURN_LOG(keyEvent.WriteToParcel(data), "write keyEvent failed");
178
179 auto remote = Remote();
180 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
181 MessageParcel reply;
182 MessageOption option = { MessageOption::TF_ASYNC };
183 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_MEDIA_KEY_EVENT, data, reply, option) == 0,
184 "send request failed");
185 }
186
OnOutputDeviceChange(const int32_t connectionState,const OutputDeviceInfo & outputDeviceInfo)187 void AVSessionCallbackProxy::OnOutputDeviceChange(const int32_t connectionState,
188 const OutputDeviceInfo& outputDeviceInfo)
189 {
190 MessageParcel data;
191 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
192 CHECK_AND_RETURN_LOG(data.WriteInt32(connectionState), "write connectionState failed");
193
194 int32_t deviceInfoSize = static_cast<int32_t>(outputDeviceInfo.deviceInfos_.size());
195 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfoSize), "write deviceInfoSize failed");
196 for (DeviceInfo deviceInfo : outputDeviceInfo.deviceInfos_) {
197 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.castCategory_), "write castCategory failed");
198 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.deviceId_), "write deviceId failed");
199 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.deviceName_), "write deviceName failed");
200 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.deviceType_), "write deviceType failed");
201 CHECK_AND_RETURN_LOG(data.WriteString(deviceInfo.ipAddress_), "write ipAddress failed");
202 CHECK_AND_RETURN_LOG(data.WriteInt32(deviceInfo.providerId_), "write providerId failed");
203 }
204
205 auto remote = Remote();
206 CHECK_AND_RETURN_LOG(remote != nullptr, "get remote service failed");
207 MessageParcel reply;
208 MessageOption option = { MessageOption::TF_ASYNC };
209 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_OUTPUT_DEVICE_CHANGE, data, reply, option) == 0,
210 "send request failed");
211 }
212
OnCommonCommand(const std::string & commonCommand,const AAFwk::WantParams & commandArgs)213 void AVSessionCallbackProxy::OnCommonCommand(const std::string& commonCommand,
214 const AAFwk::WantParams& commandArgs)
215 {
216 MessageParcel parcel;
217 CHECK_AND_RETURN_LOG(parcel.WriteInterfaceToken(GetDescriptor()), "Write interface token failed");
218 CHECK_AND_RETURN_LOG(parcel.WriteString(commonCommand), "Write event string failed");
219 CHECK_AND_RETURN_LOG(parcel.WriteParcelable(&commandArgs), "Write Want failed");
220 MessageParcel reply;
221 MessageOption option = { MessageOption::TF_ASYNC };
222 auto remote = Remote();
223 CHECK_AND_RETURN_LOG(remote != nullptr, "Get remote service failed");
224 CHECK_AND_RETURN_LOG(remote->SendRequest(SESSION_CALLBACK_ON_SEND_COMMON_COMMAND, parcel, reply, option) == 0,
225 "Send request failed");
226 }
227
OnSkipToQueueItem(int32_t itemId)228 void AVSessionCallbackProxy::OnSkipToQueueItem(int32_t itemId)
229 {
230 MessageParcel data;
231 CHECK_AND_RETURN_LOG(data.WriteInterfaceToken(GetDescriptor()), "write interface token failed");
232 CHECK_AND_RETURN_LOG(data.WriteInt32(itemId), "write itemId 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_SKIP_TO_QUEUE_ITEM, data, reply, option) == 0,
239 "send request failed");
240 }
241 } // namespace OHOS::AVSession
242