1 /*
2 * Copyright (c) 2021-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 #include "form_provider_proxy.h"
16 #include "appexecfwk_errors.h"
17 #include "string_ex.h"
18
19 namespace OHOS {
20 namespace AppExecFwk {
21 namespace {
22 static constexpr int32_t MAX_ALLOW_SIZE = 8 * 1024;
23 }
AcquireProviderFormInfo(const FormJsInfo & formJsInfo,const Want & want,const sptr<IRemoteObject> & callerToken)24 int FormProviderProxy::AcquireProviderFormInfo(
25 const FormJsInfo &formJsInfo,
26 const Want &want,
27 const sptr<IRemoteObject> &callerToken)
28 {
29 int error;
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option(MessageOption::TF_ASYNC);
33
34 if (!WriteInterfaceToken(data)) {
35 HILOG_ERROR("write interface token failed");
36 return ERR_APPEXECFWK_PARCEL_ERROR;
37 }
38 if (!data.WriteParcelable(&formJsInfo)) {
39 HILOG_ERROR("write formJsInfo error");
40 return ERR_APPEXECFWK_PARCEL_ERROR;
41 }
42 if (!data.WriteParcelable(&want)) {
43 HILOG_ERROR("write want fail");
44 return ERR_APPEXECFWK_PARCEL_ERROR;
45 }
46
47 if (!data.WriteRemoteObject(callerToken)) {
48 HILOG_ERROR("write callerToken fail");
49 return ERR_APPEXECFWK_PARCEL_ERROR;
50 }
51
52 error = SendTransactCmd(
53 IFormProvider::Message::FORM_ACQUIRE_PROVIDER_FORM_INFO,
54 data,
55 reply,
56 option);
57 if (error != ERR_OK) {
58 HILOG_ERROR("SendRequest:%{public}d failed", error);
59 return error;
60 }
61 return ERR_OK;
62 }
63
64 /**
65 * @brief Notify provider when the form was deleted.
66 * @param formIds The id list of forms.
67 * @param want Indicates the structure containing form info.
68 * @param callerToken Caller ability token.
69 * @return Returns ERR_OK on success, others on failure.
70 */
NotifyFormDelete(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)71 int FormProviderProxy::NotifyFormDelete(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken)
72 {
73 int error;
74 MessageParcel data;
75 MessageParcel reply;
76 MessageOption option(MessageOption::TF_ASYNC);
77
78 if (!WriteInterfaceToken(data)) {
79 HILOG_ERROR("error to write interface token");
80 return ERR_APPEXECFWK_PARCEL_ERROR;
81 }
82 if (!data.WriteInt64(formId)) {
83 HILOG_ERROR("error to write formId");
84 return ERR_APPEXECFWK_PARCEL_ERROR;
85 }
86 if (!data.WriteParcelable(&want)) {
87 HILOG_ERROR("error to write want");
88 return ERR_APPEXECFWK_PARCEL_ERROR;
89 }
90 if (!data.WriteRemoteObject(callerToken)) {
91 HILOG_ERROR("error to write callerToken");
92 return ERR_APPEXECFWK_PARCEL_ERROR;
93 }
94
95 error = SendTransactCmd(
96 IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_DELETE,
97 data,
98 reply,
99 option);
100 if (error != ERR_OK) {
101 HILOG_ERROR("SendRequest:%{public}d failed", error);
102 return error;
103 }
104 return ERR_OK;
105 }
106 /**
107 * @brief Notify provider when the forms was deleted.
108 * @param formIds The id list of forms.
109 * @param want Indicates the structure containing form info.
110 * @param callerToken Caller ability token.
111 * @return Returns ERR_OK on success, others on failure.
112 */
NotifyFormsDelete(const std::vector<int64_t> & formIds,const Want & want,const sptr<IRemoteObject> & callerToken)113 int FormProviderProxy::NotifyFormsDelete(
114 const std::vector<int64_t> &formIds,
115 const Want &want,
116 const sptr<IRemoteObject> &callerToken)
117 {
118 int error;
119 MessageParcel data;
120 MessageParcel reply;
121 MessageOption option(MessageOption::TF_ASYNC);
122
123 if (!WriteInterfaceToken(data)) {
124 HILOG_ERROR("write interface token failed");
125 return ERR_APPEXECFWK_PARCEL_ERROR;
126 }
127 if (!data.WriteInt64Vector(formIds)) {
128 HILOG_ERROR("write formIds failed");
129 return ERR_APPEXECFWK_PARCEL_ERROR;
130 }
131 if (!data.WriteParcelable(&want)) {
132 HILOG_ERROR("write to want error");
133 return ERR_APPEXECFWK_PARCEL_ERROR;
134 }
135 if (!data.WriteRemoteObject(callerToken)) {
136 HILOG_ERROR("write to callerToken error");
137 return ERR_APPEXECFWK_PARCEL_ERROR;
138 }
139
140 error = SendTransactCmd(
141 IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORMS_DELETE,
142 data,
143 reply,
144 option);
145 if (error != ERR_OK) {
146 HILOG_ERROR("SendRequest:%{public}d failed", error);
147 return error;
148 }
149 return ERR_OK;
150 }
151
152 /**
153 * @brief Notify provider when the form need update.
154 * @param formId The Id of the form.
155 * @param want Indicates the structure containing form info.
156 * @param callerToken Caller ability token.
157 * @return Returns ERR_OK on success, others on failure.
158 */
NotifyFormUpdate(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)159 int FormProviderProxy::NotifyFormUpdate(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken)
160 {
161 int error;
162 MessageParcel data;
163 MessageParcel reply;
164 MessageOption option(MessageOption::TF_ASYNC);
165
166 if (!WriteInterfaceToken(data)) {
167 HILOG_ERROR("write interface token failed");
168 return ERR_APPEXECFWK_PARCEL_ERROR;
169 }
170 if (!data.WriteInt64(formId)) {
171 HILOG_ERROR("write formId failed");
172 return ERR_APPEXECFWK_PARCEL_ERROR;
173 }
174
175 if (!data.WriteParcelable(&want)) {
176 HILOG_ERROR("write want failed");
177 return ERR_APPEXECFWK_PARCEL_ERROR;
178 }
179
180 if (!data.WriteRemoteObject(callerToken)) {
181 HILOG_ERROR("write callerToken failed");
182 return ERR_APPEXECFWK_PARCEL_ERROR;
183 }
184
185 error = SendTransactCmd(
186 IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_UPDATE,
187 data,
188 reply,
189 option);
190 if (error != ERR_OK) {
191 HILOG_ERROR("SendRequest:%{public}d failed", error);
192 return error;
193 }
194 return ERR_OK;
195 }
196
197 /**
198 * @brief Event notify when change the form visible.
199 *
200 * @param formIds The vector of form ids.
201 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
202 * @param want Indicates the structure containing form info.
203 * @param callerToken Caller ability token.
204 * @return Returns ERR_OK on success, others on failure.
205 */
EventNotify(const std::vector<int64_t> & formIds,const int32_t formVisibleType,const Want & want,const sptr<IRemoteObject> & callerToken)206 int FormProviderProxy::EventNotify(const std::vector<int64_t> &formIds, const int32_t formVisibleType,
207 const Want &want, const sptr<IRemoteObject> &callerToken)
208 {
209 int error;
210 MessageParcel data;
211 MessageParcel reply;
212 MessageOption option(MessageOption::TF_ASYNC);
213
214 if (!WriteInterfaceToken(data)) {
215 HILOG_ERROR("write interface token failed");
216 return ERR_APPEXECFWK_PARCEL_ERROR;
217 }
218
219 if (!data.WriteInt64Vector(formIds)) {
220 HILOG_ERROR("fail write formIds");
221 return ERR_APPEXECFWK_PARCEL_ERROR;
222 }
223
224 if (!data.WriteInt32(formVisibleType)) {
225 HILOG_ERROR("fail write formVisibleType");
226 return ERR_APPEXECFWK_PARCEL_ERROR;
227 }
228
229 if (!data.WriteParcelable(&want)) {
230 HILOG_ERROR("errpr to write want");
231 return ERR_APPEXECFWK_PARCEL_ERROR;
232 }
233
234 if (!data.WriteRemoteObject(callerToken)) {
235 HILOG_ERROR("error to write callerToken");
236 return ERR_APPEXECFWK_PARCEL_ERROR;
237 }
238
239 error = SendTransactCmd(
240 IFormProvider::Message::FORM_PROVIDER_EVENT_NOTIFY,
241 data,
242 reply,
243 option);
244 if (error != ERR_OK) {
245 HILOG_ERROR("SendRequest:%{public}d failed", error);
246 return error;
247 }
248 return ERR_OK;
249 }
250
251 /**
252 * @brief Notify provider when the temp form was cast to normal form.
253 * @param formId The Id of the form to update.
254 * @param want Indicates the structure containing form info.
255 * @param callerToken Caller ability token.
256 * @return Returns ERR_OK on success, others on failure.
257 */
NotifyFormCastTempForm(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)258 int FormProviderProxy::NotifyFormCastTempForm(
259 const int64_t formId,
260 const Want &want,
261 const sptr<IRemoteObject> &callerToken)
262 {
263 int error;
264 MessageParcel data;
265 MessageParcel reply;
266 MessageOption option(MessageOption::TF_ASYNC);
267
268 if (!WriteInterfaceToken(data)) {
269 HILOG_ERROR("write interface token failed");
270 return ERR_APPEXECFWK_PARCEL_ERROR;
271 }
272
273 if (!data.WriteInt64(formId)) {
274 HILOG_ERROR("write formId failed");
275 return ERR_APPEXECFWK_PARCEL_ERROR;
276 }
277 if (!data.WriteParcelable(&want)) {
278 HILOG_ERROR("write want failed");
279 return ERR_APPEXECFWK_PARCEL_ERROR;
280 }
281 if (!data.WriteRemoteObject(callerToken)) {
282 HILOG_ERROR("write callerToken failed");
283 return ERR_APPEXECFWK_PARCEL_ERROR;
284 }
285
286 error = SendTransactCmd(
287 IFormProvider::Message::FORM_PROVIDER_NOTIFY_TEMP_FORM_CAST,
288 data,
289 reply,
290 option);
291 if (error != ERR_OK) {
292 HILOG_ERROR("SendRequest:%{public}d failed", error);
293 return error;
294 }
295 return ERR_OK;
296 }
297
298 /**
299 * @brief Notify provider when system configuration changed.
300 * @param configuration system configuration.
301 * @param want Indicates the structure containing form info.
302 * @param callerToken Caller ability token.
303 * @return Returns ERR_OK on success, others on failure.
304 */
NotifyConfigurationUpdate(const AppExecFwk::Configuration & configuration,const Want & want,const sptr<IRemoteObject> & callerToken)305 int FormProviderProxy::NotifyConfigurationUpdate(
306 const AppExecFwk::Configuration& configuration,
307 const Want &want,
308 const sptr<IRemoteObject> &callerToken)
309 {
310 int error;
311 MessageParcel data;
312 MessageParcel reply;
313 MessageOption option(MessageOption::TF_ASYNC);
314
315 if (!WriteInterfaceToken(data)) {
316 HILOG_ERROR("write interface token failed");
317 return ERR_APPEXECFWK_PARCEL_ERROR;
318 }
319
320 if (!data.WriteParcelable(&configuration)) {
321 HILOG_ERROR("write configuration failed");
322 return ERR_APPEXECFWK_PARCEL_ERROR;
323 }
324 if (!data.WriteParcelable(&want)) {
325 HILOG_ERROR("write want failed");
326 return ERR_APPEXECFWK_PARCEL_ERROR;
327 }
328 if (!data.WriteRemoteObject(callerToken)) {
329 HILOG_ERROR("write callerToken failed");
330 return ERR_APPEXECFWK_PARCEL_ERROR;
331 }
332
333 error = SendTransactCmd(
334 IFormProvider::Message::FORM_PROVIDER_NOTIFY_CONFIGURATION_UPDATE,
335 data,
336 reply,
337 option);
338 if (error != ERR_OK) {
339 HILOG_ERROR("SendRequest:%{public}d failed", error);
340 return error;
341 }
342 return ERR_OK;
343 }
344
345 /**
346 * @brief Fire message event to form provider.
347 * @param formId The Id of the from.
348 * @param message Event message.
349 * @param want The want of the request.
350 * @param callerToken Form provider proxy object.
351 * @return Returns ERR_OK on success, others on failure.
352 */
FireFormEvent(const int64_t formId,const std::string & message,const Want & want,const sptr<IRemoteObject> & callerToken)353 int FormProviderProxy::FireFormEvent(
354 const int64_t formId,
355 const std::string &message,
356 const Want &want,
357 const sptr<IRemoteObject> &callerToken)
358 {
359 MessageParcel data;
360 if (!WriteInterfaceToken(data)) {
361 HILOG_ERROR("write interface token failed");
362 return ERR_APPEXECFWK_PARCEL_ERROR;
363 }
364 if (!data.WriteInt64(formId)) {
365 HILOG_ERROR("write formId failed");
366 return ERR_APPEXECFWK_PARCEL_ERROR;
367 }
368 if (!data.WriteString(message)) {
369 HILOG_ERROR("fail write message");
370 return ERR_APPEXECFWK_PARCEL_ERROR;
371 }
372 if (!data.WriteParcelable(&want)) {
373 HILOG_ERROR("write to want failed");
374 return ERR_APPEXECFWK_PARCEL_ERROR;
375 }
376 if (!data.WriteRemoteObject(callerToken)) {
377 HILOG_ERROR("write to callerToken failed");
378 return ERR_APPEXECFWK_PARCEL_ERROR;
379 }
380 MessageParcel reply;
381 MessageOption option(MessageOption::TF_ASYNC);
382 int error = SendTransactCmd(
383 IFormProvider::Message::FORM_PROVIDER_EVENT_MESSAGE,
384 data,
385 reply,
386 option);
387 if (error != ERR_OK) {
388 HILOG_ERROR("SendRequest:%{public}d failed", error);
389 return error;
390 }
391 return ERR_OK;
392 }
393
394 /**
395 * @brief Acquire form state to form provider.
396 * @param wantArg The want of onAcquireFormState.
397 * @param provider The provider info.
398 * @param want The want of the request.
399 * @param callerToken Form provider proxy object.
400 * @return Returns ERR_OK on success, others on failure.
401 */
AcquireState(const Want & wantArg,const std::string & provider,const Want & want,const sptr<IRemoteObject> & callerToken)402 int FormProviderProxy::AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
403 const sptr<IRemoteObject> &callerToken)
404 {
405 int error;
406 MessageParcel data;
407 MessageParcel reply;
408 MessageOption option(MessageOption::TF_ASYNC);
409
410 if (!WriteInterfaceToken(data)) {
411 HILOG_ERROR("write interface token failed");
412 return ERR_APPEXECFWK_PARCEL_ERROR;
413 }
414
415 if (!data.WriteParcelable(&wantArg)) {
416 HILOG_ERROR("write wantArg failed");
417 return ERR_APPEXECFWK_PARCEL_ERROR;
418 }
419 if (!data.WriteString(provider)) {
420 HILOG_ERROR("write string failed");
421 return ERR_APPEXECFWK_PARCEL_ERROR;
422 }
423 if (!data.WriteParcelable(&want)) {
424 HILOG_ERROR("write want failed");
425 return ERR_APPEXECFWK_PARCEL_ERROR;
426 }
427 if (!data.WriteRemoteObject(callerToken)) {
428 HILOG_ERROR("write callerToken failed");
429 return ERR_APPEXECFWK_PARCEL_ERROR;
430 }
431
432 error = SendTransactCmd(
433 IFormProvider::Message::FORM_PROVIDER_NOTIFY_STATE_ACQUIRE,
434 data,
435 reply,
436 option);
437 if (error != ERR_OK) {
438 HILOG_ERROR("SendRequest:%{public}d failed", error);
439 return error;
440 }
441 return ERR_OK;
442 }
443
AcquireFormData(int64_t formId,const sptr<IRemoteObject> & formSupplyCallback,int64_t requestCode)444 int32_t FormProviderProxy::AcquireFormData(int64_t formId, const sptr<IRemoteObject> &formSupplyCallback,
445 int64_t requestCode)
446 {
447 MessageParcel data;
448 MessageParcel reply;
449 MessageOption option(MessageOption::TF_ASYNC);
450
451 if (!WriteInterfaceToken(data)) {
452 HILOG_ERROR("write interface token failed");
453 return ERR_APPEXECFWK_PARCEL_ERROR;
454 }
455
456 if (!data.WriteInt64(formId)) {
457 HILOG_ERROR("write formId failed");
458 return ERR_APPEXECFWK_PARCEL_ERROR;
459 }
460
461 if (!data.WriteRemoteObject(formSupplyCallback)) {
462 HILOG_ERROR("fail write formSupplyCallback");
463 return ERR_APPEXECFWK_PARCEL_ERROR;
464 }
465
466 if (!data.WriteInt64(requestCode)) {
467 HILOG_ERROR("write requestCode failed");
468 return ERR_APPEXECFWK_PARCEL_ERROR;
469 }
470 int32_t result = SendTransactCmd(
471 IFormProvider::Message::FORM_ACQUIRE_PROVIDER_FOMR_DATA,
472 data,
473 reply,
474 option);
475 if (result != ERR_OK) {
476 HILOG_ERROR("error to SendRequest:%{public}d", result);
477 return result;
478 }
479
480 auto retval = reply.ReadInt32();
481 if (retval != ERR_OK) {
482 HILOG_ERROR("error to replyData:%{public}d", retval);
483 }
484
485 return retval;
486 }
487
488 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)489 int FormProviderProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
490 {
491 int32_t infoSize = reply.ReadInt32();
492 if (infoSize < 0 || infoSize > MAX_ALLOW_SIZE) {
493 HILOG_ERROR("invalid size:%{public}d", infoSize);
494 return ERR_APPEXECFWK_PARCEL_ERROR;
495 }
496 for (int32_t i = 0; i < infoSize; i++) {
497 std::unique_ptr<T> info(reply.ReadParcelable<T>());
498 if (!info) {
499 HILOG_ERROR("read Parcelable infos failed");
500 return ERR_NULL_OBJECT;
501 }
502 parcelableInfos.emplace_back(*info);
503 }
504 HILOG_INFO("get success");
505 return ERR_OK;
506 }
507
WriteInterfaceToken(MessageParcel & data)508 bool FormProviderProxy::WriteInterfaceToken(MessageParcel &data)
509 {
510 if (!data.WriteInterfaceToken(FormProviderProxy::GetDescriptor())) {
511 HILOG_ERROR("write interface token failed");
512 return false;
513 }
514 return true;
515 }
516
AcquireShareFormData(int64_t formId,const std::string & remoteDeviceId,const sptr<IRemoteObject> & formSupplyCallback,int64_t requestCode)517 int32_t FormProviderProxy::AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
518 const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode)
519 {
520 MessageParcel data;
521 MessageParcel reply;
522 MessageOption option(MessageOption::TF_ASYNC);
523
524 if (!WriteInterfaceToken(data)) {
525 HILOG_ERROR("write interface token failed");
526 return ERR_APPEXECFWK_PARCEL_ERROR;
527 }
528
529 if (!data.WriteInt64(formId)) {
530 HILOG_ERROR("write formId failed");
531 return ERR_APPEXECFWK_PARCEL_ERROR;
532 }
533
534 if (!data.WriteString(remoteDeviceId)) {
535 HILOG_ERROR("fail write remoteDeviceId");
536 return ERR_APPEXECFWK_PARCEL_ERROR;
537 }
538
539 if (!data.WriteRemoteObject(formSupplyCallback)) {
540 HILOG_ERROR("fail write formSupplyCallback");
541 return ERR_APPEXECFWK_PARCEL_ERROR;
542 }
543
544 if (!data.WriteInt64(requestCode)) {
545 HILOG_ERROR("write requestCode failed");
546 return ERR_APPEXECFWK_PARCEL_ERROR;
547 }
548 int32_t result = SendTransactCmd(
549 IFormProvider::Message::FORM_ACQUIRE_PROVIDER_SHARE_FOMR_INFO,
550 data,
551 reply,
552 option);
553 if (result != ERR_OK) {
554 HILOG_ERROR("fail SendRequest:%{public}d", result);
555 return result;
556 }
557
558 auto retval = reply.ReadInt32();
559 if (retval != ERR_OK) {
560 HILOG_ERROR("fail replyData:%{public}d", retval);
561 }
562
563 return retval;
564 }
565
SendTransactCmd(IFormProvider::Message code,MessageParcel & data,MessageParcel & reply,MessageOption & option)566 int FormProviderProxy::SendTransactCmd(IFormProvider::Message code, MessageParcel &data,
567 MessageParcel &reply, MessageOption &option)
568 {
569 sptr<IRemoteObject> remote = Remote();
570 if (remote == nullptr) {
571 HILOG_ERROR("null remote");
572 return ERR_NULL_OBJECT;
573 }
574
575 int ret = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
576 if (ret != ERR_OK) {
577 HILOG_ERROR("SendRequest fail.code= %{public}d,ret= %{public}d", code, ret);
578 return ret;
579 }
580 return ERR_OK;
581 }
582
583 /**
584 * @brief Notify provider when the form need update.
585 * @param formId The Id of the form.
586 * @param want Indicates the structure containing form info.
587 * @param callerToken Caller ability token.
588 * @return Returns ERR_OK on success, others on failure.
589 */
NotifyFormLocationUpdate(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)590 int FormProviderProxy::NotifyFormLocationUpdate(const int64_t formId, const Want &want,
591 const sptr<IRemoteObject> &callerToken)
592 {
593 int error;
594 MessageParcel data;
595 MessageParcel reply;
596 MessageOption option(MessageOption::TF_ASYNC);
597
598 if (!WriteInterfaceToken(data)) {
599 HILOG_ERROR("write interface token failed");
600 return ERR_APPEXECFWK_PARCEL_ERROR;
601 }
602 if (!data.WriteInt64(formId)) {
603 HILOG_ERROR("write formId failed");
604 return ERR_APPEXECFWK_PARCEL_ERROR;
605 }
606
607 if (!data.WriteParcelable(&want)) {
608 HILOG_ERROR("write want failed");
609 return ERR_APPEXECFWK_PARCEL_ERROR;
610 }
611
612 if (!data.WriteRemoteObject(callerToken)) {
613 HILOG_ERROR("write callerToken failed");
614 return ERR_APPEXECFWK_PARCEL_ERROR;
615 }
616
617 error = SendTransactCmd(
618 IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_LOCATION_UPDATE,
619 data,
620 reply,
621 option);
622 if (error != ERR_OK) {
623 HILOG_ERROR("SendRequest:%{public}d failed", error);
624 return error;
625 }
626 return ERR_OK;
627 }
628
629 /**
630 * @brief Notify provider when the form size changed.
631 * @param formId The Id of the form to update.
632 * @param newDimension The dimension value to be updated.
633 * @param newRect The rect value to be updated.
634 * @param want Indicates the structure containing form info.
635 * @param callerToken Caller ability token.
636 * @return Returns ERR_OK on success, others on failure.
637 */
NotifySizeChanged(const int64_t formId,const int32_t newDimension,const Rect & newRect,const Want & want,const sptr<IRemoteObject> & callerToken)638 int FormProviderProxy::NotifySizeChanged(const int64_t formId, const int32_t newDimension, const Rect &newRect,
639 const Want &want, const sptr<IRemoteObject> &callerToken)
640 {
641 int error;
642 MessageParcel data;
643 MessageParcel reply;
644 MessageOption option(MessageOption::TF_ASYNC);
645 if (!WriteInterfaceToken(data)) {
646 HILOG_ERROR("write interface token failed");
647 return ERR_APPEXECFWK_PARCEL_ERROR;
648 }
649 if (!data.WriteInt64(formId)) {
650 HILOG_ERROR("write formId failed");
651 return ERR_APPEXECFWK_PARCEL_ERROR;
652 }
653 if (!data.WriteInt32(newDimension)) {
654 HILOG_ERROR("Write newDimension failed");
655 return ERR_APPEXECFWK_PARCEL_ERROR;
656 }
657 if (!data.WriteParcelable(&newRect)) {
658 HILOG_ERROR("write newRect failed");
659 return ERR_APPEXECFWK_PARCEL_ERROR;
660 }
661 if (!data.WriteParcelable(&want)) {
662 HILOG_ERROR("write want failed");
663 return ERR_APPEXECFWK_PARCEL_ERROR;
664 }
665 if (!data.WriteRemoteObject(callerToken)) {
666 HILOG_ERROR("write callerToken failed");
667 return ERR_APPEXECFWK_PARCEL_ERROR;
668 }
669 error = SendTransactCmd(
670 IFormProvider::Message::FORM_PROVIDER_NOTIFY_SIZE_CHANGED,
671 data,
672 reply,
673 option);
674 if (error != ERR_OK) {
675 HILOG_ERROR("SendRequest:%{public}d failed", error);
676 return error;
677 }
678 return ERR_OK;
679 }
680 } // namespace AppExecFwk
681 } // namespace OHOS
682