1 /*
2 * Copyright (c) 2021-2024 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 "form_mgr_proxy.h"
17
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_mgr_errors.h"
21 #include "running_form_info.h"
22 #include "string_ex.h"
23
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 static constexpr int32_t MAX_ALLOW_SIZE = 8 * 1024;
28 }
FormMgrProxy(const sptr<IRemoteObject> & impl)29 FormMgrProxy::FormMgrProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IFormMgr>(impl)
30 {}
31 /**
32 * @brief Add form with want, send want to form manager service.
33 * @param formId The Id of the forms to add.
34 * @param want The want of the form to add.
35 * @param callerToken Caller ability token.
36 * @param formInfo Form info.
37 * @return Returns ERR_OK on success, others on failure.
38 */
AddForm(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken,FormJsInfo & formInfo)39 int FormMgrProxy::AddForm(
40 const int64_t formId,
41 const Want &want,
42 const sptr<IRemoteObject> &callerToken,
43 FormJsInfo &formInfo)
44 {
45 MessageParcel data;
46 if (!WriteInterfaceToken(data)) {
47 HILOG_ERROR("write to interface token failed");
48 return ERR_APPEXECFWK_PARCEL_ERROR;
49 }
50 if (!data.WriteInt64(formId)) {
51 HILOG_ERROR("write to formId failed");
52 return ERR_APPEXECFWK_PARCEL_ERROR;
53 }
54 if (!data.WriteParcelable(&want)) {
55 HILOG_ERROR("write to want failed");
56 return ERR_APPEXECFWK_PARCEL_ERROR;
57 }
58
59 if (!data.WriteRemoteObject(callerToken)) {
60 HILOG_ERROR("write to callerTokenfailed");
61 return ERR_APPEXECFWK_PARCEL_ERROR;
62 }
63
64 int error = GetParcelableInfo<FormJsInfo>(IFormMgr::Message::FORM_MGR_ADD_FORM, data, formInfo);
65 if (error != ERR_OK) {
66 HILOG_ERROR("SendRequest:%{public}d failed", error);
67 }
68
69 return error;
70 }
71
72 /**
73 * @brief Add form with want, send want to form manager service.
74 * @param want The want of the form to add.
75 * @param runningFormInfo Running form info.
76 * @return Returns ERR_OK on success, others on failure.
77 */
CreateForm(const Want & want,RunningFormInfo & runningFormInfo)78 int FormMgrProxy::CreateForm(const Want &want, RunningFormInfo &runningFormInfo)
79 {
80 MessageParcel data;
81 if (!WriteInterfaceToken(data)) {
82 HILOG_ERROR("write to interface token failed");
83 return ERR_APPEXECFWK_PARCEL_ERROR;
84 }
85 if (!data.WriteParcelable(&want)) {
86 HILOG_ERROR("write to want failed");
87 return ERR_APPEXECFWK_PARCEL_ERROR;
88 }
89 int ret = GetParcelableInfo<RunningFormInfo>(IFormMgr::Message::FORM_MGR_CREATE_FORM, data, runningFormInfo);
90 if (ret != ERR_OK) {
91 HILOG_ERROR("fail SendRequest:%{public}d", ret);
92 }
93 return ret;
94 }
95
96 /**
97 * @brief Delete forms with formIds, send formIds to form manager service.
98 * @param formId The Id of the forms to delete.
99 * @param callerToken Caller ability token.
100 * @return Returns ERR_OK on success, others on failure.
101 */
DeleteForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)102 int FormMgrProxy::DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
103 {
104 MessageParcel data;
105 if (!WriteInterfaceToken(data)) {
106 HILOG_ERROR("write interface token failed");
107 return ERR_APPEXECFWK_PARCEL_ERROR;
108 }
109 if (!data.WriteInt64(formId)) {
110 HILOG_ERROR("write want failed");
111 return ERR_APPEXECFWK_PARCEL_ERROR;
112 }
113 if (!data.WriteRemoteObject(callerToken)) {
114 HILOG_ERROR("write callerToken failed");
115 return ERR_APPEXECFWK_PARCEL_ERROR;
116 }
117 MessageParcel reply;
118 MessageOption option;
119 int error = SendTransactCmd(
120 IFormMgr::Message::FORM_MGR_DELETE_FORM,
121 data,
122 reply,
123 option);
124 if (error != ERR_OK) {
125 HILOG_ERROR("SendRequest:%{public}d failed", error);
126 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
127 }
128 return reply.ReadInt32();
129 }
130
StopRenderingForm(const int64_t formId,const std::string & compId)131 int FormMgrProxy::StopRenderingForm(const int64_t formId, const std::string &compId)
132 {
133 MessageParcel data;
134 if (!WriteInterfaceToken(data)) {
135 HILOG_ERROR("write interface token failed");
136 return ERR_APPEXECFWK_PARCEL_ERROR;
137 }
138 if (!data.WriteInt64(formId)) {
139 HILOG_ERROR("write want failed");
140 return ERR_APPEXECFWK_PARCEL_ERROR;
141 }
142 if (!data.WriteString(compId)) {
143 HILOG_ERROR("write compId failed");
144 return ERR_APPEXECFWK_PARCEL_ERROR;
145 }
146 MessageParcel reply;
147 MessageOption option;
148 int error = SendTransactCmd(
149 IFormMgr::Message::FORM_MGR_STOP_RENDERING_FORM,
150 data,
151 reply,
152 option);
153 if (error != ERR_OK) {
154 HILOG_ERROR("SendRequest:%{public}d failed", error);
155 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
156 }
157 return reply.ReadInt32();
158 }
159
160 /**
161 * @brief Release forms with formIds, send formIds to form manager service.
162 * @param formId The Id of the forms to release.
163 * @param callerToken Caller ability token.
164 * @param delCache Delete Cache or not.
165 * @return Returns ERR_OK on success, others on failure.
166 */
ReleaseForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const bool delCache)167 int FormMgrProxy::ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache)
168 {
169 MessageParcel data;
170 if (!WriteInterfaceToken(data)) {
171 HILOG_ERROR("write interface token failed");
172 return ERR_APPEXECFWK_PARCEL_ERROR;
173 }
174 if (!data.WriteInt64(formId)) {
175 HILOG_ERROR("write want failed");
176 return ERR_APPEXECFWK_PARCEL_ERROR;
177 }
178 if (!data.WriteRemoteObject(callerToken)) {
179 HILOG_ERROR("write callerToken failed");
180 return ERR_APPEXECFWK_PARCEL_ERROR;
181 }
182 if (!data.WriteBool(delCache)) {
183 HILOG_ERROR("write delCache failed");
184 return ERR_APPEXECFWK_PARCEL_ERROR;
185 }
186
187 MessageParcel reply;
188 MessageOption option;
189 int error = SendTransactCmd(
190 IFormMgr::Message::FORM_MGR_RELEASE_FORM,
191 data,
192 reply,
193 option);
194 if (error != ERR_OK) {
195 HILOG_ERROR("SendRequest:%{public}d failed", error);
196 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
197 }
198 return reply.ReadInt32();
199 }
200
201 /**
202 * @brief Update form with formId, send formId to form manager service.
203 * @param formId The Id of the form to update.
204 * @param bundleName Provider ability bundleName.
205 * @param FormProviderData Form binding data.
206 * @return Returns ERR_OK on success, others on failure.
207 */
UpdateForm(const int64_t formId,const FormProviderData & FormProviderData)208 int FormMgrProxy::UpdateForm(const int64_t formId, const FormProviderData &FormProviderData)
209 {
210 MessageParcel data;
211 if (!WriteInterfaceToken(data)) {
212 HILOG_ERROR("write interface token failed");
213 return ERR_APPEXECFWK_PARCEL_ERROR;
214 }
215 if (!data.WriteInt64(formId)) {
216 HILOG_ERROR("write formId failed");
217 return ERR_APPEXECFWK_PARCEL_ERROR;
218 }
219 if (!data.WriteParcelable(&FormProviderData)) {
220 HILOG_ERROR("write formBindingData failed");
221 return ERR_APPEXECFWK_PARCEL_ERROR;
222 }
223 MessageParcel reply;
224 MessageOption option;
225 int error = SendTransactCmd(
226 IFormMgr::Message::FORM_MGR_UPDATE_FORM,
227 data,
228 reply,
229 option);
230 if (error != ERR_OK) {
231 HILOG_ERROR("SendRequest:%{public}d failed", error);
232 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
233 }
234 return reply.ReadInt32();
235 }
236
237 /**
238 * @brief Set next refresh time.
239 * @param formId The Id of the form to update.
240 * @param bundleName Provider ability bundleName.
241 * @param nextTime Next refresh time.
242 * @return Returns ERR_OK on success, others on failure.
243 */
SetNextRefreshTime(const int64_t formId,const int64_t nextTime)244 int FormMgrProxy::SetNextRefreshTime(const int64_t formId, const int64_t nextTime)
245 {
246 MessageParcel data;
247 MessageParcel reply;
248
249 if (!WriteInterfaceToken(data)) {
250 HILOG_ERROR("write interface token failed");
251 return ERR_APPEXECFWK_PARCEL_ERROR;
252 }
253 if (!data.WriteInt64(formId)) {
254 HILOG_ERROR("write formId failed");
255 return ERR_APPEXECFWK_PARCEL_ERROR;
256 }
257 if (!data.WriteInt64(nextTime)) {
258 HILOG_ERROR("write nextTime failed");
259 return ERR_APPEXECFWK_PARCEL_ERROR;
260 }
261 MessageOption option;
262 int error = SendTransactCmd(
263 IFormMgr::Message::FORM_MGR_SET_NEXT_REFRESH_TIME,
264 data,
265 reply,
266 option);
267 if (error != ERR_OK) {
268 HILOG_ERROR("SendRequest:%{public}d failed", error);
269 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
270 }
271 return reply.ReadInt32();
272 }
273
ReleaseRenderer(int64_t formId,const std::string & compId)274 int FormMgrProxy::ReleaseRenderer(int64_t formId, const std::string &compId)
275 {
276 MessageParcel data;
277 MessageParcel reply;
278
279 if (!WriteInterfaceToken(data)) {
280 HILOG_ERROR("write interface token failed");
281 return ERR_APPEXECFWK_PARCEL_ERROR;
282 }
283 if (!data.WriteInt64(formId)) {
284 HILOG_ERROR("write formId failed");
285 return ERR_APPEXECFWK_PARCEL_ERROR;
286 }
287 if (!data.WriteString(compId)) {
288 HILOG_ERROR("write compId failed");
289 return ERR_APPEXECFWK_PARCEL_ERROR;
290 }
291 MessageOption option;
292 int error = SendTransactCmd(
293 IFormMgr::Message::FORM_MGR_RELEASE_RENDERER,
294 data,
295 reply,
296 option);
297 if (error != ERR_OK) {
298 HILOG_ERROR("SendRequest:%{public}d failed", error);
299 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
300 }
301 return reply.ReadInt32();
302 }
303
RequestPublishForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId)304 ErrCode FormMgrProxy::RequestPublishForm(Want &want, bool withFormBindingData,
305 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
306 {
307 MessageParcel data;
308 MessageParcel reply;
309
310 if (!WriteInterfaceToken(data)) {
311 HILOG_ERROR("write interface token failed");
312 return ERR_APPEXECFWK_PARCEL_ERROR;
313 }
314 if (!data.WriteParcelable(&want)) {
315 HILOG_ERROR("write want failed");
316 return ERR_APPEXECFWK_PARCEL_ERROR;
317 }
318 if (!data.WriteBool(withFormBindingData)) {
319 HILOG_ERROR("write withFormBindingData failed");
320 return ERR_APPEXECFWK_PARCEL_ERROR;
321 }
322 if (withFormBindingData) {
323 if (!data.WriteParcelable(formBindingData.get())) {
324 HILOG_ERROR("write formBindingData failed");
325 return ERR_APPEXECFWK_PARCEL_ERROR;
326 }
327 }
328 MessageOption option;
329 int32_t error = SendTransactCmd(
330 IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM,
331 data,
332 reply,
333 option);
334 if (error != ERR_OK) {
335 HILOG_ERROR("SendRequest:%{public}d failed", error);
336 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
337 }
338 ErrCode errCode = reply.ReadInt32();
339 if (errCode == ERR_OK) {
340 formId = reply.ReadInt64();
341 }
342 return errCode;
343 }
344
SetPublishFormResult(const int64_t formId,Constants::PublishFormResult & errorCodeInfo)345 ErrCode FormMgrProxy::SetPublishFormResult(const int64_t formId, Constants::PublishFormResult &errorCodeInfo)
346 {
347 MessageParcel data;
348 MessageParcel reply;
349
350 if (!WriteInterfaceToken(data)) {
351 HILOG_ERROR("write interface token failed");
352 return ERR_APPEXECFWK_PARCEL_ERROR;
353 }
354 if (!data.WriteInt64(formId)) {
355 HILOG_ERROR("write want failed");
356 return ERR_APPEXECFWK_PARCEL_ERROR;
357 }
358
359 if (!data.WriteString(errorCodeInfo.message)) {
360 HILOG_ERROR("fail write ErrorCode message");
361 return ERR_APPEXECFWK_PARCEL_ERROR;
362 }
363
364 if (!data.WriteInt32(static_cast<int32_t>(errorCodeInfo.code))) {
365 HILOG_ERROR("write ErrorCode failed");
366 return ERR_APPEXECFWK_PARCEL_ERROR;
367 }
368
369 MessageOption option;
370 int32_t error = SendTransactCmd(
371 IFormMgr::Message::FORM_MGR_PUBLISH_FORM_ERRCODE_RESULT,
372 data,
373 reply,
374 option);
375 if (error != ERR_OK) {
376 HILOG_ERROR("SendRequest:%{public}d failed", error);
377 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
378 }
379 return reply.ReadInt32();
380 }
381
AcquireAddFormResult(const int64_t formId)382 ErrCode FormMgrProxy::AcquireAddFormResult(const int64_t formId)
383 {
384 MessageParcel data;
385 MessageParcel reply;
386
387 if (!WriteInterfaceToken(data)) {
388 HILOG_ERROR("write interface token failed");
389 return ERR_APPEXECFWK_PARCEL_ERROR;
390 }
391 if (!data.WriteInt64(formId)) {
392 HILOG_ERROR("write want failed");
393 return ERR_APPEXECFWK_PARCEL_ERROR;
394 }
395
396 MessageOption option(MessageOption::TF_SYNC);
397 int32_t error = SendTransactCmd(
398 IFormMgr::Message::FORM_MGR_ACQUIRE_ADD_FORM_RESULT,
399 data,
400 reply,
401 option);
402 if (error != ERR_OK) {
403 HILOG_ERROR("SendRequest:%{public}d failed", error);
404 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
405 }
406 return reply.ReadInt32();
407 }
408
LifecycleUpdate(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,bool updateType)409 int FormMgrProxy::LifecycleUpdate(
410 const std::vector<int64_t> &formIds,
411 const sptr<IRemoteObject> &callerToken,
412 bool updateType)
413 {
414 MessageParcel data;
415 MessageParcel reply;
416
417 if (!WriteInterfaceToken(data)) {
418 HILOG_ERROR("write interface token failed");
419 return ERR_APPEXECFWK_PARCEL_ERROR;
420 }
421 if (!data.WriteInt64Vector(formIds)) {
422 HILOG_ERROR("write formId failed");
423 return ERR_APPEXECFWK_PARCEL_ERROR;
424 }
425 if (!data.WriteRemoteObject(callerToken)) {
426 HILOG_ERROR("write bundleName failed");
427 return ERR_APPEXECFWK_PARCEL_ERROR;
428 }
429 if (!data.WriteBool(updateType)) {
430 HILOG_ERROR("write nextTime failed");
431 return ERR_APPEXECFWK_PARCEL_ERROR;
432 }
433 MessageOption option;
434 int error = SendTransactCmd(
435 IFormMgr::Message::FORM_MGR_LIFECYCLE_UPDATE,
436 data,
437 reply,
438 option);
439 if (error != ERR_OK) {
440 HILOG_ERROR("SendRequest:%{public}d failed", error);
441 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
442 }
443
444 return reply.ReadInt32();
445 }
446 /**
447 * @brief Request form with formId and want, send formId and want to form manager service.
448 * @param formId The Id of the form to update.
449 * @param callerToken Caller ability token.
450 * @param want The want of the form to add.
451 * @return Returns ERR_OK on success, others on failure.
452 */
RequestForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const Want & want)453 int FormMgrProxy::RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want)
454 {
455 HILOG_INFO("call");
456
457 MessageParcel data;
458 if (!WriteInterfaceToken(data)) {
459 HILOG_ERROR("write interface token failed");
460 return ERR_APPEXECFWK_PARCEL_ERROR;
461 }
462 if (!data.WriteInt64(formId)) {
463 HILOG_ERROR("write formId failed");
464 return ERR_APPEXECFWK_PARCEL_ERROR;
465 }
466 if (!data.WriteRemoteObject(callerToken)) {
467 HILOG_ERROR("write callerToken failed");
468 return ERR_APPEXECFWK_PARCEL_ERROR;
469 }
470 if (!data.WriteParcelable(&want)) {
471 HILOG_ERROR("write want failed");
472 return ERR_APPEXECFWK_PARCEL_ERROR;
473 }
474
475 MessageParcel reply;
476 MessageOption option;
477 int error = SendTransactCmd(
478 IFormMgr::Message::FORM_MGR_REQUEST_FORM,
479 data,
480 reply,
481 option);
482 if (error != ERR_OK) {
483 HILOG_ERROR("SendRequest:%{public}d failed", error);
484 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
485 }
486 return reply.ReadInt32();
487 }
488
489 /**
490 * @brief Form visible/invisible notify, send formIds to form manager service.
491 * @param formIds The Id list of the forms to notify.
492 * @param callerToken Caller ability token.
493 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
494 * @return Returns ERR_OK on success, others on failure.
495 */
NotifyWhetherVisibleForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,const int32_t formVisibleType)496 int FormMgrProxy::NotifyWhetherVisibleForms(
497 const std::vector<int64_t> &formIds,
498 const sptr<IRemoteObject> &callerToken,
499 const int32_t formVisibleType)
500 {
501 MessageParcel data;
502 if (!WriteInterfaceToken(data)) {
503 HILOG_ERROR("write interface token failed");
504 return ERR_APPEXECFWK_PARCEL_ERROR;
505 }
506
507 if (!data.WriteInt64Vector(formIds)) {
508 HILOG_ERROR("write formIds failed");
509 return ERR_APPEXECFWK_PARCEL_ERROR;
510 }
511
512 if (!data.WriteRemoteObject(callerToken)) {
513 HILOG_ERROR("write callerToken failed");
514 return ERR_APPEXECFWK_PARCEL_ERROR;
515 }
516
517 if (!data.WriteInt32(formVisibleType)) {
518 HILOG_ERROR("fail write formVisibleType");
519 return ERR_APPEXECFWK_PARCEL_ERROR;
520 }
521
522 MessageParcel reply;
523 MessageOption option;
524 int error = SendTransactCmd(
525 IFormMgr::Message::FORM_MGR_NOTIFY_FORM_WHETHER_VISIBLE,
526 data,
527 reply,
528 option);
529 if (error != ERR_OK) {
530 HILOG_ERROR("SendRequest:%{public}d failed", error);
531 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
532 }
533 return reply.ReadInt32();
534 }
535
536 /**
537 * @brief Query whether has visible form by tokenId.
538 * @param tokenId Unique identification of application.
539 * @return Returns true if has visible form, false otherwise.
540 */
HasFormVisible(const uint32_t tokenId)541 bool FormMgrProxy::HasFormVisible(const uint32_t tokenId)
542 {
543 HILOG_DEBUG("call");
544
545 MessageParcel data;
546 if (!WriteInterfaceToken(data)) {
547 HILOG_ERROR("error to write interface token");
548 return false;
549 }
550 if (!data.WriteUint32(tokenId)) {
551 HILOG_ERROR("fail write tokenId");
552 return false;
553 }
554
555 // send request
556 MessageParcel reply;
557 MessageOption option;
558 int error = SendTransactCmd(
559 IFormMgr::Message::FORM_MGR_HAS_FORM_VISIBLE_WITH_TOKENID,
560 data,
561 reply,
562 option);
563 if (error != ERR_OK) {
564 HILOG_ERROR("SendRequest:%{public}d failed", error);
565 return false;
566 }
567
568 // retrieve and return result.
569 return reply.ReadBool();
570 }
571
572 /**
573 * @brief temp form to normal form.
574 * @param formId The Id of the form.
575 * @param callerToken Caller ability token.
576 * @return Returns ERR_OK on success, others on failure.
577 */
CastTempForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)578 int FormMgrProxy::CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
579 {
580 MessageParcel data;
581 if (!WriteInterfaceToken(data)) {
582 HILOG_ERROR("write interface token failed");
583 return ERR_APPEXECFWK_PARCEL_ERROR;
584 }
585 if (!data.WriteInt64(formId)) {
586 HILOG_ERROR("write want failed");
587 return ERR_APPEXECFWK_PARCEL_ERROR;
588 }
589 if (!data.WriteRemoteObject(callerToken)) {
590 HILOG_ERROR("callerToken is write failed");
591 return ERR_APPEXECFWK_PARCEL_ERROR;
592 }
593
594 MessageParcel reply;
595 MessageOption option;
596 int error = SendTransactCmd(
597 IFormMgr::Message::FORM_MGR_CAST_TEMP_FORM,
598 data,
599 reply,
600 option);
601 if (error != ERR_OK) {
602 HILOG_ERROR("SendRequest:%{public}d failed", error);
603 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
604 }
605 return reply.ReadInt32();
606 }
607 /**
608 * @brief Dump all of form storage infos.
609 * @param formInfos All of form storage infos.
610 * @return Returns ERR_OK on success, others on failure.
611 */
DumpStorageFormInfos(std::string & formInfos)612 int FormMgrProxy::DumpStorageFormInfos(std::string &formInfos)
613 {
614 MessageParcel data;
615 if (!WriteInterfaceToken(data)) {
616 HILOG_ERROR("write interface token failed");
617 return ERR_APPEXECFWK_PARCEL_ERROR;
618 }
619
620 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_STORAGE_FORM_INFOS, data, formInfos);
621 if (error != ERR_OK) {
622 HILOG_ERROR("GetStringInfo:%{public}d failed", error);
623 }
624
625 return error;
626 }
627 /**
628 * @brief Dump form info by a bundle name.
629 * @param bundleName The bundle name of form provider.
630 * @param formInfos Form infos.
631 * @return Returns ERR_OK on success, others on failure.
632 */
DumpFormInfoByBundleName(const std::string & bundleName,std::string & formInfos)633 int FormMgrProxy::DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos)
634 {
635 MessageParcel data;
636 if (!WriteInterfaceToken(data)) {
637 HILOG_ERROR("write interface token failed");
638 return ERR_APPEXECFWK_PARCEL_ERROR;
639 }
640
641 if (!data.WriteString(bundleName)) {
642 HILOG_ERROR("write bundleName failed");
643 return ERR_APPEXECFWK_PARCEL_ERROR;
644 }
645
646 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_NAME, data, formInfos);
647 if (error != ERR_OK) {
648 HILOG_ERROR("GetStringInfo:%{public}d failed", error);
649 }
650
651 return error;
652 }
653 /**
654 * @brief Dump form info by a bundle name.
655 * @param formId The id of the form.
656 * @param formInfo Form info.
657 * @return Returns ERR_OK on success, others on failure.
658 */
DumpFormInfoByFormId(const std::int64_t formId,std::string & formInfo)659 int FormMgrProxy::DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo)
660 {
661 MessageParcel data;
662 if (!WriteInterfaceToken(data)) {
663 HILOG_ERROR("write interface token failed");
664 return ERR_APPEXECFWK_PARCEL_ERROR;
665 }
666 if (!data.WriteInt64(formId)) {
667 HILOG_ERROR("write formId failed");
668 return ERR_APPEXECFWK_PARCEL_ERROR;
669 }
670
671 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID, data, formInfo);
672 if (error != ERR_OK) {
673 HILOG_ERROR("GetStringInfo:%{public}d failed", error);
674 }
675
676 return error;
677 }
678 /**
679 * @brief Dump timer info by form id.
680 * @param formId The id of the form.
681 * @param formInfo Form timer info.
682 * @return Returns ERR_OK on success, others on failure.
683 */
DumpFormTimerByFormId(const std::int64_t formId,std::string & isTimingService)684 int FormMgrProxy::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService)
685 {
686 MessageParcel data;
687 if (!WriteInterfaceToken(data)) {
688 HILOG_ERROR("write interface token failed");
689 return ERR_APPEXECFWK_PARCEL_ERROR;
690 }
691 if (!data.WriteInt64(formId)) {
692 HILOG_ERROR("write formId failed");
693 return ERR_APPEXECFWK_PARCEL_ERROR;
694 }
695
696 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID, data, isTimingService);
697 if (error != ERR_OK) {
698 HILOG_ERROR("GetStringInfo:%{public}d failed", error);
699 }
700
701 return error;
702 }
703 /**
704 * @brief Process js message event.
705 * @param formId Indicates the unique id of form.
706 * @param want information passed to supplier.
707 * @param callerToken Caller ability token.
708 * @return Returns true if execute success, false otherwise.
709 */
MessageEvent(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)710 int FormMgrProxy::MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken)
711 {
712 MessageParcel data;
713 if (!WriteInterfaceToken(data)) {
714 HILOG_ERROR("write interface token failed");
715 return ERR_APPEXECFWK_PARCEL_ERROR;
716 }
717 if (!data.WriteInt64(formId)) {
718 HILOG_ERROR("write formId failed");
719 return ERR_APPEXECFWK_PARCEL_ERROR;
720 }
721 if (!data.WriteParcelable(&want)) {
722 HILOG_ERROR("error to write want");
723 return ERR_APPEXECFWK_PARCEL_ERROR;
724 }
725
726 if (!data.WriteRemoteObject(callerToken)) {
727 HILOG_ERROR("error to write callerToken");
728 return ERR_APPEXECFWK_PARCEL_ERROR;
729 }
730
731 MessageParcel reply;
732 MessageOption option;
733 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_MESSAGE_EVENT,
734 data, reply, option);
735 if (error != ERR_OK) {
736 HILOG_ERROR("SendRequest:%{public}d failed", error);
737 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
738 }
739 return reply.ReadInt32();
740 }
741
742 /**
743 * @brief Process Background event.
744 * @param formId Indicates the unique id of form.
745 * @param want the want of the ability to start.
746 * @param callerToken Caller ability token.
747 * @return Returns true if execute success, false otherwise.
748 */
BackgroundEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)749 int FormMgrProxy::BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
750 {
751 MessageParcel data;
752 if (!WriteInterfaceToken(data)) {
753 HILOG_ERROR("write interfaceToken failed");
754 return ERR_APPEXECFWK_PARCEL_ERROR;
755 }
756 if (!data.WriteInt64(formId)) {
757 HILOG_ERROR("write formId failed");
758 return ERR_APPEXECFWK_PARCEL_ERROR;
759 }
760 if (!data.WriteParcelable(&want)) {
761 HILOG_ERROR("write want failed");
762 return ERR_APPEXECFWK_PARCEL_ERROR;
763 }
764
765 if (!data.WriteRemoteObject(callerToken)) {
766 HILOG_ERROR("write callerToken failed");
767 return ERR_APPEXECFWK_PARCEL_ERROR;
768 }
769
770 MessageParcel reply;
771 MessageOption option;
772 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_BACKGROUND_EVENT,
773 data, reply, option);
774 if (error != ERR_OK) {
775 HILOG_ERROR("SendRequest:%{public}d failed", error);
776 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
777 }
778 return reply.ReadInt32();
779 }
780
781 /**
782 * @brief Process js router event.
783 * @param formId Indicates the unique id of form.
784 * @param want the want of the ability to start.
785 * @param callerToken Caller ability token.
786 * @return Returns true if execute success, false otherwise.
787 */
RouterEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)788 int FormMgrProxy::RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
789 {
790 MessageParcel data;
791 if (!WriteInterfaceToken(data)) {
792 HILOG_ERROR("write to interface token error");
793 return ERR_APPEXECFWK_PARCEL_ERROR;
794 }
795 if (!data.WriteInt64(formId)) {
796 HILOG_ERROR("write to formId error");
797 return ERR_APPEXECFWK_PARCEL_ERROR;
798 }
799 if (!data.WriteParcelable(&want)) {
800 HILOG_ERROR("write to want error");
801 return ERR_APPEXECFWK_PARCEL_ERROR;
802 }
803
804 if (!data.WriteRemoteObject(callerToken)) {
805 HILOG_ERROR("write to callerToken error");
806 return ERR_APPEXECFWK_PARCEL_ERROR;
807 }
808
809 MessageParcel reply;
810 MessageOption option;
811 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ROUTER_EVENT,
812 data, reply, option);
813 if (error != ERR_OK) {
814 HILOG_ERROR("SendRequest:%{public}d failed", error);
815 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
816 }
817 return reply.ReadInt32();
818 }
819
820 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)821 int FormMgrProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
822 {
823 int32_t infoSize = reply.ReadInt32();
824 if (infoSize < 0 || infoSize > MAX_ALLOW_SIZE) {
825 HILOG_ERROR("invalid size = %{public}d", infoSize);
826 return ERR_APPEXECFWK_PARCEL_ERROR;
827 }
828 for (int32_t i = 0; i < infoSize; i++) {
829 std::unique_ptr<T> info(reply.ReadParcelable<T>());
830 if (!info) {
831 HILOG_ERROR("error to Read Parcelable infos");
832 return ERR_APPEXECFWK_PARCEL_ERROR;
833 }
834 parcelableInfos.emplace_back(*info);
835 }
836 HILOG_DEBUG("get parcelable infos success");
837 return ERR_OK;
838 }
WriteInterfaceToken(MessageParcel & data)839 bool FormMgrProxy::WriteInterfaceToken(MessageParcel &data)
840 {
841 if (!data.WriteInterfaceToken(IFormMgr::GetDescriptor())) {
842 HILOG_ERROR("write interface token failed");
843 return false;
844 }
845 return true;
846 }
GetStringInfo(IFormMgr::Message code,MessageParcel & data,std::string & stringInfo)847 int FormMgrProxy::GetStringInfo(IFormMgr::Message code, MessageParcel &data, std::string &stringInfo)
848 {
849 HILOG_DEBUG("GetStringInfo start");
850 int error;
851 MessageParcel reply;
852 MessageOption option(MessageOption::TF_SYNC);
853 error = SendTransactCmd(code, data, reply, option);
854 if (error != ERR_OK) {
855 return error;
856 }
857
858 error = reply.ReadInt32();
859 if (error != ERR_OK) {
860 HILOG_ERROR("error to read reply result");
861 return error;
862 }
863 std::vector<std::string> stringInfoList;
864 if (!reply.ReadStringVector(&stringInfoList)) {
865 HILOG_ERROR("fail read string vector from reply");
866 return false;
867 }
868 if (stringInfoList.empty()) {
869 HILOG_INFO("No string info");
870 return ERR_APPEXECFWK_FORM_COMMON_CODE;
871 }
872 for (const auto &info : stringInfoList) {
873 stringInfo += info;
874 }
875 HILOG_DEBUG("get string info success");
876 return ERR_OK;
877 }
GetFormsInfo(IFormMgr::Message code,MessageParcel & data,std::vector<FormInfo> & formInfos)878 int FormMgrProxy::GetFormsInfo(IFormMgr::Message code, MessageParcel &data, std::vector<FormInfo> &formInfos)
879 {
880 HILOG_DEBUG("GetFormsInfo start");
881 int error;
882 MessageParcel reply;
883 MessageOption option(MessageOption::TF_SYNC);
884 error = SendTransactCmd(code, data, reply, option);
885 if (error != ERR_OK) {
886 return error;
887 }
888
889 error = reply.ReadInt32();
890 if (error != ERR_OK) {
891 HILOG_ERROR("read reply result fail");
892 return error;
893 }
894
895 return GetParcelableInfos<FormInfo>(reply, formInfos);
896 }
897
GetPublishedFormInfoById(IFormMgr::Message code,MessageParcel & data,RunningFormInfo & formInfo)898 int FormMgrProxy::GetPublishedFormInfoById(IFormMgr::Message code, MessageParcel &data, RunningFormInfo &formInfo)
899 {
900 HILOG_DEBUG("GetPublishedFormInfoById start");
901
902 auto error = GetParcelableInfo<RunningFormInfo>(code, data, formInfo);
903 if (error != ERR_OK) {
904 HILOG_ERROR("get parcelable info failed");
905 }
906
907 return error;
908 }
909
GetPublishedFormInfos(IFormMgr::Message code,MessageParcel & data,std::vector<RunningFormInfo> & formInfos)910 int FormMgrProxy::GetPublishedFormInfos(IFormMgr::Message code, MessageParcel &data,
911 std::vector<RunningFormInfo> &formInfos)
912 {
913 HILOG_DEBUG("GetPublishedFormInfos start");
914 int error;
915 MessageParcel reply;
916 MessageOption option(MessageOption::TF_SYNC);
917 error = SendTransactCmd(code, data, reply, option);
918 if (error != ERR_OK) {
919 return error;
920 }
921
922 error = reply.ReadInt32();
923 if (error != ERR_OK) {
924 HILOG_ERROR("read reply result fail");
925 return error;
926 }
927
928 return GetParcelableInfos<RunningFormInfo>(reply, formInfos);
929 }
930
GetRunningFormInfos(IFormMgr::Message code,MessageParcel & data,std::vector<RunningFormInfo> & runningFormInfos)931 ErrCode FormMgrProxy::GetRunningFormInfos(IFormMgr::Message code, MessageParcel &data,
932 std::vector<RunningFormInfo> &runningFormInfos)
933 {
934 ErrCode error;
935 MessageParcel reply;
936 MessageOption option(MessageOption::TF_SYNC);
937 error = SendTransactCmd(code, data, reply, option);
938 if (error != ERR_OK) {
939 return error;
940 }
941
942 error = reply.ReadInt32();
943 if (error != ERR_OK) {
944 HILOG_ERROR("read replyResult failed");
945 return error;
946 }
947 return GetParcelableInfos<RunningFormInfo>(reply, runningFormInfos);
948 }
949
950 template<typename T>
GetParcelableInfo(IFormMgr::Message code,MessageParcel & data,T & parcelableInfo)951 int FormMgrProxy::GetParcelableInfo(IFormMgr::Message code, MessageParcel &data, T &parcelableInfo)
952 {
953 int error;
954 MessageParcel reply;
955 MessageOption option(MessageOption::TF_SYNC);
956 error = SendTransactCmd(code, data, reply, option);
957 if (error != ERR_OK) {
958 return error;
959 }
960
961 error = reply.ReadInt32();
962 if (error != ERR_OK) {
963 HILOG_ERROR("read reply result failed");
964 return error;
965 }
966
967 std::unique_ptr<T> info(reply.ReadParcelable<T>());
968 if (!info) {
969 HILOG_ERROR("readParcelableInfo failed");
970 return ERR_APPEXECFWK_PARCEL_ERROR;
971 }
972 parcelableInfo = *info;
973 HILOG_DEBUG("get parcelable info success");
974 return ERR_OK;
975 }
976
SendTransactCmd(IFormMgr::Message code,MessageParcel & data,MessageParcel & reply,MessageOption & option)977 int FormMgrProxy::SendTransactCmd(IFormMgr::Message code, MessageParcel &data,
978 MessageParcel &reply, MessageOption &option)
979 {
980 sptr<IRemoteObject> remote = Remote();
981 if (!remote) {
982 HILOG_ERROR("error to get remote object, cmd:%{public}d", code);
983 return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED;
984 }
985 int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
986 if (result != ERR_OK) {
987 HILOG_ERROR("error to SendRequest:%{public}d,cmd:%{public}d", result, code);
988 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
989 }
990 return ERR_OK;
991 }
992
993 /**
994 * @brief Delete the invalid forms.
995 * @param formIds Indicates the ID of the valid forms.
996 * @param callerToken Caller ability token.
997 * @param numFormsDeleted Returns the number of the deleted forms.
998 * @return Returns ERR_OK on success, others on failure.
999 */
DeleteInvalidForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,int32_t & numFormsDeleted)1000 int FormMgrProxy::DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
1001 int32_t &numFormsDeleted)
1002 {
1003 MessageParcel data;
1004 if (!WriteInterfaceToken(data)) {
1005 HILOG_ERROR("write interface token failed");
1006 return ERR_APPEXECFWK_PARCEL_ERROR;
1007 }
1008 if (!data.WriteInt64Vector(formIds)) {
1009 HILOG_ERROR("write vector formIds failed");
1010 return ERR_APPEXECFWK_PARCEL_ERROR;
1011 }
1012 if (!data.WriteRemoteObject(callerToken)) {
1013 HILOG_ERROR("error to write callerToken");
1014 return ERR_APPEXECFWK_PARCEL_ERROR;
1015 }
1016
1017 MessageParcel reply;
1018 MessageOption option;
1019 int error = SendTransactCmd(
1020 IFormMgr::Message::FORM_MGR_DELETE_INVALID_FORMS,
1021 data,
1022 reply,
1023 option);
1024 if (error != ERR_OK) {
1025 HILOG_ERROR("SendRequest:%{public}d failed", error);
1026 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1027 }
1028
1029 int32_t result = reply.ReadInt32();
1030 if (result != ERR_OK) {
1031 HILOG_ERROR("read reply result failed");
1032 return result;
1033 }
1034 numFormsDeleted = reply.ReadInt32();
1035 return result;
1036 }
1037
1038 /**
1039 * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
1040 * @param want Indicates a set of parameters to be transparently passed to the form provider.
1041 * @param callerToken Caller ability token.
1042 * @param stateInfo Returns the form's state info of the specify.
1043 * @return Returns ERR_OK on success, others on failure.
1044 */
AcquireFormState(const Want & want,const sptr<IRemoteObject> & callerToken,FormStateInfo & stateInfo)1045 int FormMgrProxy::AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo)
1046 {
1047 MessageParcel data;
1048 if (!WriteInterfaceToken(data)) {
1049 HILOG_ERROR("write interface token failed");
1050 return ERR_APPEXECFWK_PARCEL_ERROR;
1051 }
1052 if (!data.WriteParcelable(&want)) {
1053 HILOG_ERROR("write want failed");
1054 return ERR_APPEXECFWK_PARCEL_ERROR;
1055 }
1056 if (!data.WriteRemoteObject(callerToken)) {
1057 HILOG_ERROR("write callerToken failed");
1058 return ERR_APPEXECFWK_PARCEL_ERROR;
1059 }
1060
1061 MessageParcel reply;
1062 MessageOption option;
1063 int error = SendTransactCmd(
1064 IFormMgr::Message::FORM_MGR_ACQUIRE_FORM_STATE,
1065 data,
1066 reply,
1067 option);
1068 if (error != ERR_OK) {
1069 HILOG_ERROR("SendRequest:%{public}d failed", error);
1070 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1071 }
1072
1073 int32_t result = reply.ReadInt32();
1074 if (result != ERR_OK) {
1075 HILOG_ERROR("read reply result failed");
1076 return result;
1077 }
1078 stateInfo.state = (FormState)reply.ReadInt32();
1079 stateInfo.want = want;
1080 return result;
1081 }
1082
1083 /**
1084 * @brief Notify the form is visible or not.
1085 * @param formIds Indicates the ID of the forms.
1086 * @param isVisible Visible or not.
1087 * @param callerToken Host client.
1088 * @return Returns ERR_OK on success, others on failure.
1089 */
NotifyFormsVisible(const std::vector<int64_t> & formIds,bool isVisible,const sptr<IRemoteObject> & callerToken)1090 int FormMgrProxy::NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
1091 const sptr<IRemoteObject> &callerToken)
1092 {
1093 MessageParcel data;
1094 if (!WriteInterfaceToken(data)) {
1095 HILOG_ERROR("error to write interface token");
1096 return ERR_APPEXECFWK_PARCEL_ERROR;
1097 }
1098 if (!data.WriteInt64Vector(formIds)) {
1099 HILOG_ERROR("error to write vector formIds");
1100 return ERR_APPEXECFWK_PARCEL_ERROR;
1101 }
1102 if (!data.WriteBool(isVisible)) {
1103 HILOG_ERROR("fail write bool isVisible");
1104 return ERR_APPEXECFWK_PARCEL_ERROR;
1105 }
1106 if (!data.WriteRemoteObject(callerToken)) {
1107 HILOG_ERROR("write to callerToken failed ");
1108 return ERR_APPEXECFWK_PARCEL_ERROR;
1109 }
1110
1111 MessageParcel reply;
1112 MessageOption option;
1113 int error = SendTransactCmd(
1114 IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_VISIBLE,
1115 data,
1116 reply,
1117 option);
1118 if (error != ERR_OK) {
1119 HILOG_ERROR("SendRequest:%{public}d failed", error);
1120 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1121 }
1122
1123 int32_t result = reply.ReadInt32();
1124 if (result != ERR_OK) {
1125 HILOG_ERROR("read reply result failed");
1126 return result;
1127 }
1128 return result;
1129 }
1130
NotifyFormsPrivacyProtected(const std::vector<int64_t> & formIds,bool isProtected,const sptr<IRemoteObject> & callerToken)1131 int FormMgrProxy::NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
1132 const sptr<IRemoteObject> &callerToken)
1133 {
1134 MessageParcel data;
1135 if (!WriteInterfaceToken(data)) {
1136 HILOG_ERROR("write interface token failed");
1137 return ERR_APPEXECFWK_PARCEL_ERROR;
1138 }
1139 if (!data.WriteInt64Vector(formIds)) {
1140 HILOG_ERROR("write vector formIds failed");
1141 return ERR_APPEXECFWK_PARCEL_ERROR;
1142 }
1143 if (!data.WriteBool(isProtected)) {
1144 HILOG_ERROR("fail write bool isProtected");
1145 return ERR_APPEXECFWK_PARCEL_ERROR;
1146 }
1147 if (!data.WriteRemoteObject(callerToken)) {
1148 HILOG_ERROR("write callerToken error");
1149 return ERR_APPEXECFWK_PARCEL_ERROR;
1150 }
1151
1152 MessageParcel reply;
1153 MessageOption option;
1154 int error = SendTransactCmd(
1155 IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_PRIVACY_PROTECTED,
1156 data,
1157 reply,
1158 option);
1159 if (error != ERR_OK) {
1160 HILOG_ERROR("SendRequest:%{public}d failed", error);
1161 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1162 }
1163
1164 int32_t result = reply.ReadInt32();
1165 if (result != ERR_OK) {
1166 HILOG_ERROR("read reply result failed");
1167 return result;
1168 }
1169 return result;
1170 }
1171
1172 /**
1173 * @brief Notify the form is enable to be updated or not.
1174 * @param formIds Indicates the ID of the forms.
1175 * @param isEnableUpdate enable update or not.
1176 * @param callerToken Host client.
1177 * @return Returns ERR_OK on success, others on failure.
1178 */
NotifyFormsEnableUpdate(const std::vector<int64_t> & formIds,bool isEnableUpdate,const sptr<IRemoteObject> & callerToken)1179 int FormMgrProxy::NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
1180 const sptr<IRemoteObject> &callerToken)
1181 {
1182 MessageParcel data;
1183 if (!WriteInterfaceToken(data)) {
1184 HILOG_ERROR("write interface token failed");
1185 return ERR_APPEXECFWK_PARCEL_ERROR;
1186 }
1187 if (!data.WriteInt64Vector(formIds)) {
1188 HILOG_ERROR("write vector formIds failed");
1189 return ERR_APPEXECFWK_PARCEL_ERROR;
1190 }
1191 if (!data.WriteBool(isEnableUpdate)) {
1192 HILOG_ERROR("write bool isEnableUpdate failed");
1193 return ERR_APPEXECFWK_PARCEL_ERROR;
1194 }
1195 if (!data.WriteRemoteObject(callerToken)) {
1196 HILOG_ERROR("write error to callerToken");
1197 return ERR_APPEXECFWK_PARCEL_ERROR;
1198 }
1199
1200 MessageParcel reply;
1201 MessageOption option;
1202 int error = SendTransactCmd(
1203 IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_ENABLE_UPDATE,
1204 data,
1205 reply,
1206 option);
1207 if (error != ERR_OK) {
1208 HILOG_ERROR("SendRequest:%{public}d failed", error);
1209 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1210 }
1211
1212 int32_t result = reply.ReadInt32();
1213 if (result != ERR_OK) {
1214 HILOG_ERROR("read reply result failed");
1215 return result;
1216 }
1217 return result;
1218 }
1219
1220 /**
1221 * @brief Get All FormsInfo.
1222 * @param formInfos Return the forms' information of all forms provided.
1223 * @return Returns ERR_OK on success, others on failure.
1224 */
GetAllFormsInfo(std::vector<FormInfo> & formInfos)1225 int FormMgrProxy::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
1226 {
1227 MessageParcel data;
1228 if (!WriteInterfaceToken(data)) {
1229 HILOG_ERROR("write interface token failed");
1230 return ERR_APPEXECFWK_PARCEL_ERROR;
1231 }
1232
1233 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_ALL_FORMS_INFO, data, formInfos);
1234 if (error != ERR_OK) {
1235 HILOG_ERROR("fail GetAllFormsInfo:%{public}d", error);
1236 }
1237
1238 return error;
1239 }
1240
1241 /**
1242 * @brief Get forms info by bundle name .
1243 * @param bundleName Application name.
1244 * @param formInfos Return the forms' information of the specify application name.
1245 * @return Returns ERR_OK on success, others on failure.
1246 */
GetFormsInfoByApp(std::string & bundleName,std::vector<FormInfo> & formInfos)1247 int FormMgrProxy::GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos)
1248 {
1249 HILOG_INFO("bundleName:%{public}s", bundleName.c_str());
1250 MessageParcel data;
1251 if (!WriteInterfaceToken(data)) {
1252 HILOG_ERROR("write interface token failed");
1253 return ERR_APPEXECFWK_PARCEL_ERROR;
1254 }
1255
1256 if (!data.WriteString(bundleName)) {
1257 HILOG_ERROR("write bundleName failed");
1258 return ERR_APPEXECFWK_PARCEL_ERROR;
1259 }
1260
1261 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_APP, data, formInfos);
1262 if (error != ERR_OK) {
1263 HILOG_ERROR("fail GetFormsInfoByApp:%{public}d", error);
1264 }
1265
1266 return error;
1267 }
1268
1269 /**
1270 * @brief Get forms info by bundle name and module name.
1271 * @param bundleName bundle name.
1272 * @param moduleName Module name of hap.
1273 * @param formInfos Return the forms' information of the specify bundle name and module name.
1274 * @return Returns ERR_OK on success, others on failure.
1275 */
GetFormsInfoByModule(std::string & bundleName,std::string & moduleName,std::vector<FormInfo> & formInfos)1276 int FormMgrProxy::GetFormsInfoByModule(std::string &bundleName, std::string &moduleName,
1277 std::vector<FormInfo> &formInfos)
1278 {
1279 MessageParcel data;
1280 if (!WriteInterfaceToken(data)) {
1281 HILOG_ERROR("write interface token failed");
1282 return ERR_APPEXECFWK_PARCEL_ERROR;
1283 }
1284
1285 if (!data.WriteString(bundleName)) {
1286 HILOG_ERROR("write bundleName failed");
1287 return ERR_APPEXECFWK_PARCEL_ERROR;
1288 }
1289
1290 if (!data.WriteString(moduleName)) {
1291 HILOG_ERROR("fail write moduleName");
1292 return ERR_APPEXECFWK_PARCEL_ERROR;
1293 }
1294
1295 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_MODULE, data, formInfos);
1296 if (error != ERR_OK) {
1297 HILOG_ERROR("fail GetFormsInfoByModule:%{public}d", error);
1298 }
1299
1300 return error;
1301 }
1302
GetFormsInfoByFilter(const FormInfoFilter & filter,std::vector<FormInfo> & formInfos)1303 int FormMgrProxy::GetFormsInfoByFilter(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos)
1304 {
1305 MessageParcel data;
1306 if (!WriteInterfaceToken(data)) {
1307 HILOG_ERROR("write interface token failed");
1308 return ERR_APPEXECFWK_PARCEL_ERROR;
1309 }
1310
1311 if (!data.WriteString(filter.bundleName)) {
1312 HILOG_ERROR("write bundleName failed");
1313 return ERR_APPEXECFWK_PARCEL_ERROR;
1314 }
1315
1316 if (!data.WriteString(filter.moduleName)) {
1317 HILOG_ERROR("write moduleName failed");
1318 return ERR_APPEXECFWK_PARCEL_ERROR;
1319 }
1320
1321 if (!data.WriteInt32Vector(filter.supportDimensions)) {
1322 HILOG_ERROR("fail write vector supportDimensions");
1323 return ERR_APPEXECFWK_PARCEL_ERROR;
1324 }
1325
1326 if (!data.WriteInt32Vector(filter.supportShapes)) {
1327 HILOG_ERROR("fail write vector supportShapes");
1328 return ERR_APPEXECFWK_PARCEL_ERROR;
1329 }
1330
1331 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_FILTER, data, formInfos);
1332 if (error != ERR_OK) {
1333 HILOG_ERROR("fail GetFormsInfoByFilter:%{public}d", error);
1334 }
1335
1336 return error;
1337 }
1338
GetRunningFormInfos(bool isUnusedInclude,std::vector<RunningFormInfo> & runningFormInfos)1339 ErrCode FormMgrProxy::GetRunningFormInfos(bool isUnusedInclude, std::vector<RunningFormInfo> &runningFormInfos)
1340 {
1341 MessageParcel data;
1342 if (!WriteInterfaceToken(data)) {
1343 HILOG_ERROR("write interface token failed");
1344 return ERR_APPEXECFWK_PARCEL_ERROR;
1345 }
1346
1347 if (!data.WriteBool(isUnusedInclude)) {
1348 HILOG_ERROR("write isUnusedInclude failed");
1349 return ERR_APPEXECFWK_PARCEL_ERROR;
1350 }
1351
1352 ErrCode error = GetRunningFormInfos(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS, data, runningFormInfos);
1353 if (error != ERR_OK) {
1354 HILOG_ERROR("fail GetRunningFormInfos:%{public}d", error);
1355 }
1356 return error;
1357 }
1358
GetRunningFormInfosByBundleName(const std::string & bundleName,bool isUnusedInclude,std::vector<RunningFormInfo> & runningFormInfos)1359 ErrCode FormMgrProxy::GetRunningFormInfosByBundleName(
1360 const std::string &bundleName, bool isUnusedInclude, std::vector<RunningFormInfo> &runningFormInfos)
1361 {
1362 MessageParcel data;
1363 if (!WriteInterfaceToken(data)) {
1364 HILOG_ERROR("write interface token failed");
1365 return ERR_APPEXECFWK_PARCEL_ERROR;
1366 }
1367
1368 if (!data.WriteString(bundleName)) {
1369 HILOG_ERROR("write bundleName failed");
1370 return ERR_APPEXECFWK_PARCEL_ERROR;
1371 }
1372
1373 if (!data.WriteBool(isUnusedInclude)) {
1374 HILOG_ERROR("write isUnusedInclude failed");
1375 return ERR_APPEXECFWK_PARCEL_ERROR;
1376 }
1377
1378 ErrCode error = GetRunningFormInfos(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS_BY_BUNDLE,
1379 data, runningFormInfos);
1380 if (error != ERR_OK) {
1381 HILOG_ERROR("fail GetRunningFormInfosByBundleName:%{public}d", error);
1382 }
1383 return error;
1384 }
1385
GetFormsInfo(const FormInfoFilter & filter,std::vector<FormInfo> & formInfos)1386 int32_t FormMgrProxy::GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos)
1387 {
1388 HILOG_INFO("start");
1389 MessageParcel data;
1390 // write in token to help identify which stub to be called.
1391 if (!WriteInterfaceToken(data)) {
1392 HILOG_ERROR("write interface token failed");
1393 return ERR_APPEXECFWK_PARCEL_ERROR;
1394 }
1395 if (!data.WriteParcelable(&filter)) {
1396 HILOG_ERROR("fail write FormInfoFilter");
1397 return ERR_APPEXECFWK_PARCEL_ERROR;
1398 }
1399 // call private GetFormsInfo with Message which will send request to tell stub which handle function to be used.
1400 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO, data, formInfos);
1401 // formInfos should have been fulfilled at this point.
1402 if (error != ERR_OK) {
1403 HILOG_ERROR("fail GetAllFormsInfo:%{public}d", error);
1404 }
1405
1406 return error;
1407 }
1408
GetPublishedFormInfoById(const int64_t formId,RunningFormInfo & formInfo)1409 int32_t FormMgrProxy::GetPublishedFormInfoById(const int64_t formId, RunningFormInfo &formInfo)
1410 {
1411 HILOG_INFO("start");
1412 MessageParcel data;
1413 // write in token to help identify which stub to be called.
1414 if (!WriteInterfaceToken(data)) {
1415 HILOG_ERROR("write interface token failed");
1416 return ERR_APPEXECFWK_PARCEL_ERROR;
1417 }
1418 if (!data.WriteInt64(formId)) {
1419 HILOG_ERROR("write to formId error");
1420 return ERR_APPEXECFWK_PARCEL_ERROR;
1421 }
1422 int error = GetPublishedFormInfoById(IFormMgr::Message::FORM_MGR_GET_PUBLISHED_FORM_INFO_BY_ID, data, formInfo);
1423 // formInfos should have been fulfilled at this point.
1424 if (error != ERR_OK) {
1425 HILOG_ERROR("fail GetPublishedFormInfoById:%{public}d", error);
1426 }
1427
1428 return error;
1429 }
1430
GetPublishedFormInfos(std::vector<RunningFormInfo> & formInfos)1431 int32_t FormMgrProxy::GetPublishedFormInfos(std::vector<RunningFormInfo> &formInfos)
1432 {
1433 HILOG_INFO("start");
1434 MessageParcel data;
1435 // write in token to help identify which stub to be called.
1436 if (!WriteInterfaceToken(data)) {
1437 HILOG_ERROR("write interface token failed");
1438 return ERR_APPEXECFWK_PARCEL_ERROR;
1439 }
1440 int error = GetPublishedFormInfos(IFormMgr::Message::FORM_MGR_GET_PUBLISHED_FORM_INFOS, data, formInfos);
1441 // formInfos should have been fulfilled at this point.
1442 if (error != ERR_OK) {
1443 HILOG_ERROR("fail GetPublishedFormInfos:%{public}d", error);
1444 }
1445
1446 return error;
1447 }
1448
IsRequestPublishFormSupported()1449 bool FormMgrProxy::IsRequestPublishFormSupported()
1450 {
1451 HILOG_INFO("start");
1452 MessageParcel data;
1453 // write in token to help identify which stub to be called.
1454 if (!WriteInterfaceToken(data)) {
1455 HILOG_ERROR("error to write interface token");
1456 return false;
1457 }
1458 // send request.
1459 MessageParcel reply;
1460 MessageOption option;
1461 int error = SendTransactCmd(
1462 IFormMgr::Message::FORM_MGR_IS_REQUEST_PUBLISH_FORM_SUPPORTED,
1463 data,
1464 reply,
1465 option);
1466 if (error != ERR_OK) {
1467 HILOG_ERROR("SendRequest:%{public}d failed", error);
1468 return false;
1469 }
1470 // retrieve and return result.
1471 return reply.ReadBool();
1472 }
1473
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken)1474 int32_t FormMgrProxy::StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken)
1475 {
1476 HILOG_INFO("start");
1477 MessageParcel data;
1478 // write in token to help identify which stub to be called.
1479 if (!WriteInterfaceToken(data)) {
1480 HILOG_ERROR("write interface token failed");
1481 return ERR_APPEXECFWK_PARCEL_ERROR;
1482 }
1483 // write in want
1484 if (!data.WriteParcelable(&want)) {
1485 HILOG_ERROR("write want failed");
1486 return ERR_APPEXECFWK_PARCEL_ERROR;
1487 }
1488 // write in callerToken
1489 if (!data.WriteRemoteObject(callerToken)) {
1490 HILOG_ERROR("write callerToken failed");
1491 return ERR_APPEXECFWK_PARCEL_ERROR;
1492 }
1493 // send request.
1494 MessageParcel reply;
1495 MessageOption option;
1496 int error = SendTransactCmd(
1497 IFormMgr::Message::FORM_MGR_START_ABILITY,
1498 data,
1499 reply,
1500 option);
1501 if (error != ERR_OK) {
1502 HILOG_ERROR("SendRequest:%{public}d failed", error);
1503 return error;
1504 }
1505 // retrieve and return result.
1506 return reply.ReadInt32();
1507 }
1508
StartAbilityByFms(const Want & want)1509 int32_t FormMgrProxy::StartAbilityByFms(const Want &want)
1510 {
1511 HILOG_INFO("start");
1512 MessageParcel data;
1513 // write in token to help identify which stub to be called.
1514 if (!WriteInterfaceToken(data)) {
1515 HILOG_ERROR("write interface token failed");
1516 return ERR_APPEXECFWK_PARCEL_ERROR;
1517 }
1518 // write in want
1519 if (!data.WriteParcelable(&want)) {
1520 HILOG_ERROR("write want failed");
1521 return ERR_APPEXECFWK_PARCEL_ERROR;
1522 }
1523 // send request.
1524 MessageParcel reply;
1525 MessageOption option;
1526 int error = SendTransactCmd(
1527 IFormMgr::Message::FORM_MGR_START_ABILITY_BY_FMS,
1528 data,
1529 reply,
1530 option);
1531 if (error != ERR_OK) {
1532 HILOG_ERROR("SendRequest:%{public}d failed", error);
1533 return error;
1534 }
1535 // retrieve and return result.
1536 return reply.ReadInt32();
1537 }
1538
StartAbilityByCrossBundle(const Want & want)1539 int32_t FormMgrProxy::StartAbilityByCrossBundle(const Want &want)
1540 {
1541 HILOG_INFO("start");
1542 MessageParcel data;
1543 // write in token to help identify which stub to be called.
1544 if (!WriteInterfaceToken(data)) {
1545 HILOG_ERROR("write interface token failed");
1546 return ERR_APPEXECFWK_FORM_GET_SYSMGR_FAILED;
1547 }
1548 // write in want
1549 if (!data.WriteParcelable(&want)) {
1550 HILOG_ERROR("write want failed");
1551 return ERR_APPEXECFWK_FORM_GET_SYSMGR_FAILED;
1552 }
1553 // send request.
1554 MessageParcel reply;
1555 MessageOption option;
1556 int error = SendTransactCmd(
1557 IFormMgr::Message::FORM_MGR_START_ABILITY_BY_CROSS_BUNDLE,
1558 data,
1559 reply,
1560 option);
1561 if (error != ERR_OK) {
1562 HILOG_ERROR("SendRequest:%{public}d failed", error);
1563 return ERR_APPEXECFWK_FORM_GET_SYSMGR_FAILED;
1564 }
1565 // retrieve and return result.
1566 return reply.ReadInt32();
1567 }
1568
ShareForm(int64_t formId,const std::string & deviceId,const sptr<IRemoteObject> & callerToken,int64_t requestCode)1569 int32_t FormMgrProxy::ShareForm(int64_t formId, const std::string &deviceId, const sptr<IRemoteObject> &callerToken,
1570 int64_t requestCode)
1571 {
1572 MessageParcel data;
1573 if (!WriteInterfaceToken(data)) {
1574 HILOG_ERROR("error to write interface token");
1575 return ERR_APPEXECFWK_PARCEL_ERROR;
1576 }
1577
1578 if (!data.WriteInt64(formId)) {
1579 HILOG_ERROR("error to write formId");
1580 return ERR_APPEXECFWK_PARCEL_ERROR;
1581 }
1582
1583 if (!data.WriteString(deviceId)) {
1584 HILOG_ERROR("fail write deviceId");
1585 return ERR_APPEXECFWK_PARCEL_ERROR;
1586 }
1587
1588 if (!data.WriteRemoteObject(callerToken)) {
1589 HILOG_ERROR("write callerToken failed");
1590 return ERR_APPEXECFWK_PARCEL_ERROR;
1591 }
1592
1593 if (!data.WriteInt64(requestCode)) {
1594 HILOG_ERROR("write requestCode failed");
1595 return ERR_APPEXECFWK_PARCEL_ERROR;
1596 }
1597
1598 MessageParcel reply;
1599 MessageOption option;
1600 auto error = SendTransactCmd(
1601 IFormMgr::Message::FORM_MGR_SHARE_FORM, data, reply, option);
1602 if (error != ERR_OK) {
1603 HILOG_ERROR("SendRequest:%{public}d failed", error);
1604 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1605 }
1606 return reply.ReadInt32();
1607 }
1608
AcquireFormData(int64_t formId,int64_t requestCode,const sptr<IRemoteObject> & callerToken,AAFwk::WantParams & formData)1609 int32_t FormMgrProxy::AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
1610 AAFwk::WantParams &formData)
1611 {
1612 MessageParcel data;
1613 if (!WriteInterfaceToken(data)) {
1614 HILOG_ERROR("write interface token failed");
1615 return ERR_APPEXECFWK_PARCEL_ERROR;
1616 }
1617
1618 if (!data.WriteInt64(formId)) {
1619 HILOG_ERROR("write formId failed");
1620 return ERR_APPEXECFWK_PARCEL_ERROR;
1621 }
1622
1623 if (!data.WriteInt64(requestCode)) {
1624 HILOG_ERROR("write requestCode failed");
1625 return ERR_APPEXECFWK_PARCEL_ERROR;
1626 }
1627
1628 if (!data.WriteRemoteObject(callerToken)) {
1629 HILOG_ERROR("write callerToken failed");
1630 return ERR_APPEXECFWK_PARCEL_ERROR;
1631 }
1632
1633 int error;
1634 MessageParcel reply;
1635 MessageOption option(MessageOption::TF_SYNC);
1636 error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ACQUIRE_DATA, data, reply, option);
1637 if (error != ERR_OK) {
1638 return error;
1639 }
1640
1641 error = reply.ReadInt32();
1642 if (error != ERR_OK) {
1643 HILOG_ERROR("read replyResult failed");
1644 return error;
1645 }
1646 std::shared_ptr<AAFwk::WantParams> wantParams(reply.ReadParcelable<AAFwk::WantParams>());
1647 if (wantParams == nullptr) {
1648 HILOG_ERROR("ReadParcelable<wantParams> failed");
1649 return ERR_APPEXECFWK_PARCEL_ERROR;
1650 }
1651 formData = *wantParams;
1652 return ERR_OK;
1653 }
1654
RecvFormShareInfoFromRemote(const FormShareInfo & info)1655 int32_t FormMgrProxy::RecvFormShareInfoFromRemote(const FormShareInfo &info)
1656 {
1657 MessageParcel data;
1658 if (!WriteInterfaceToken(data)) {
1659 HILOG_ERROR("write interface token failed");
1660 return ERR_APPEXECFWK_PARCEL_ERROR;
1661 }
1662
1663 if (!data.WriteParcelable(&info)) {
1664 HILOG_ERROR("fail write form share info");
1665 return ERR_APPEXECFWK_PARCEL_ERROR;
1666 }
1667
1668 MessageParcel reply;
1669 MessageOption option;
1670 auto error = SendTransactCmd(
1671 IFormMgr::Message::FORM_MGR_RECV_FORM_SHARE_INFO_FROM_REMOTE, data, reply, option);
1672 if (error != ERR_OK) {
1673 HILOG_ERROR("SendRequest:%{public}d failed", error);
1674 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1675 }
1676 return reply.ReadInt32();
1677 }
1678
CheckFMSReady()1679 bool FormMgrProxy::CheckFMSReady()
1680 {
1681 HILOG_DEBUG("start");
1682 MessageParcel data;
1683 // write in token to help identify which stub to be called
1684 if (!WriteInterfaceToken(data)) {
1685 HILOG_ERROR("write interface token failed");
1686 return false;
1687 }
1688 // send request
1689 MessageParcel reply;
1690 MessageOption option;
1691 int error = SendTransactCmd(
1692 IFormMgr::Message::FORM_MGR_CHECK_FMS_READY, data, reply, option);
1693 if (error != ERR_OK) {
1694 HILOG_ERROR("SendRequest:%{public}d failed", error);
1695 return false;
1696 }
1697 // retrieve and return result;
1698 return reply.ReadBool();
1699 }
1700
IsSystemAppForm(const std::string & bundleName)1701 bool FormMgrProxy::IsSystemAppForm(const std::string &bundleName)
1702 {
1703 MessageParcel data;
1704 // write in token to help identify which stub to be called
1705 if (!WriteInterfaceToken(data)) {
1706 HILOG_ERROR("write interface token failed");
1707 return false;
1708 }
1709 if (!data.WriteString(bundleName)) {
1710 HILOG_ERROR("write bundleName failed");
1711 return false;
1712 }
1713 MessageParcel reply;
1714 MessageOption option;
1715 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_IS_SYSTEM_APP_FORM, data, reply, option);
1716 if (error != ERR_OK) {
1717 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
1718 return false;
1719 }
1720 return reply.ReadBool();
1721 }
1722
SetBackgroundFunction(const std::string funcName,const std::string params)1723 int32_t FormMgrProxy::SetBackgroundFunction(const std::string funcName, const std::string params)
1724 {
1725 HILOG_DEBUG("start");
1726 MessageParcel data;
1727 // write in token to help identify which stub to be called
1728 if (!data.WriteString16(Str8ToStr16(funcName))) {
1729 HILOG_ERROR("write funcName failed");
1730 return ERR_APPEXECFWK_PARCEL_ERROR;
1731 }
1732 if (!data.WriteString16(Str8ToStr16(params))) {
1733 HILOG_ERROR("write params failed");
1734 return ERR_APPEXECFWK_PARCEL_ERROR;
1735 }
1736 // send request
1737 MessageParcel reply;
1738 MessageOption option(MessageOption::TF_ASYNC);
1739 sptr<IRemoteObject> remote = Remote();
1740 if (!remote) {
1741 HILOG_ERROR("get remoteObject failed");
1742 return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED;
1743 }
1744 int error = remote->SendRequest(Constants::EVENT_CALL_NOTIFY, data, reply, option);
1745 if (error != ERR_OK) {
1746 HILOG_ERROR("SendRequest:%{public}d failed", error);
1747 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1748 }
1749 // retrieve and return result;
1750 return reply.ReadInt32();
1751 }
1752
GetFormsCount(bool isTempFormFlag,int32_t & formCount)1753 int32_t FormMgrProxy::GetFormsCount(bool isTempFormFlag, int32_t &formCount)
1754 {
1755 HILOG_INFO("start");
1756 MessageParcel data;
1757 if (!WriteInterfaceToken(data)) {
1758 HILOG_ERROR("write interface token failed");
1759 return ERR_APPEXECFWK_PARCEL_ERROR;
1760 }
1761 if (!data.WriteBool(isTempFormFlag)) {
1762 HILOG_ERROR("write bool isEnableUpdate failed");
1763 return ERR_APPEXECFWK_PARCEL_ERROR;
1764 }
1765 MessageParcel reply;
1766 MessageOption option;
1767 int error = SendTransactCmd(
1768 IFormMgr::Message::FORM_MGR_GET_FORMS_COUNT, data, reply, option);
1769 if (error != ERR_OK) {
1770 HILOG_ERROR("SendRequest:%{public}d failed", error);
1771 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1772 }
1773 int32_t result = reply.ReadInt32();
1774 formCount = reply.ReadInt32();
1775 return result;
1776 }
1777
RegisterFormAddObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1778 ErrCode FormMgrProxy::RegisterFormAddObserverByBundle(const std::string bundleName,
1779 const sptr<IRemoteObject> &callerToken)
1780 {
1781 HILOG_DEBUG("RegisterFormAddObserverByBundle start");
1782 MessageParcel data;
1783 if (!WriteInterfaceToken(data)) {
1784 HILOG_ERROR("write interface token failed");
1785 return ERR_APPEXECFWK_PARCEL_ERROR;
1786 }
1787
1788 if (!data.WriteString(bundleName)) {
1789 HILOG_ERROR("error to write bundleName");
1790 return ERR_APPEXECFWK_PARCEL_ERROR;
1791 }
1792
1793 if (!data.WriteRemoteObject(callerToken)) {
1794 HILOG_ERROR("write callerToken failed");
1795 return ERR_APPEXECFWK_PARCEL_ERROR;
1796 }
1797
1798 MessageParcel reply;
1799 MessageOption option(MessageOption::TF_ASYNC);
1800 auto error = SendTransactCmd(
1801 IFormMgr::Message::FORM_MGR_REGISTER_FORM_ADD_OBSERVER_BY_BUNDLE, data, reply, option);
1802 if (error != ERR_OK) {
1803 HILOG_ERROR("SendRequest:%{public}d failed", error);
1804 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1805 }
1806 return reply.ReadInt32();
1807 }
1808
RegisterFormRemoveObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1809 ErrCode FormMgrProxy::RegisterFormRemoveObserverByBundle(const std::string bundleName,
1810 const sptr<IRemoteObject> &callerToken)
1811 {
1812 HILOG_DEBUG("start");
1813 MessageParcel data;
1814 if (!WriteInterfaceToken(data)) {
1815 HILOG_ERROR("write interface token failed");
1816 return ERR_APPEXECFWK_PARCEL_ERROR;
1817 }
1818
1819 if (!data.WriteString(bundleName)) {
1820 HILOG_ERROR("write bundleName failed");
1821 return ERR_APPEXECFWK_PARCEL_ERROR;
1822 }
1823
1824 if (!data.WriteRemoteObject(callerToken)) {
1825 HILOG_ERROR("write callerToken failed");
1826 return ERR_APPEXECFWK_PARCEL_ERROR;
1827 }
1828
1829 MessageParcel reply;
1830 MessageOption option(MessageOption::TF_ASYNC);
1831 auto error = SendTransactCmd(
1832 IFormMgr::Message::FORM_MGR_REGISTER_FORM_REMOVE_OBSERVER_BY_BUNDLE,
1833 data, reply, option);
1834 if (error != ERR_OK) {
1835 HILOG_ERROR("SendRequest:%{public}d failed", error);
1836 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1837 }
1838 return reply.ReadInt32();
1839 }
1840
GetHostFormsCount(std::string & bundleName,int32_t & formCount)1841 int32_t FormMgrProxy::GetHostFormsCount(std::string &bundleName, int32_t &formCount)
1842 {
1843 HILOG_INFO("start");
1844 MessageParcel data;
1845 if (!WriteInterfaceToken(data)) {
1846 HILOG_ERROR("write interface token failed");
1847 return ERR_APPEXECFWK_PARCEL_ERROR;
1848 }
1849 if (!data.WriteString(bundleName)) {
1850 HILOG_ERROR("write bundleName failed");
1851 return ERR_APPEXECFWK_PARCEL_ERROR;
1852 }
1853 MessageParcel reply;
1854 MessageOption option;
1855 int error = SendTransactCmd(
1856 IFormMgr::Message::FORM_MGR_GET_HOST_FORMS_COUNT, data, reply, option);
1857 if (error != ERR_OK) {
1858 HILOG_ERROR("SendRequest:%{public}d failed", error);
1859 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1860 }
1861 int32_t result = reply.ReadInt32();
1862 formCount = reply.ReadInt32();
1863 return result;
1864 }
1865
GetFormInstancesByFilter(const FormInstancesFilter & formInstancesFilter,std::vector<FormInstance> & formInstances)1866 int32_t FormMgrProxy::GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
1867 std::vector<FormInstance> &formInstances)
1868 {
1869 HILOG_DEBUG("start");
1870 MessageParcel data;
1871 // write in token to help identify which stub to be called.
1872 if (!WriteInterfaceToken(data)) {
1873 HILOG_ERROR("write interface token failed");
1874 return ERR_APPEXECFWK_PARCEL_ERROR;
1875 }
1876 if (!data.WriteParcelable(&formInstancesFilter)) {
1877 HILOG_ERROR("fail write formInstancesFilter");
1878 return ERR_APPEXECFWK_PARCEL_ERROR;
1879 }
1880 auto error = GetFormInstance(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_FILTER, data, formInstances);
1881 if (error != ERR_OK) {
1882 HILOG_ERROR("fail get form instances by filter:%{public}d", error);
1883 }
1884
1885 return error;
1886 }
1887
GetFormInstanceById(const int64_t formId,FormInstance & formInstance)1888 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, FormInstance &formInstance)
1889 {
1890 HILOG_DEBUG("GetFormInstanceById start");
1891 MessageParcel data;
1892 // write in token to help identify which stub to be called.
1893 if (!WriteInterfaceToken(data)) {
1894 HILOG_ERROR("error to write interface token");
1895 return ERR_APPEXECFWK_PARCEL_ERROR;
1896 }
1897 if (!data.WriteInt64(formId)) {
1898 HILOG_ERROR("error to write formId");
1899 return ERR_APPEXECFWK_PARCEL_ERROR;
1900 }
1901 auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1902 data, formInstance);
1903 if (error != ERR_OK) {
1904 HILOG_ERROR("get parcelable info failed");
1905 }
1906
1907 return error;
1908 }
1909
GetFormInstanceById(const int64_t formId,bool isUnusedInclude,FormInstance & formInstance)1910 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, bool isUnusedInclude, FormInstance &formInstance)
1911 {
1912 HILOG_DEBUG("start");
1913 MessageParcel data;
1914 // write in token to help identify which stub to be called.
1915 if (!WriteInterfaceToken(data)) {
1916 HILOG_ERROR("write interface token failed");
1917 return ERR_APPEXECFWK_PARCEL_ERROR;
1918 }
1919 if (!data.WriteInt64(formId)) {
1920 HILOG_ERROR("write formId failed");
1921 return ERR_APPEXECFWK_PARCEL_ERROR;
1922 }
1923 if (!data.WriteBool(isUnusedInclude)) {
1924 HILOG_ERROR("write isUnusedInclude failed");
1925 return ERR_APPEXECFWK_PARCEL_ERROR;
1926 }
1927
1928 auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1929 data, formInstance);
1930 if (error != ERR_OK) {
1931 HILOG_ERROR("get parcelable info failed");
1932 }
1933
1934 return error;
1935 }
1936
GetFormInstance(IFormMgr::Message code,MessageParcel & data,std::vector<FormInstance> & formInstances)1937 ErrCode FormMgrProxy::GetFormInstance(IFormMgr::Message code, MessageParcel &data,
1938 std::vector<FormInstance> &formInstances)
1939 {
1940 HILOG_DEBUG("GetFormInstance start");
1941 int error;
1942 MessageParcel reply;
1943 MessageOption option(MessageOption::TF_SYNC);
1944 error = SendTransactCmd(code, data, reply, option);
1945 if (error != ERR_OK) {
1946 return error;
1947 }
1948 error = reply.ReadInt32();
1949 if (error != ERR_OK) {
1950 HILOG_ERROR("read replyResult failed");
1951 return error;
1952 }
1953 auto ret = GetParcelableInfos<FormInstance>(reply, formInstances);
1954 if (ret != ERR_OK) {
1955 HILOG_ERROR("fail get parcelable infos");
1956 return ERR_APPEXECFWK_PARCEL_ERROR;
1957 }
1958 return ret;
1959 }
1960
RegisterAddObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1961 ErrCode FormMgrProxy::RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1962 {
1963 HILOG_DEBUG("start");
1964 MessageParcel data;
1965 if (!WriteInterfaceToken(data)) {
1966 HILOG_ERROR("error to write interface token");
1967 return ERR_APPEXECFWK_PARCEL_ERROR;
1968 }
1969 if (!data.WriteString(bundleName)) {
1970 HILOG_ERROR("error to write bundleName");
1971 return ERR_APPEXECFWK_PARCEL_ERROR;
1972 }
1973 if (!data.WriteRemoteObject(callerToken)) {
1974 HILOG_ERROR("error to write callerToken");
1975 return ERR_APPEXECFWK_PARCEL_ERROR;
1976 }
1977 MessageParcel reply;
1978 MessageOption option(MessageOption::TF_ASYNC);
1979 auto error = SendTransactCmd(
1980 IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER, data, reply, option);
1981 if (error != ERR_OK) {
1982 HILOG_ERROR("error to SendRequest:%{public}d", error);
1983 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1984 }
1985 return reply.ReadInt32();
1986 }
1987
RegisterRemoveObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1988 ErrCode FormMgrProxy::RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1989 {
1990 HILOG_DEBUG("call");
1991 MessageParcel data;
1992 if (!WriteInterfaceToken(data)) {
1993 HILOG_ERROR("write interface token failed");
1994 return ERR_APPEXECFWK_PARCEL_ERROR;
1995 }
1996 if (!data.WriteString(bundleName)) {
1997 HILOG_ERROR("write bundleName failed");
1998 return ERR_APPEXECFWK_PARCEL_ERROR;
1999 }
2000 if (!data.WriteRemoteObject(callerToken)) {
2001 HILOG_ERROR("write callerToken failed");
2002 return ERR_APPEXECFWK_PARCEL_ERROR;
2003 }
2004 MessageParcel reply;
2005 MessageOption option(MessageOption::TF_ASYNC);
2006 int error = SendTransactCmd(
2007 IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER, data, reply, option);
2008 if (error != ERR_OK) {
2009 HILOG_ERROR("SendRequest:%{public}d failed", error);
2010 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2011 }
2012 return reply.ReadInt32();
2013 }
2014
RegisterFormRouterProxy(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken)2015 ErrCode FormMgrProxy::RegisterFormRouterProxy(const std::vector<int64_t> &formIds,
2016 const sptr<IRemoteObject> &callerToken)
2017 {
2018 HILOG_DEBUG("call");
2019 MessageParcel data;
2020 if (!WriteInterfaceToken(data)) {
2021 HILOG_ERROR("write interface token failed");
2022 return ERR_APPEXECFWK_PARCEL_ERROR;
2023 }
2024 if (!data.WriteInt64Vector(formIds)) {
2025 HILOG_ERROR("write vector formIds failed");
2026 return ERR_APPEXECFWK_PARCEL_ERROR;
2027 }
2028 if (!data.WriteRemoteObject(callerToken)) {
2029 HILOG_ERROR("write callerToken failed");
2030 return ERR_APPEXECFWK_PARCEL_ERROR;
2031 }
2032 MessageParcel reply;
2033 MessageOption option;
2034 int error = SendTransactCmd(
2035 IFormMgr::Message::FORM_MGR_REGISTER_FORM_ROUTER_PROXY, data, reply, option);
2036 if (error != ERR_OK) {
2037 HILOG_ERROR("SendRequest:%{public}d failed", error);
2038 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2039 }
2040 return reply.ReadInt32();
2041 }
2042
UnregisterFormRouterProxy(const std::vector<int64_t> & formIds)2043 ErrCode FormMgrProxy::UnregisterFormRouterProxy(const std::vector<int64_t> &formIds)
2044 {
2045 HILOG_DEBUG("call");
2046 MessageParcel data;
2047 if (!WriteInterfaceToken(data)) {
2048 HILOG_ERROR("write interface token failed");
2049 return ERR_APPEXECFWK_PARCEL_ERROR;
2050 }
2051 if (!data.WriteInt64Vector(formIds)) {
2052 HILOG_ERROR("write vector formIds failed");
2053 return ERR_APPEXECFWK_PARCEL_ERROR;
2054 }
2055 MessageParcel reply;
2056 MessageOption option;
2057 int error = SendTransactCmd(
2058 IFormMgr::Message::FORM_MGR_UNREGISTER_FORM_ROUTER_PROXY, data, reply, option);
2059 if (error != ERR_OK) {
2060 HILOG_ERROR("SendRequest:%{public}d failed", error);
2061 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2062 }
2063 return reply.ReadInt32();
2064 }
2065
UpdateProxyForm(int64_t formId,const FormProviderData & FormProviderData,const std::vector<FormDataProxy> & formDataProxies)2066 ErrCode FormMgrProxy::UpdateProxyForm(int64_t formId, const FormProviderData &FormProviderData,
2067 const std::vector<FormDataProxy> &formDataProxies)
2068 {
2069 MessageParcel data;
2070 if (!WriteInterfaceToken(data)) {
2071 HILOG_ERROR("write interface token failed");
2072 return ERR_APPEXECFWK_PARCEL_ERROR;
2073 }
2074 if (!data.WriteInt64(formId)) {
2075 HILOG_ERROR("write formId failed");
2076 return ERR_APPEXECFWK_PARCEL_ERROR;
2077 }
2078 if (!data.WriteParcelable(&FormProviderData)) {
2079 HILOG_ERROR("write formBindingData failed");
2080 return ERR_APPEXECFWK_PARCEL_ERROR;
2081 }
2082 if (!WriteFormDataProxies(data, formDataProxies)) {
2083 HILOG_ERROR("write formDataProxies failed");
2084 return ERR_APPEXECFWK_PARCEL_ERROR;
2085 }
2086 MessageParcel reply;
2087 MessageOption option(MessageOption::TF_SYNC);
2088 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_PROXY_FORM, data, reply, option);
2089 if (error != ERR_OK) {
2090 HILOG_ERROR("fail SendTransactCmd");
2091 return error;
2092 }
2093 return reply.ReadInt32();
2094 }
2095
RequestPublishProxyForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId,const std::vector<FormDataProxy> & formDataProxies)2096 ErrCode FormMgrProxy::RequestPublishProxyForm(Want &want, bool withFormBindingData,
2097 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
2098 const std::vector<FormDataProxy> &formDataProxies)
2099 {
2100 MessageParcel data;
2101
2102 if (!WriteInterfaceToken(data)) {
2103 HILOG_ERROR("write interface token failed");
2104 return ERR_APPEXECFWK_PARCEL_ERROR;
2105 }
2106 if (!data.WriteParcelable(&want)) {
2107 HILOG_ERROR("write want failed");
2108 return ERR_APPEXECFWK_PARCEL_ERROR;
2109 }
2110 if (!data.WriteBool(withFormBindingData)) {
2111 HILOG_ERROR("write withFormBindingData failed");
2112 return ERR_APPEXECFWK_PARCEL_ERROR;
2113 }
2114 if (withFormBindingData) {
2115 if (!data.WriteParcelable(formBindingData.get())) {
2116 HILOG_ERROR("write formBindingData failed");
2117 return ERR_APPEXECFWK_PARCEL_ERROR;
2118 }
2119 }
2120 if (!WriteFormDataProxies(data, formDataProxies)) {
2121 HILOG_ERROR("write formDataProxies failed");
2122 return ERR_APPEXECFWK_PARCEL_ERROR;
2123 }
2124
2125 MessageParcel reply;
2126 MessageOption option(MessageOption::TF_SYNC);
2127 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_PROXY_FORM, data, reply, option);
2128 if (error != ERR_OK) {
2129 HILOG_ERROR("fail SendTransactCmd");
2130 return error;
2131 }
2132 ErrCode errCode = reply.ReadInt32();
2133 if (errCode == ERR_OK) {
2134 formId = reply.ReadInt64();
2135 }
2136 return errCode;
2137 }
2138
WriteFormDataProxies(MessageParcel & data,const std::vector<FormDataProxy> & formDataProxies)2139 bool FormMgrProxy::WriteFormDataProxies(MessageParcel &data, const std::vector<FormDataProxy> &formDataProxies)
2140 {
2141 HILOG_DEBUG("proxies size:%{public}zu", formDataProxies.size());
2142 if (!data.WriteInt32(formDataProxies.size())) {
2143 HILOG_ERROR("fail marshalling form data proxies size");
2144 return false;
2145 }
2146 for (const auto &formDataProxy : formDataProxies) {
2147 if (!data.WriteString16(Str8ToStr16(formDataProxy.key))) {
2148 HILOG_ERROR("fail marshalling formDataProxy key:%{public}s", formDataProxy.key.c_str());
2149 return false;
2150 }
2151 if (!data.WriteString16(Str8ToStr16(formDataProxy.subscribeId))) {
2152 HILOG_ERROR("fail marshalling formDataProxy subscribeId:%{public}s",
2153 formDataProxy.subscribeId.c_str());
2154 return false;
2155 }
2156 }
2157 return true;
2158 }
2159
RegisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)2160 int32_t FormMgrProxy::RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
2161 {
2162 HILOG_DEBUG("start");
2163 MessageParcel data;
2164 // write in token to help identify which stub to be called.
2165 if (!WriteInterfaceToken(data)) {
2166 HILOG_ERROR("error to write interface token");
2167 return ERR_APPEXECFWK_PARCEL_ERROR;
2168 }
2169 // write in interceptor
2170 if (!data.WriteRemoteObject(interceptorCallback)) {
2171 HILOG_ERROR("error to write interceptor");
2172 return ERR_APPEXECFWK_PARCEL_ERROR;
2173 }
2174 // send request.
2175 MessageParcel reply;
2176 MessageOption option;
2177 int error = SendTransactCmd(
2178 IFormMgr::Message::FORM_MGR_REGISTER_PUBLISH_FORM_INTERCEPTOR,
2179 data,
2180 reply,
2181 option);
2182 if (error != ERR_OK) {
2183 HILOG_ERROR("SendRequest:%{public}d failed", error);
2184 return error;
2185 }
2186 // retrieve and return result.
2187 return reply.ReadInt32();
2188 }
2189
UnregisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)2190 int32_t FormMgrProxy::UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
2191 {
2192 HILOG_DEBUG("start");
2193 MessageParcel data;
2194 // write in token to help identify which stub to be called.
2195 if (!WriteInterfaceToken(data)) {
2196 HILOG_ERROR("write interface token failed");
2197 return ERR_APPEXECFWK_PARCEL_ERROR;
2198 }
2199 // write in interceptor
2200 if (!data.WriteRemoteObject(interceptorCallback)) {
2201 HILOG_ERROR("fail write interceptor");
2202 return ERR_APPEXECFWK_PARCEL_ERROR;
2203 }
2204
2205 MessageParcel reply;
2206 MessageOption option;
2207 int error = SendTransactCmd(
2208 IFormMgr::Message::FORM_MGR_UNREGISTER_PUBLISH_FORM_INTERCEPTOR,
2209 data,
2210 reply,
2211 option);
2212 if (error != ERR_OK) {
2213 HILOG_ERROR("SendRequest:%{public}d failed", error);
2214 return error;
2215 }
2216 return reply.ReadInt32();
2217 }
2218
RegisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)2219 ErrCode FormMgrProxy::RegisterClickEventObserver(
2220 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
2221 {
2222 HILOG_DEBUG("Click callback event start");
2223 MessageParcel data;
2224 if (!WriteInterfaceToken(data)) {
2225 HILOG_ERROR("write interface token failed");
2226 return ERR_APPEXECFWK_PARCEL_ERROR;
2227 }
2228
2229 if (!data.WriteString(bundleName)) {
2230 HILOG_ERROR("write bundleName failed");
2231 return ERR_APPEXECFWK_PARCEL_ERROR;
2232 }
2233
2234 if (!data.WriteString(formEventType)) {
2235 HILOG_ERROR("write formEventType failed");
2236 return ERR_APPEXECFWK_PARCEL_ERROR;
2237 }
2238
2239 if (!data.WriteRemoteObject(observer)) {
2240 HILOG_ERROR("fail write observer");
2241 return ERR_APPEXECFWK_PARCEL_ERROR;
2242 }
2243
2244 MessageParcel reply;
2245 MessageOption option(MessageOption::TF_ASYNC);
2246 int error = SendTransactCmd(
2247 IFormMgr::Message::FORM_MGR_REGISTER_CLICK_EVENT_OBSERVER, data, reply, option);
2248 if (error != ERR_OK) {
2249 HILOG_ERROR("SendRequest:%{public}d failed", error);
2250 return error;
2251 }
2252 return ERR_OK;
2253 }
2254
UnregisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)2255 ErrCode FormMgrProxy::UnregisterClickEventObserver(
2256 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
2257 {
2258 HILOG_DEBUG("Click callback event start");
2259 MessageParcel data;
2260 if (!WriteInterfaceToken(data)) {
2261 HILOG_ERROR("write interface token failed");
2262 return ERR_APPEXECFWK_PARCEL_ERROR;
2263 }
2264
2265 if (!data.WriteString(bundleName)) {
2266 HILOG_ERROR("write bundleName failed");
2267 return ERR_APPEXECFWK_PARCEL_ERROR;
2268 }
2269
2270 if (!data.WriteString(formEventType)) {
2271 HILOG_ERROR("write formEventType failed");
2272 return ERR_APPEXECFWK_PARCEL_ERROR;
2273 }
2274
2275 if (!data.WriteRemoteObject(observer)) {
2276 HILOG_ERROR("fail write observer");
2277 return ERR_APPEXECFWK_PARCEL_ERROR;
2278 }
2279
2280 MessageParcel reply;
2281 MessageOption option(MessageOption::TF_ASYNC);
2282 int error = SendTransactCmd(
2283 IFormMgr::Message::FORM_MGR_UNREGISTER_CLICK_EVENT_OBSERVER, data, reply, option);
2284 if (error != ERR_OK) {
2285 HILOG_ERROR("SendRequest:%{public}d failed", error);
2286 return error;
2287 }
2288 return ERR_OK;
2289 }
2290
SetFormsRecyclable(const std::vector<int64_t> & formIds)2291 int32_t FormMgrProxy::SetFormsRecyclable(const std::vector<int64_t> &formIds)
2292 {
2293 HILOG_DEBUG("start");
2294 MessageParcel data;
2295 if (!WriteInterfaceToken(data)) {
2296 HILOG_ERROR("write interface token failed");
2297 return ERR_APPEXECFWK_PARCEL_ERROR;
2298 }
2299 if (!data.WriteInt64Vector(formIds)) {
2300 HILOG_ERROR("write vector formIds failed");
2301 return ERR_APPEXECFWK_PARCEL_ERROR;
2302 }
2303 MessageParcel reply;
2304 MessageOption option(MessageOption::TF_SYNC);
2305 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_SET_FORMS_RECYCLABLE, data, reply, option);
2306 if (error != ERR_OK) {
2307 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2308 return error;
2309 }
2310 return reply.ReadInt32();
2311 }
2312
RecycleForms(const std::vector<int64_t> & formIds,const Want & want)2313 int32_t FormMgrProxy::RecycleForms(const std::vector<int64_t> &formIds, const Want &want)
2314 {
2315 HILOG_DEBUG("start");
2316 MessageParcel data;
2317 if (!WriteInterfaceToken(data)) {
2318 HILOG_ERROR("write interface token failed");
2319 return ERR_APPEXECFWK_PARCEL_ERROR;
2320 }
2321 if (!data.WriteInt64Vector(formIds)) {
2322 HILOG_ERROR("write vector formIds failed");
2323 return ERR_APPEXECFWK_PARCEL_ERROR;
2324 }
2325 if (!data.WriteParcelable(&want)) {
2326 HILOG_ERROR("write want failed");
2327 return ERR_APPEXECFWK_PARCEL_ERROR;
2328 }
2329 MessageParcel reply;
2330 MessageOption option(MessageOption::TF_SYNC);
2331 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_RECYCLE_FORMS, data, reply, option);
2332 if (error != ERR_OK) {
2333 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2334 return error;
2335 }
2336 return reply.ReadInt32();
2337 }
2338
RecoverForms(const std::vector<int64_t> & formIds,const Want & want)2339 int32_t FormMgrProxy::RecoverForms(const std::vector<int64_t> &formIds, const Want &want)
2340 {
2341 HILOG_DEBUG("start");
2342 MessageParcel data;
2343 if (!WriteInterfaceToken(data)) {
2344 HILOG_ERROR("write interface token failed");
2345 return ERR_APPEXECFWK_PARCEL_ERROR;
2346 }
2347 if (!data.WriteInt64Vector(formIds)) {
2348 HILOG_ERROR("write vector formIds failed");
2349 return ERR_APPEXECFWK_PARCEL_ERROR;
2350 }
2351 if (!data.WriteParcelable(&want)) {
2352 HILOG_ERROR("write want failed");
2353 return ERR_APPEXECFWK_PARCEL_ERROR;
2354 }
2355 MessageParcel reply;
2356 MessageOption option(MessageOption::TF_SYNC);
2357 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_RECOVER_FORMS, data, reply, option);
2358 if (error != ERR_OK) {
2359 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2360 return error;
2361 }
2362 return reply.ReadInt32();
2363 }
2364
UpdateFormLocation(const int64_t & formId,const int32_t & formLocation)2365 ErrCode FormMgrProxy::UpdateFormLocation(const int64_t &formId, const int32_t &formLocation)
2366 {
2367 HILOG_DEBUG("start");
2368 MessageParcel data;
2369 if (!WriteInterfaceToken(data)) {
2370 HILOG_ERROR("write interface token failed");
2371 return ERR_APPEXECFWK_PARCEL_ERROR;
2372 }
2373 if (!data.WriteInt64(formId)) {
2374 HILOG_ERROR("write formId failed");
2375 return ERR_APPEXECFWK_PARCEL_ERROR;
2376 }
2377 if (!data.WriteInt32(formLocation)) {
2378 HILOG_ERROR("fail write formLocation");
2379 return ERR_APPEXECFWK_PARCEL_ERROR;
2380 }
2381 MessageParcel reply;
2382 MessageOption option(MessageOption::TF_SYNC);
2383 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_FORM_LOCATION, data, reply, option);
2384 if (error != ERR_OK) {
2385 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2386 return error;
2387 }
2388 return reply.ReadInt32();
2389 }
2390
RequestPublishFormWithSnapshot(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId)2391 ErrCode FormMgrProxy::RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData,
2392 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
2393 {
2394 MessageParcel data;
2395 MessageParcel reply;
2396
2397 if (!WriteInterfaceToken(data)) {
2398 HILOG_ERROR("write interface token failed");
2399 return ERR_APPEXECFWK_PARCEL_ERROR;
2400 }
2401 if (!data.WriteParcelable(&want)) {
2402 HILOG_ERROR("write want failed");
2403 return ERR_APPEXECFWK_PARCEL_ERROR;
2404 }
2405 if (!data.WriteBool(withFormBindingData)) {
2406 HILOG_ERROR("write withFormBindingData failed");
2407 return ERR_APPEXECFWK_PARCEL_ERROR;
2408 }
2409 if (withFormBindingData) {
2410 if (!data.WriteParcelable(formBindingData.get())) {
2411 HILOG_ERROR("write formBindingData failed");
2412 return ERR_APPEXECFWK_PARCEL_ERROR;
2413 }
2414 }
2415
2416 MessageOption option;
2417 int32_t error = SendTransactCmd(
2418 IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM_WITH_SNAPSHOT,
2419 data,
2420 reply,
2421 option);
2422 if (error != ERR_OK) {
2423 HILOG_ERROR("SendRequest:%{public}d failed", error);
2424 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2425 }
2426 ErrCode errCode = reply.ReadInt32();
2427 if (errCode == ERR_OK) {
2428 formId = reply.ReadInt64();
2429 }
2430 return errCode;
2431 }
2432
BatchRefreshForms(const int32_t formRefreshType)2433 int32_t FormMgrProxy::BatchRefreshForms(const int32_t formRefreshType)
2434 {
2435 MessageParcel data;
2436 if (!WriteInterfaceToken(data)) {
2437 HILOG_ERROR("write interface token failed");
2438 return ERR_APPEXECFWK_PARCEL_ERROR;
2439 }
2440 if (!data.WriteInt32(formRefreshType)) {
2441 HILOG_ERROR("fail write formRefreshType");
2442 return ERR_APPEXECFWK_PARCEL_ERROR;
2443 }
2444 MessageParcel reply;
2445 MessageOption option(MessageOption::TF_SYNC);
2446 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_BATCH_REFRESH_FORMS, data, reply, option);
2447 if (error != ERR_OK) {
2448 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2449 return error;
2450 }
2451 return reply.ReadInt32();
2452 }
2453
EnableForms(const std::string bundleName,const bool enable)2454 int32_t FormMgrProxy::EnableForms(const std::string bundleName, const bool enable)
2455 {
2456 HILOG_DEBUG("EnableForms start.%{public}s", bundleName.c_str());
2457 MessageParcel data;
2458 if (!WriteInterfaceToken(data)) {
2459 HILOG_ERROR("write interface token failed");
2460 return ERR_APPEXECFWK_PARCEL_ERROR;
2461 }
2462
2463 if (!data.WriteString(bundleName)) {
2464 HILOG_ERROR("write bundleName failed");
2465 return ERR_APPEXECFWK_PARCEL_ERROR;
2466 }
2467
2468 if (!data.WriteBool(enable)) {
2469 HILOG_ERROR("fail write enable");
2470 return ERR_APPEXECFWK_PARCEL_ERROR;
2471 }
2472
2473 MessageParcel reply;
2474 MessageOption option(MessageOption::TF_SYNC);
2475 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ENABLE_FORMS, data, reply, option);
2476 if (error != ERR_OK) {
2477 HILOG_ERROR("SendRequest:%{public}d failed", error);
2478 return error;
2479 }
2480 return ERR_OK;
2481 }
2482
IsFormBundleForbidden(const std::string & bundleName)2483 bool FormMgrProxy::IsFormBundleForbidden(const std::string &bundleName)
2484 {
2485 MessageParcel data;
2486 if (!WriteInterfaceToken(data)) {
2487 HILOG_ERROR("write interface token failed");
2488 return true;
2489 }
2490
2491 if (!data.WriteString(bundleName)) {
2492 HILOG_ERROR("write bundleName failed");
2493 return true;
2494 }
2495
2496 MessageParcel reply;
2497 MessageOption option;
2498 int error = SendTransactCmd(
2499 IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_FORBIDDEN, data, reply, option);
2500 if (error != ERR_OK) {
2501 HILOG_ERROR("SendRequest:%{public}d failed", error);
2502 return false;
2503 }
2504 return reply.ReadBool();
2505 }
2506
LockForms(const std::vector<FormLockInfo> & formLockInfos,OHOS::AppExecFwk::LockChangeType type)2507 int32_t FormMgrProxy::LockForms(const std::vector<FormLockInfo> &formLockInfos, OHOS::AppExecFwk::LockChangeType type)
2508 {
2509 HILOG_DEBUG("LockForms start");
2510 MessageParcel data;
2511 if (!WriteInterfaceToken(data)) {
2512 HILOG_ERROR("write interface token failed");
2513 return ERR_APPEXECFWK_PARCEL_ERROR;
2514 }
2515
2516 if (formLockInfos.size() > static_cast<size_t>(MAX_ALLOW_SIZE)) {
2517 HILOG_ERROR("The vector/array size exceeds the security limit!");
2518 return ERR_APPEXECFWK_PARCEL_ERROR;
2519 }
2520
2521 data.WriteInt32(formLockInfos.size());
2522 for (auto it = formLockInfos.begin(); it != formLockInfos.end(); ++it) {
2523 if (!data.WriteParcelable(&(*it))) {
2524 HILOG_ERROR("Write [(*it)] failed!");
2525 return ERR_APPEXECFWK_PARCEL_ERROR;
2526 }
2527 }
2528
2529 data.WriteInt32(static_cast<int32_t>(type));
2530
2531 MessageParcel reply;
2532 MessageOption option(MessageOption::TF_SYNC);
2533 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_LOCK_FORMS, data, reply, option);
2534 if (error != ERR_OK) {
2535 HILOG_ERROR("SendRequest:%{public}d failed", error);
2536 return error;
2537 }
2538 return reply.ReadInt32();
2539 }
2540
IsFormBundleProtected(const std::string & bundleName,int64_t formId)2541 bool FormMgrProxy::IsFormBundleProtected(const std::string &bundleName, int64_t formId)
2542 {
2543 MessageParcel data;
2544 if (!WriteInterfaceToken(data)) {
2545 HILOG_ERROR("write interface token failed");
2546 return true;
2547 }
2548
2549 if (!data.WriteString(bundleName)) {
2550 HILOG_ERROR("write bundleName failed");
2551 return true;
2552 }
2553
2554 if (!data.WriteInt64(formId)) {
2555 HILOG_ERROR("fail write formId ");
2556 return true;
2557 }
2558
2559 MessageParcel reply;
2560 MessageOption option;
2561 int error = SendTransactCmd(
2562 IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_PEOTECTED, data, reply, option);
2563 if (error != ERR_OK) {
2564 HILOG_ERROR("SendRequest:%{public}d failed", error);
2565 return false;
2566 }
2567 return reply.ReadBool();
2568 }
2569
IsFormBundleExempt(int64_t formId)2570 bool FormMgrProxy::IsFormBundleExempt(int64_t formId)
2571 {
2572 MessageParcel data;
2573 if (!WriteInterfaceToken(data)) {
2574 HILOG_ERROR("write interface token failed");
2575 return true;
2576 }
2577
2578 if (!data.WriteInt64(formId)) {
2579 HILOG_ERROR("fail write formId ");
2580 return true;
2581 }
2582
2583 MessageParcel reply;
2584 MessageOption option;
2585 int error = SendTransactCmd(
2586 IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_EXEMPT, data, reply, option);
2587 if (error != ERR_OK) {
2588 HILOG_ERROR("SendRequest:%{public}d failed", error);
2589 return false;
2590 }
2591 return reply.ReadBool();
2592 }
2593
NotifyFormLocked(const int64_t & formId,bool isLocked)2594 int32_t FormMgrProxy::NotifyFormLocked(const int64_t &formId, bool isLocked)
2595 {
2596 MessageParcel data;
2597 if (!WriteInterfaceToken(data)) {
2598 HILOG_ERROR("error to write interface token");
2599 return ERR_APPEXECFWK_PARCEL_ERROR;
2600 }
2601 if (!data.WriteInt64(formId)) {
2602 HILOG_ERROR("error to write formId");
2603 return ERR_APPEXECFWK_PARCEL_ERROR;
2604 }
2605 if (!data.WriteBool(isLocked)) {
2606 HILOG_ERROR("fail write bool isLocked");
2607 return ERR_APPEXECFWK_PARCEL_ERROR;
2608 }
2609
2610 MessageParcel reply;
2611 MessageOption option;
2612 int error = SendTransactCmd(
2613 IFormMgr::Message::FORM_MGR_NOTIFY_FORM_LOCKED,
2614 data,
2615 reply,
2616 option);
2617 if (error != ERR_OK) {
2618 HILOG_ERROR("SendRequest:%{public}d failed", error);
2619 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2620 }
2621
2622 int32_t result = reply.ReadInt32();
2623 if (result != ERR_OK) {
2624 HILOG_ERROR("read reply result failed");
2625 return result;
2626 }
2627 return result;
2628 }
2629
UpdateFormSize(const int64_t & formId,float width,float height,float borderWidth)2630 ErrCode FormMgrProxy::UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth)
2631 {
2632 HILOG_DEBUG("start");
2633 MessageParcel data;
2634 if (!WriteInterfaceToken(data)) {
2635 HILOG_ERROR("write interface token failed");
2636 return ERR_APPEXECFWK_PARCEL_ERROR;
2637 }
2638 if (!data.WriteInt64(formId)) {
2639 HILOG_ERROR("fail write formId ");
2640 return ERR_APPEXECFWK_PARCEL_ERROR;
2641 }
2642 if (!data.WriteFloat(width)) {
2643 HILOG_ERROR("fail write width");
2644 return ERR_APPEXECFWK_PARCEL_ERROR;
2645 }
2646 if (!data.WriteFloat(height)) {
2647 HILOG_ERROR("fail write height");
2648 return ERR_APPEXECFWK_PARCEL_ERROR;
2649 }
2650 if (!data.WriteFloat(borderWidth)) {
2651 HILOG_ERROR("fail write borderWidth");
2652 return ERR_APPEXECFWK_PARCEL_ERROR;
2653 }
2654 MessageParcel reply;
2655 MessageOption option(MessageOption::TF_SYNC);
2656 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_FORM_SIZE, data, reply, option);
2657 if (error != ERR_OK) {
2658 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2659 return error;
2660 }
2661 return reply.ReadInt32();
2662 }
2663
OpenFormEditAbility(const std::string & abilityName,const int64_t & formId,bool isMainPage)2664 ErrCode FormMgrProxy::OpenFormEditAbility(const std::string &abilityName, const int64_t &formId, bool isMainPage)
2665 {
2666 HILOG_DEBUG("start");
2667 MessageParcel data;
2668 if (!WriteInterfaceToken(data)) {
2669 HILOG_ERROR("write interface token failed");
2670 return ERR_APPEXECFWK_PARCEL_ERROR;
2671 }
2672 if (!data.WriteString(abilityName)) {
2673 HILOG_ERROR("fail write abilityName ");
2674 return ERR_APPEXECFWK_PARCEL_ERROR;
2675 }
2676 if (!data.WriteInt64(formId)) {
2677 HILOG_ERROR("fail write formId ");
2678 return ERR_APPEXECFWK_PARCEL_ERROR;
2679 }
2680 if (!data.WriteBool(isMainPage)) {
2681 HILOG_ERROR("fail write isMainPage ");
2682 return ERR_APPEXECFWK_PARCEL_ERROR;
2683 }
2684
2685 MessageParcel reply;
2686 MessageOption option(MessageOption::TF_SYNC);
2687 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_OPEN_FORM_EDIT_ABILITY, data, reply, option);
2688 if (error != ERR_OK) {
2689 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2690 return error;
2691 }
2692 return reply.ReadInt32();
2693 }
2694
RegisterOverflowProxy(const sptr<IRemoteObject> & callerToken)2695 bool FormMgrProxy::RegisterOverflowProxy(const sptr<IRemoteObject> &callerToken)
2696 {
2697 HILOG_DEBUG("call");
2698 MessageParcel data;
2699 if (!WriteInterfaceToken(data)) {
2700 HILOG_ERROR("Write interface token failed");
2701 return false;
2702 }
2703 if (!data.WriteRemoteObject(callerToken)) {
2704 HILOG_ERROR("Write callerToken failed");
2705 return false;
2706 }
2707 MessageParcel reply;
2708 MessageOption option;
2709 ErrCode error = SendTransactCmd(IFormMgr::Message::FORM_MGR_REGISTER_OVERFLOW_PROXY, data, reply, option);
2710 if (error != ERR_OK) {
2711 HILOG_ERROR("SendRequest: %{public}d failed", error);
2712 return false;
2713 }
2714 return reply.ReadBool();
2715 }
2716
UnregisterOverflowProxy()2717 bool FormMgrProxy::UnregisterOverflowProxy()
2718 {
2719 HILOG_DEBUG("call");
2720 MessageParcel data;
2721 if (!WriteInterfaceToken(data)) {
2722 HILOG_ERROR("write interface token failed");
2723 return false;
2724 }
2725 MessageParcel reply;
2726 MessageOption option;
2727 ErrCode error = SendTransactCmd(
2728 IFormMgr::Message::FORM_MGR_UNREGISTER_OVERFLOW_PROXY, data, reply, option);
2729 if (error != ERR_OK) {
2730 HILOG_ERROR("SendRequest:%{public}d failed", error);
2731 return false;
2732 }
2733 return reply.ReadBool();
2734 }
2735
RequestOverflow(const int64_t formId,const OverflowInfo & overflowInfo,bool isOverflow)2736 ErrCode FormMgrProxy::RequestOverflow(const int64_t formId, const OverflowInfo &overflowInfo, bool isOverflow)
2737 {
2738 HILOG_INFO("call");
2739 MessageParcel data;
2740 if (!WriteInterfaceToken(data)) {
2741 HILOG_ERROR("Write interface token failed");
2742 return ERR_APPEXECFWK_PARCEL_ERROR;
2743 }
2744 if (!data.WriteInt64(formId)) {
2745 HILOG_ERROR("Write formId failed");
2746 return ERR_APPEXECFWK_PARCEL_ERROR;
2747 }
2748 if (!data.WriteParcelable(&overflowInfo)) {
2749 HILOG_ERROR("Write overflowInfo failed");
2750 return ERR_APPEXECFWK_PARCEL_ERROR;
2751 }
2752 if (!data.WriteBool(isOverflow)) {
2753 HILOG_ERROR("Write isOverflow failed");
2754 return ERR_APPEXECFWK_PARCEL_ERROR;
2755 }
2756
2757 MessageParcel reply;
2758 MessageOption option;
2759 ErrCode error = SendTransactCmd(IFormMgr::Message::FORM_MGR_REQUEST_OVERFLOW, data, reply, option);
2760 if (error != ERR_OK) {
2761 HILOG_ERROR("SendRequest failed: %{public}d", error);
2762 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2763 }
2764 return reply.ReadInt32();
2765 }
2766
RegisterChangeSceneAnimationStateProxy(const sptr<IRemoteObject> & callerToken)2767 bool FormMgrProxy::RegisterChangeSceneAnimationStateProxy(const sptr<IRemoteObject> &callerToken)
2768 {
2769 HILOG_DEBUG("call");
2770 MessageParcel data;
2771 if (!WriteInterfaceToken(data)) {
2772 HILOG_ERROR("write interface token failed");
2773 return false;
2774 }
2775 if (!data.WriteRemoteObject(callerToken)) {
2776 HILOG_ERROR("write callerToken failed");
2777 return false;
2778 }
2779 MessageParcel reply;
2780 MessageOption option;
2781 ErrCode error = SendTransactCmd(
2782 IFormMgr::Message::FORM_MGR_REGISTER_CHANGE_SCENEANIMATION_STATE_PROXY, data, reply, option);
2783 if (error != ERR_OK) {
2784 HILOG_ERROR("SendRequest:%{public}d failed", error);
2785 return false;
2786 }
2787 return reply.ReadBool();
2788 }
2789
UnregisterChangeSceneAnimationStateProxy()2790 bool FormMgrProxy::UnregisterChangeSceneAnimationStateProxy()
2791 {
2792 HILOG_DEBUG("call");
2793 MessageParcel data;
2794 if (!WriteInterfaceToken(data)) {
2795 HILOG_ERROR("write interface token failed");
2796 return false;
2797 }
2798 MessageParcel reply;
2799 MessageOption option;
2800 ErrCode error = SendTransactCmd(
2801 IFormMgr::Message::FORM_MGR_UNREGISTER_CHANGE_SCENEANIMATION_STATE_PROXY, data, reply, option);
2802 if (error != ERR_OK) {
2803 HILOG_ERROR("SendRequest:%{public}d failed", error);
2804 return false;
2805 }
2806 return reply.ReadBool();
2807 }
2808
ChangeSceneAnimationState(const int64_t formId,int32_t state)2809 ErrCode FormMgrProxy::ChangeSceneAnimationState(const int64_t formId, int32_t state)
2810 {
2811 HILOG_INFO("call");
2812 MessageParcel data;
2813 if (!WriteInterfaceToken(data)) {
2814 HILOG_ERROR("Write interface token failed");
2815 return ERR_APPEXECFWK_PARCEL_ERROR;
2816 }
2817 if (!data.WriteInt64(formId)) {
2818 HILOG_ERROR("Write formId failed");
2819 return ERR_APPEXECFWK_PARCEL_ERROR;
2820 }
2821 if (!data.WriteInt32(state)) {
2822 HILOG_ERROR("Write state failed");
2823 return ERR_APPEXECFWK_PARCEL_ERROR;
2824 }
2825
2826 MessageParcel reply;
2827 MessageOption option;
2828 ErrCode error = SendTransactCmd(
2829 IFormMgr::Message::FORM_MGR_CHANGE_SCENE_ANIMATION_STATE,
2830 data,
2831 reply,
2832 option);
2833 if (error != ERR_OK) {
2834 HILOG_ERROR("SendRequest failed: %{public}d", error);
2835 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2836 }
2837 return reply.ReadInt32();
2838 }
2839
RegisterGetFormRectProxy(const sptr<IRemoteObject> & callerToken)2840 bool FormMgrProxy::RegisterGetFormRectProxy(const sptr<IRemoteObject> &callerToken)
2841 {
2842 MessageParcel data;
2843 if (!WriteInterfaceToken(data)) {
2844 HILOG_ERROR("Failed to write interface token");
2845 return false;
2846 }
2847
2848 if (!data.WriteRemoteObject(callerToken)) {
2849 HILOG_ERROR("Failed to write callerToken");
2850 return false;
2851 }
2852
2853 MessageParcel reply;
2854 MessageOption option;
2855 int error = SendTransactCmd(
2856 IFormMgr::Message::FORM_MGR_REGISTER_GET_FORM_RECT,
2857 data,
2858 reply,
2859 option);
2860 if (error != ERR_OK) {
2861 HILOG_ERROR("Failed to SendRequest: %{public}d", error);
2862 return false;
2863 }
2864 return reply.ReadBool();
2865 }
2866
UnregisterGetFormRectProxy()2867 bool FormMgrProxy::UnregisterGetFormRectProxy()
2868 {
2869 HILOG_DEBUG("call");
2870 MessageParcel data;
2871 if (!WriteInterfaceToken(data)) {
2872 HILOG_ERROR("write interface token failed");
2873 return false;
2874 }
2875 MessageParcel reply;
2876 MessageOption option;
2877 ErrCode error = SendTransactCmd(
2878 IFormMgr::Message::FORM_MGR_UNREGISTER_GET_FORM_RECT, data, reply, option);
2879 if (error != ERR_OK) {
2880 HILOG_ERROR("SendRequest:%{public}d failed", error);
2881 return false;
2882 }
2883 return reply.ReadBool();
2884 }
2885
GetFormRect(const int64_t formId,Rect & rect)2886 ErrCode FormMgrProxy::GetFormRect(const int64_t formId, Rect &rect)
2887 {
2888 MessageParcel data;
2889 if (!WriteInterfaceToken(data)) {
2890 HILOG_ERROR("Failed to write interface token");
2891 return ERR_APPEXECFWK_PARCEL_ERROR;
2892 }
2893
2894 if (!data.WriteInt64(formId)) {
2895 HILOG_ERROR("Failed to write formId");
2896 return ERR_APPEXECFWK_PARCEL_ERROR;
2897 }
2898
2899 MessageParcel reply;
2900 MessageOption option;
2901 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_GET_FORM_RECT, data, reply, option);
2902 if (error != ERR_OK) {
2903 HILOG_ERROR("Failed to SendRequest: %{public}d", error);
2904 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2905 }
2906 error = reply.ReadInt32();
2907 if (error != ERR_OK) {
2908 HILOG_ERROR("Read reply result fail: %{public}d", error);
2909 return error;
2910 }
2911 std::unique_ptr<Rect> result(reply.ReadParcelable<Rect>());
2912 if (!result) {
2913 HILOG_ERROR("Failed to get parcelable info");
2914 return ERR_APPEXECFWK_PARCEL_ERROR;
2915 }
2916 rect = *result;
2917 return ERR_OK;
2918 }
2919
UpdateFormSize(const int64_t formId,const int32_t newDimension,const Rect & newRect)2920 ErrCode FormMgrProxy::UpdateFormSize(const int64_t formId, const int32_t newDimension, const Rect &newRect)
2921 {
2922 HILOG_INFO("call");
2923 MessageParcel data;
2924 if (!WriteInterfaceToken(data)) {
2925 HILOG_ERROR("Write interface token failed");
2926 return ERR_APPEXECFWK_PARCEL_ERROR;
2927 }
2928 if (!data.WriteInt64(formId)) {
2929 HILOG_ERROR("Write formId failed");
2930 return ERR_APPEXECFWK_PARCEL_ERROR;
2931 }
2932 if (!data.WriteInt32(newDimension)) {
2933 HILOG_ERROR("Write newDimension failed");
2934 return ERR_APPEXECFWK_PARCEL_ERROR;
2935 }
2936 if (!data.WriteParcelable(&newRect)) {
2937 HILOG_ERROR("Write newRect failed");
2938 return ERR_APPEXECFWK_PARCEL_ERROR;
2939 }
2940 MessageParcel reply;
2941 MessageOption option;
2942 ErrCode error = SendTransactCmd(IFormMgr::Message::FORM_MGR_NOTIFY_UPDATE_FORM_SIZE, data, reply, option);
2943 if (error != ERR_OK) {
2944 HILOG_ERROR("SendRequest failed: %{public}d", error);
2945 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2946 }
2947 return reply.ReadInt32();
2948 }
2949
RegisterGetLiveFormStatusProxy(const sptr<IRemoteObject> & callerToken)2950 bool FormMgrProxy::RegisterGetLiveFormStatusProxy(const sptr<IRemoteObject> &callerToken)
2951 {
2952 MessageParcel data;
2953 if (!WriteInterfaceToken(data)) {
2954 HILOG_ERROR("Failed to write interface token");
2955 return false;
2956 }
2957
2958 if (!data.WriteRemoteObject(callerToken)) {
2959 HILOG_ERROR("Failed to write callerToken");
2960 return false;
2961 }
2962
2963 MessageParcel reply;
2964 MessageOption option;
2965 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_REGISTER_GET_LIVE_FORM_STATUS, data, reply, option);
2966 if (error != ERR_OK) {
2967 HILOG_ERROR("Failed to SendRequest: %{public}d", error);
2968 return false;
2969 }
2970 return reply.ReadBool();
2971 }
2972
UnregisterGetLiveFormStatusProxy()2973 bool FormMgrProxy::UnregisterGetLiveFormStatusProxy()
2974 {
2975 HILOG_DEBUG("call");
2976 MessageParcel data;
2977 if (!WriteInterfaceToken(data)) {
2978 HILOG_ERROR("write interface token failed");
2979 return false;
2980 }
2981
2982 MessageParcel reply;
2983 MessageOption option;
2984 ErrCode error = SendTransactCmd(
2985 IFormMgr::Message::FORM_MGR_UNREGISTER_GET_LIVE_FORM_STATUS, data, reply, option);
2986 if (error != ERR_OK) {
2987 HILOG_ERROR("SendRequest:%{public}d failed", error);
2988 return false;
2989 }
2990 return reply.ReadBool();
2991 }
2992 } // namespace AppExecFwk
2993 } // namespace OHOS
2994