1 /*
2 * Copyright (c) 2021-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 #include "form_provider_stub.h"
16 #include "appexecfwk_errors.h"
17 #include "app_scheduler_interface.h"
18 #include "errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_mgr_errors.h"
21 #include "ipc_skeleton.h"
22 #include "ipc_types.h"
23 #include "iremote_object.h"
24
25 namespace OHOS {
26 namespace AppExecFwk {
FormProviderStub()27 FormProviderStub::FormProviderStub()
28 {}
29
~FormProviderStub()30 FormProviderStub::~FormProviderStub()
31 {}
32 /**
33 * @brief handle remote request.
34 * @param data input param.
35 * @param reply output param.
36 * @param option message option.
37 * @return Returns ERR_OK on success, others on failure.
38 */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int FormProviderStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
40 {
41 HILOG_INFO("code:%{public}u, flags:%{public}d", code, option.GetFlags());
42 std::u16string descriptor = FormProviderStub::GetDescriptor();
43 std::u16string remoteDescriptor = data.ReadInterfaceToken();
44 if (descriptor != remoteDescriptor) {
45 HILOG_ERROR("localDescribe not equal to remote");
46 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
47 }
48
49 switch (code) {
50 case static_cast<uint32_t>(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_FORM_INFO):
51 return HandleAcquireProviderFormInfo(data, reply);
52 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_DELETE):
53 return HandleNotifyFormDelete(data, reply);
54 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORMS_DELETE):
55 return HandleNotifyFormsDelete(data, reply);
56 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_UPDATE):
57 return HandleNotifyFormUpdate(data, reply);
58 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_EVENT_NOTIFY):
59 return HandleEventNotify(data, reply);
60 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_TEMP_FORM_CAST):
61 return HandleNotifyFormCastTempForm(data, reply);
62 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_EVENT_MESSAGE):
63 return HandleFireFormEvent(data, reply);
64 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_STATE_ACQUIRE):
65 return HandleAcquireState(data, reply);
66 case static_cast<uint32_t>(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_SHARE_FOMR_INFO):
67 return HandleAcquireShareFormData(data, reply);
68 case static_cast<uint32_t>(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_FOMR_DATA):
69 return HandleAcquireFormData(data, reply);
70 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_CONFIGURATION_UPDATE):
71 return HandleNotifyConfigurationUpdate(data, reply);
72 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_LOCATION_UPDATE):
73 return HandleNotifyFormLocationUpdate(data, reply);
74 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_SIZE_CHANGED):
75 return HandleNotifySizeChanged(data, reply);
76 default:
77 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
78 }
79 }
80
HandleAcquireProviderFormInfo(MessageParcel & data,MessageParcel & reply)81 int FormProviderStub::HandleAcquireProviderFormInfo(MessageParcel &data, MessageParcel &reply)
82 {
83 std::unique_ptr<FormJsInfo> formJsInfo(data.ReadParcelable<FormJsInfo>());
84 if (!formJsInfo) {
85 HILOG_ERROR("ReadParcelable<FormJsInfo> failed");
86 return ERR_APPEXECFWK_PARCEL_ERROR;
87 }
88 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
89 if (!want) {
90 HILOG_ERROR("ReadParcelable<Want> failed");
91 return ERR_APPEXECFWK_PARCEL_ERROR;
92 }
93
94 sptr<IRemoteObject> client = data.ReadRemoteObject();
95 if (client == nullptr) {
96 HILOG_ERROR("get remote object failed");
97 return ERR_APPEXECFWK_PARCEL_ERROR;
98 }
99
100 int32_t result = AcquireProviderFormInfo(*formJsInfo, *want, client);
101 reply.WriteInt32(result);
102 return result;
103 }
104 /**
105 * @brief handle NotifyFormDelete message.
106 * @param data input param.
107 * @param reply output param.
108 * @return Returns ERR_OK on success, others on failure.
109 */
HandleNotifyFormDelete(MessageParcel & data,MessageParcel & reply)110 int FormProviderStub::HandleNotifyFormDelete(MessageParcel &data, MessageParcel &reply)
111 {
112 int64_t formId = data.ReadInt64();
113 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
114 if (!want) {
115 HILOG_ERROR("ReadParcelable<FormReqInfo> failed");
116 return ERR_APPEXECFWK_PARCEL_ERROR;
117 }
118
119 sptr<IRemoteObject> client = data.ReadRemoteObject();
120 if (client == nullptr) {
121 HILOG_ERROR("get remote object failed");
122 return ERR_APPEXECFWK_PARCEL_ERROR;
123 }
124
125 int32_t result = NotifyFormDelete(formId, *want, client);
126 reply.WriteInt32(result);
127 return result;
128 }
129 /**
130 * @brief handle NotifyFormsDelete message.
131 * @param data input param.
132 * @param reply output param.
133 * @return Returns ERR_OK on success, others on failure.
134 */
HandleNotifyFormsDelete(MessageParcel & data,MessageParcel & reply)135 int FormProviderStub::HandleNotifyFormsDelete(MessageParcel &data, MessageParcel &reply)
136 {
137 std::vector<int64_t> formIds;
138 bool ret = data.ReadInt64Vector(&formIds);
139 if (ret) {
140 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
141 if (!want) {
142 HILOG_ERROR("ReadParcelable<FormReqInfo> failed");
143 return ERR_APPEXECFWK_PARCEL_ERROR;
144 }
145
146 sptr<IRemoteObject> client = data.ReadRemoteObject();
147 if (client == nullptr) {
148 HILOG_ERROR("get remote object failed");
149 return ERR_APPEXECFWK_PARCEL_ERROR;
150 }
151
152 int32_t result = NotifyFormsDelete(formIds, *want, client);
153 reply.WriteInt32(result);
154 return result;
155 }
156
157 return ERR_INVALID_DATA;
158 }
159 /**
160 * @brief handle NotifyFormUpdate message.
161 * @param data input param.
162 * @param reply output param.
163 * @return Returns ERR_OK on success, others on failure.
164 */
HandleNotifyFormUpdate(MessageParcel & data,MessageParcel & reply)165 int FormProviderStub::HandleNotifyFormUpdate(MessageParcel &data, MessageParcel &reply)
166 {
167 int64_t formId = data.ReadInt64();
168
169 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
170 if (!want) {
171 HILOG_ERROR("ReadParcelable<Want> failed");
172 return ERR_APPEXECFWK_PARCEL_ERROR;
173 }
174
175 sptr<IRemoteObject> client = data.ReadRemoteObject();
176 if (client == nullptr) {
177 HILOG_ERROR("get remote object failed");
178 return ERR_APPEXECFWK_PARCEL_ERROR;
179 }
180
181 int32_t result = NotifyFormUpdate(formId, *want, client);
182 reply.WriteInt32(result);
183 return result;
184 }
185
186 /**
187 * @brief handle EventNotify message.
188 * @param data input param.
189 * @param reply output param.
190 * @return Returns ERR_OK on success, others on failure.
191 */
HandleEventNotify(MessageParcel & data,MessageParcel & reply)192 int FormProviderStub::HandleEventNotify(MessageParcel &data, MessageParcel &reply)
193 {
194 std::vector<int64_t> formIds;
195 bool ret = data.ReadInt64Vector(&formIds);
196 if (ret) {
197 int32_t formVisibleType = data.ReadInt32();
198
199 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
200 if (!want) {
201 HILOG_ERROR("ReadParcelable<Want> failed");
202 return ERR_APPEXECFWK_PARCEL_ERROR;
203 }
204
205 sptr<IRemoteObject> client = data.ReadRemoteObject();
206 if (client == nullptr) {
207 HILOG_ERROR("get remote object failed");
208 return ERR_APPEXECFWK_PARCEL_ERROR;
209 }
210
211 int32_t result = EventNotify(formIds, formVisibleType, *want, client);
212 reply.WriteInt32(result);
213 return result;
214 }
215
216 return ERR_INVALID_DATA;
217 }
218
219 /**
220 * @brief handle NotifyFormCastTempForm message.
221 * @param data input param.
222 * @param reply output param.
223 * @return Returns ERR_OK on success, others on failure.
224 */
HandleNotifyFormCastTempForm(MessageParcel & data,MessageParcel & reply)225 int FormProviderStub::HandleNotifyFormCastTempForm(MessageParcel &data, MessageParcel &reply)
226 {
227 int64_t formId = data.ReadInt64();
228
229 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
230 if (!want) {
231 HILOG_ERROR("ReadParcelable<Want> failed");
232 return ERR_APPEXECFWK_PARCEL_ERROR;
233 }
234
235 sptr<IRemoteObject> client = data.ReadRemoteObject();
236 if (client == nullptr) {
237 HILOG_ERROR("get remote object failed");
238 return ERR_APPEXECFWK_PARCEL_ERROR;
239 }
240
241 int32_t result = NotifyFormCastTempForm(formId, *want, client);
242 reply.WriteInt32(result);
243 return result;
244 }
245
246 /**
247 * @brief handle NotifyConfigurationUpdate message.
248 * @param data input param.
249 * @param reply output param.
250 * @return Returns ERR_OK on success, others on failure.
251 */
HandleNotifyConfigurationUpdate(MessageParcel & data,MessageParcel & reply)252 int FormProviderStub::HandleNotifyConfigurationUpdate(MessageParcel &data, MessageParcel &reply)
253 {
254 std::unique_ptr<AppExecFwk::Configuration> configuration(data.ReadParcelable<AppExecFwk::Configuration>());
255 HILOG_INFO("Call.");
256 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
257 if (!want) {
258 HILOG_ERROR("ReadParcelable<Want> failed");
259 return ERR_APPEXECFWK_PARCEL_ERROR;
260 }
261
262 sptr<IRemoteObject> client = data.ReadRemoteObject();
263 if (client == nullptr) {
264 HILOG_ERROR("get remote object failed");
265 return ERR_APPEXECFWK_PARCEL_ERROR;
266 }
267
268 int32_t result = NotifyConfigurationUpdate(*configuration, *want, client);
269 reply.WriteInt32(result);
270 return result;
271 }
272
273 /**
274 * @brief handle FireFormEvent message.
275 * @param data input param.
276 * @param reply output param.
277 * @return Returns ERR_OK on success, others on failure.
278 */
HandleFireFormEvent(MessageParcel & data,MessageParcel & reply)279 int FormProviderStub::HandleFireFormEvent(MessageParcel &data, MessageParcel &reply)
280 {
281 int64_t formId = data.ReadInt64();
282 std::string message = data.ReadString();
283 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
284 if (!want) {
285 HILOG_ERROR("get want failed");
286 return ERR_APPEXECFWK_PARCEL_ERROR;
287 }
288
289 sptr<IRemoteObject> client = data.ReadRemoteObject();
290 if (client == nullptr) {
291 HILOG_ERROR("get remote object failed");
292 return ERR_APPEXECFWK_PARCEL_ERROR;
293 }
294
295 int32_t result = FireFormEvent(formId, message, *want, client);
296 reply.WriteInt32(result);
297 return result;
298 }
299 /**
300 * @brief handle AcquireState message.
301 * @param data input param.
302 * @param reply output param.
303 * @return Returns ERR_OK on success, others on failure.
304 */
HandleAcquireState(MessageParcel & data,MessageParcel & reply)305 int FormProviderStub::HandleAcquireState(MessageParcel &data, MessageParcel &reply)
306 {
307 std::unique_ptr<Want> wantArg(data.ReadParcelable<Want>());
308 if (!wantArg) {
309 HILOG_ERROR("ReadParcelable<Want> failed");
310 return ERR_APPEXECFWK_PARCEL_ERROR;
311 }
312 std::string provider = data.ReadString();
313 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
314 if (!want) {
315 HILOG_ERROR("ReadParcelable<Want> failed");
316 return ERR_APPEXECFWK_PARCEL_ERROR;
317 }
318 sptr<IRemoteObject> client = data.ReadRemoteObject();
319 if (client == nullptr) {
320 HILOG_ERROR("get remote object failed");
321 return ERR_APPEXECFWK_PARCEL_ERROR;
322 }
323 int32_t result = AcquireState(*wantArg, provider, *want, client);
324 reply.WriteInt32(result);
325 return result;
326 }
327
HandleAcquireShareFormData(MessageParcel & data,MessageParcel & reply)328 int32_t FormProviderStub::HandleAcquireShareFormData(MessageParcel &data, MessageParcel &reply)
329 {
330 auto formId = data.ReadInt64();
331 auto remoteDeviceId = data.ReadString();
332 auto remoteObj = data.ReadRemoteObject();
333 if (remoteObj == nullptr) {
334 HILOG_ERROR("get remoteObject failed");
335 return ERR_APPEXECFWK_PARCEL_ERROR;
336 }
337
338 auto requestCode = data.ReadInt64();
339 auto result = AcquireShareFormData(formId, remoteDeviceId, remoteObj, requestCode);
340 if (!reply.WriteInt32(result)) {
341 HILOG_ERROR("write result failed");
342 return ERR_APPEXECFWK_PARCEL_ERROR;
343 }
344
345 return ERR_OK;
346 }
347
HandleAcquireFormData(MessageParcel & data,MessageParcel & reply)348 int32_t FormProviderStub::HandleAcquireFormData(MessageParcel &data, MessageParcel &reply)
349 {
350 auto formId = data.ReadInt64();
351 auto remoteObj = data.ReadRemoteObject();
352 if (remoteObj == nullptr) {
353 HILOG_ERROR("get remoteObject failed");
354 return ERR_APPEXECFWK_PARCEL_ERROR;
355 }
356
357 auto requestCode = data.ReadInt64();
358 auto result = AcquireFormData(formId, remoteObj, requestCode);
359 if (!reply.WriteInt32(result)) {
360 HILOG_ERROR("write result failed");
361 return ERR_APPEXECFWK_PARCEL_ERROR;
362 }
363
364 return ERR_OK;
365 }
366
HandleNotifyFormLocationUpdate(MessageParcel & data,MessageParcel & reply)367 int32_t FormProviderStub::HandleNotifyFormLocationUpdate(MessageParcel &data, MessageParcel &reply)
368 {
369 auto formId = data.ReadInt64();
370 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
371 if (!want) {
372 HILOG_ERROR("ReadParcelable<Want> failed");
373 return ERR_APPEXECFWK_PARCEL_ERROR;
374 }
375 auto remoteObj = data.ReadRemoteObject();
376 if (remoteObj == nullptr) {
377 HILOG_ERROR("get remoteObject failed");
378 return ERR_APPEXECFWK_PARCEL_ERROR;
379 }
380 auto result = NotifyFormLocationUpdate(formId, *want, remoteObj);
381 if (!reply.WriteInt32(result)) {
382 HILOG_ERROR("write result failed");
383 return ERR_APPEXECFWK_PARCEL_ERROR;
384 }
385
386 return ERR_OK;
387 }
388
HandleNotifySizeChanged(MessageParcel & data,MessageParcel & reply)389 int32_t FormProviderStub::HandleNotifySizeChanged(MessageParcel &data, MessageParcel &reply)
390 {
391 HILOG_INFO("Call.");
392 int64_t formId = data.ReadInt64();
393 int32_t newDimension = data.ReadInt32();
394 std::unique_ptr<Rect> newRect(data.ReadParcelable<Rect>());
395 if (newRect == nullptr) {
396 HILOG_ERROR("Read newRect failed");
397 return ERR_APPEXECFWK_PARCEL_ERROR;
398 }
399 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
400 if (!want) {
401 HILOG_ERROR("ReadParcelable<Want> failed");
402 return ERR_APPEXECFWK_PARCEL_ERROR;
403 }
404 auto remoteObj = data.ReadRemoteObject();
405 if (remoteObj == nullptr) {
406 HILOG_ERROR("get remoteObject failed");
407 return ERR_APPEXECFWK_PARCEL_ERROR;
408 }
409 auto result = NotifySizeChanged(formId, newDimension, *newRect, *want, remoteObj);
410 if (!reply.WriteInt32(result)) {
411 HILOG_ERROR("write result failed");
412 return ERR_APPEXECFWK_PARCEL_ERROR;
413 }
414 return ERR_OK;
415 }
416 } // namespace AppExecFwk
417 } // namespace OHOS