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
ShareForm(int64_t formId,const std::string & deviceId,const sptr<IRemoteObject> & callerToken,int64_t requestCode)1539 int32_t FormMgrProxy::ShareForm(int64_t formId, const std::string &deviceId, const sptr<IRemoteObject> &callerToken,
1540 int64_t requestCode)
1541 {
1542 MessageParcel data;
1543 if (!WriteInterfaceToken(data)) {
1544 HILOG_ERROR("error to write interface token");
1545 return ERR_APPEXECFWK_PARCEL_ERROR;
1546 }
1547
1548 if (!data.WriteInt64(formId)) {
1549 HILOG_ERROR("error to write formId");
1550 return ERR_APPEXECFWK_PARCEL_ERROR;
1551 }
1552
1553 if (!data.WriteString(deviceId)) {
1554 HILOG_ERROR("fail write deviceId");
1555 return ERR_APPEXECFWK_PARCEL_ERROR;
1556 }
1557
1558 if (!data.WriteRemoteObject(callerToken)) {
1559 HILOG_ERROR("write callerToken failed");
1560 return ERR_APPEXECFWK_PARCEL_ERROR;
1561 }
1562
1563 if (!data.WriteInt64(requestCode)) {
1564 HILOG_ERROR("write requestCode failed");
1565 return ERR_APPEXECFWK_PARCEL_ERROR;
1566 }
1567
1568 MessageParcel reply;
1569 MessageOption option;
1570 auto error = SendTransactCmd(
1571 IFormMgr::Message::FORM_MGR_SHARE_FORM, data, reply, option);
1572 if (error != ERR_OK) {
1573 HILOG_ERROR("SendRequest:%{public}d failed", error);
1574 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1575 }
1576 return reply.ReadInt32();
1577 }
1578
AcquireFormData(int64_t formId,int64_t requestCode,const sptr<IRemoteObject> & callerToken,AAFwk::WantParams & formData)1579 int32_t FormMgrProxy::AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
1580 AAFwk::WantParams &formData)
1581 {
1582 MessageParcel data;
1583 if (!WriteInterfaceToken(data)) {
1584 HILOG_ERROR("write interface token failed");
1585 return ERR_APPEXECFWK_PARCEL_ERROR;
1586 }
1587
1588 if (!data.WriteInt64(formId)) {
1589 HILOG_ERROR("write formId 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 if (!data.WriteRemoteObject(callerToken)) {
1599 HILOG_ERROR("write callerToken failed");
1600 return ERR_APPEXECFWK_PARCEL_ERROR;
1601 }
1602
1603 int error;
1604 MessageParcel reply;
1605 MessageOption option(MessageOption::TF_SYNC);
1606 error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ACQUIRE_DATA, data, reply, option);
1607 if (error != ERR_OK) {
1608 return error;
1609 }
1610
1611 error = reply.ReadInt32();
1612 if (error != ERR_OK) {
1613 HILOG_ERROR("read replyResult failed");
1614 return error;
1615 }
1616 std::shared_ptr<AAFwk::WantParams> wantParams(reply.ReadParcelable<AAFwk::WantParams>());
1617 if (wantParams == nullptr) {
1618 HILOG_ERROR("ReadParcelable<wantParams> failed");
1619 return ERR_APPEXECFWK_PARCEL_ERROR;
1620 }
1621 formData = *wantParams;
1622 return ERR_OK;
1623 }
1624
RecvFormShareInfoFromRemote(const FormShareInfo & info)1625 int32_t FormMgrProxy::RecvFormShareInfoFromRemote(const FormShareInfo &info)
1626 {
1627 MessageParcel data;
1628 if (!WriteInterfaceToken(data)) {
1629 HILOG_ERROR("write interface token failed");
1630 return ERR_APPEXECFWK_PARCEL_ERROR;
1631 }
1632
1633 if (!data.WriteParcelable(&info)) {
1634 HILOG_ERROR("fail write form share info");
1635 return ERR_APPEXECFWK_PARCEL_ERROR;
1636 }
1637
1638 MessageParcel reply;
1639 MessageOption option;
1640 auto error = SendTransactCmd(
1641 IFormMgr::Message::FORM_MGR_RECV_FORM_SHARE_INFO_FROM_REMOTE, data, reply, option);
1642 if (error != ERR_OK) {
1643 HILOG_ERROR("SendRequest:%{public}d failed", error);
1644 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1645 }
1646 return reply.ReadInt32();
1647 }
1648
CheckFMSReady()1649 bool FormMgrProxy::CheckFMSReady()
1650 {
1651 HILOG_DEBUG("start");
1652 MessageParcel data;
1653 // write in token to help identify which stub to be called
1654 if (!WriteInterfaceToken(data)) {
1655 HILOG_ERROR("write interface token failed");
1656 return false;
1657 }
1658 // send request
1659 MessageParcel reply;
1660 MessageOption option;
1661 int error = SendTransactCmd(
1662 IFormMgr::Message::FORM_MGR_CHECK_FMS_READY, data, reply, option);
1663 if (error != ERR_OK) {
1664 HILOG_ERROR("SendRequest:%{public}d failed", error);
1665 return false;
1666 }
1667 // retrieve and return result;
1668 return reply.ReadBool();
1669 }
1670
IsSystemAppForm(const std::string & bundleName)1671 bool FormMgrProxy::IsSystemAppForm(const std::string &bundleName)
1672 {
1673 MessageParcel data;
1674 // write in token to help identify which stub to be called
1675 if (!WriteInterfaceToken(data)) {
1676 HILOG_ERROR("write interface token failed");
1677 return false;
1678 }
1679 if (!data.WriteString(bundleName)) {
1680 HILOG_ERROR("write bundleName failed");
1681 return false;
1682 }
1683 MessageParcel reply;
1684 MessageOption option;
1685 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_IS_SYSTEM_APP_FORM, data, reply, option);
1686 if (error != ERR_OK) {
1687 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
1688 return false;
1689 }
1690 return reply.ReadBool();
1691 }
1692
SetBackgroundFunction(const std::string funcName,const std::string params)1693 int32_t FormMgrProxy::SetBackgroundFunction(const std::string funcName, const std::string params)
1694 {
1695 HILOG_DEBUG("start");
1696 MessageParcel data;
1697 // write in token to help identify which stub to be called
1698 if (!data.WriteString16(Str8ToStr16(funcName))) {
1699 HILOG_ERROR("write funcName failed");
1700 return ERR_APPEXECFWK_PARCEL_ERROR;
1701 }
1702 if (!data.WriteString16(Str8ToStr16(params))) {
1703 HILOG_ERROR("write params failed");
1704 return ERR_APPEXECFWK_PARCEL_ERROR;
1705 }
1706 // send request
1707 MessageParcel reply;
1708 MessageOption option;
1709 sptr<IRemoteObject> remote = Remote();
1710 if (!remote) {
1711 HILOG_ERROR("get remoteObject failed");
1712 return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED;
1713 }
1714 int error = remote->SendRequest(Constants::EVENT_CALL_NOTIFY, data, reply, option);
1715 if (error != ERR_OK) {
1716 HILOG_ERROR("SendRequest:%{public}d failed", error);
1717 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1718 }
1719 // retrieve and return result;
1720 return reply.ReadInt32();
1721 }
1722
GetFormsCount(bool isTempFormFlag,int32_t & formCount)1723 int32_t FormMgrProxy::GetFormsCount(bool isTempFormFlag, int32_t &formCount)
1724 {
1725 HILOG_INFO("start");
1726 MessageParcel data;
1727 if (!WriteInterfaceToken(data)) {
1728 HILOG_ERROR("write interface token failed");
1729 return ERR_APPEXECFWK_PARCEL_ERROR;
1730 }
1731 if (!data.WriteBool(isTempFormFlag)) {
1732 HILOG_ERROR("write bool isEnableUpdate failed");
1733 return ERR_APPEXECFWK_PARCEL_ERROR;
1734 }
1735 MessageParcel reply;
1736 MessageOption option;
1737 int error = SendTransactCmd(
1738 IFormMgr::Message::FORM_MGR_GET_FORMS_COUNT, data, reply, option);
1739 if (error != ERR_OK) {
1740 HILOG_ERROR("SendRequest:%{public}d failed", error);
1741 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1742 }
1743 int32_t result = reply.ReadInt32();
1744 formCount = reply.ReadInt32();
1745 return result;
1746 }
1747
RegisterFormAddObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1748 ErrCode FormMgrProxy::RegisterFormAddObserverByBundle(const std::string bundleName,
1749 const sptr<IRemoteObject> &callerToken)
1750 {
1751 HILOG_DEBUG("RegisterFormAddObserverByBundle start");
1752 MessageParcel data;
1753 if (!WriteInterfaceToken(data)) {
1754 HILOG_ERROR("write interface token failed");
1755 return ERR_APPEXECFWK_PARCEL_ERROR;
1756 }
1757
1758 if (!data.WriteString(bundleName)) {
1759 HILOG_ERROR("error to write bundleName");
1760 return ERR_APPEXECFWK_PARCEL_ERROR;
1761 }
1762
1763 if (!data.WriteRemoteObject(callerToken)) {
1764 HILOG_ERROR("write callerToken failed");
1765 return ERR_APPEXECFWK_PARCEL_ERROR;
1766 }
1767
1768 MessageParcel reply;
1769 MessageOption option(MessageOption::TF_ASYNC);
1770 auto error = SendTransactCmd(
1771 IFormMgr::Message::FORM_MGR_REGISTER_FORM_ADD_OBSERVER_BY_BUNDLE, data, reply, option);
1772 if (error != ERR_OK) {
1773 HILOG_ERROR("SendRequest:%{public}d failed", error);
1774 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1775 }
1776 return reply.ReadInt32();
1777 }
1778
RegisterFormRemoveObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1779 ErrCode FormMgrProxy::RegisterFormRemoveObserverByBundle(const std::string bundleName,
1780 const sptr<IRemoteObject> &callerToken)
1781 {
1782 HILOG_DEBUG("start");
1783 MessageParcel data;
1784 if (!WriteInterfaceToken(data)) {
1785 HILOG_ERROR("write interface token failed");
1786 return ERR_APPEXECFWK_PARCEL_ERROR;
1787 }
1788
1789 if (!data.WriteString(bundleName)) {
1790 HILOG_ERROR("write bundleName failed");
1791 return ERR_APPEXECFWK_PARCEL_ERROR;
1792 }
1793
1794 if (!data.WriteRemoteObject(callerToken)) {
1795 HILOG_ERROR("write callerToken failed");
1796 return ERR_APPEXECFWK_PARCEL_ERROR;
1797 }
1798
1799 MessageParcel reply;
1800 MessageOption option(MessageOption::TF_ASYNC);
1801 auto error = SendTransactCmd(
1802 IFormMgr::Message::FORM_MGR_REGISTER_FORM_REMOVE_OBSERVER_BY_BUNDLE,
1803 data, reply, option);
1804 if (error != ERR_OK) {
1805 HILOG_ERROR("SendRequest:%{public}d failed", error);
1806 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1807 }
1808 return reply.ReadInt32();
1809 }
1810
GetHostFormsCount(std::string & bundleName,int32_t & formCount)1811 int32_t FormMgrProxy::GetHostFormsCount(std::string &bundleName, int32_t &formCount)
1812 {
1813 HILOG_INFO("start");
1814 MessageParcel data;
1815 if (!WriteInterfaceToken(data)) {
1816 HILOG_ERROR("write interface token failed");
1817 return ERR_APPEXECFWK_PARCEL_ERROR;
1818 }
1819 if (!data.WriteString(bundleName)) {
1820 HILOG_ERROR("write bundleName failed");
1821 return ERR_APPEXECFWK_PARCEL_ERROR;
1822 }
1823 MessageParcel reply;
1824 MessageOption option;
1825 int error = SendTransactCmd(
1826 IFormMgr::Message::FORM_MGR_GET_HOST_FORMS_COUNT, data, reply, option);
1827 if (error != ERR_OK) {
1828 HILOG_ERROR("SendRequest:%{public}d failed", error);
1829 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1830 }
1831 int32_t result = reply.ReadInt32();
1832 formCount = reply.ReadInt32();
1833 return result;
1834 }
1835
GetFormInstancesByFilter(const FormInstancesFilter & formInstancesFilter,std::vector<FormInstance> & formInstances)1836 int32_t FormMgrProxy::GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
1837 std::vector<FormInstance> &formInstances)
1838 {
1839 HILOG_DEBUG("start");
1840 MessageParcel data;
1841 // write in token to help identify which stub to be called.
1842 if (!WriteInterfaceToken(data)) {
1843 HILOG_ERROR("write interface token failed");
1844 return ERR_APPEXECFWK_PARCEL_ERROR;
1845 }
1846 if (!data.WriteParcelable(&formInstancesFilter)) {
1847 HILOG_ERROR("fail write formInstancesFilter");
1848 return ERR_APPEXECFWK_PARCEL_ERROR;
1849 }
1850 auto error = GetFormInstance(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_FILTER, data, formInstances);
1851 if (error != ERR_OK) {
1852 HILOG_ERROR("fail get form instances by filter:%{public}d", error);
1853 }
1854
1855 return error;
1856 }
1857
GetFormInstanceById(const int64_t formId,FormInstance & formInstance)1858 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, FormInstance &formInstance)
1859 {
1860 HILOG_DEBUG("GetFormInstanceById start");
1861 MessageParcel data;
1862 // write in token to help identify which stub to be called.
1863 if (!WriteInterfaceToken(data)) {
1864 HILOG_ERROR("error to write interface token");
1865 return ERR_APPEXECFWK_PARCEL_ERROR;
1866 }
1867 if (!data.WriteInt64(formId)) {
1868 HILOG_ERROR("error to write formId");
1869 return ERR_APPEXECFWK_PARCEL_ERROR;
1870 }
1871 auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1872 data, formInstance);
1873 if (error != ERR_OK) {
1874 HILOG_ERROR("get parcelable info failed");
1875 }
1876
1877 return error;
1878 }
1879
GetFormInstanceById(const int64_t formId,bool isUnusedInclude,FormInstance & formInstance)1880 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, bool isUnusedInclude, FormInstance &formInstance)
1881 {
1882 HILOG_DEBUG("start");
1883 MessageParcel data;
1884 // write in token to help identify which stub to be called.
1885 if (!WriteInterfaceToken(data)) {
1886 HILOG_ERROR("write interface token failed");
1887 return ERR_APPEXECFWK_PARCEL_ERROR;
1888 }
1889 if (!data.WriteInt64(formId)) {
1890 HILOG_ERROR("write formId failed");
1891 return ERR_APPEXECFWK_PARCEL_ERROR;
1892 }
1893 if (!data.WriteBool(isUnusedInclude)) {
1894 HILOG_ERROR("write isUnusedInclude failed");
1895 return ERR_APPEXECFWK_PARCEL_ERROR;
1896 }
1897
1898 auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1899 data, formInstance);
1900 if (error != ERR_OK) {
1901 HILOG_ERROR("get parcelable info failed");
1902 }
1903
1904 return error;
1905 }
1906
GetFormInstance(IFormMgr::Message code,MessageParcel & data,std::vector<FormInstance> & formInstances)1907 ErrCode FormMgrProxy::GetFormInstance(IFormMgr::Message code, MessageParcel &data,
1908 std::vector<FormInstance> &formInstances)
1909 {
1910 HILOG_DEBUG("GetFormInstance start");
1911 int error;
1912 MessageParcel reply;
1913 MessageOption option(MessageOption::TF_SYNC);
1914 error = SendTransactCmd(code, data, reply, option);
1915 if (error != ERR_OK) {
1916 return error;
1917 }
1918 error = reply.ReadInt32();
1919 if (error != ERR_OK) {
1920 HILOG_ERROR("read replyResult failed");
1921 return error;
1922 }
1923 auto ret = GetParcelableInfos<FormInstance>(reply, formInstances);
1924 if (ret != ERR_OK) {
1925 HILOG_ERROR("fail get parcelable infos");
1926 return ERR_APPEXECFWK_PARCEL_ERROR;
1927 }
1928 return ret;
1929 }
1930
RegisterAddObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1931 ErrCode FormMgrProxy::RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1932 {
1933 HILOG_DEBUG("start");
1934 MessageParcel data;
1935 if (!WriteInterfaceToken(data)) {
1936 HILOG_ERROR("error to write interface token");
1937 return ERR_APPEXECFWK_PARCEL_ERROR;
1938 }
1939 if (!data.WriteString(bundleName)) {
1940 HILOG_ERROR("error to write bundleName");
1941 return ERR_APPEXECFWK_PARCEL_ERROR;
1942 }
1943 if (!data.WriteRemoteObject(callerToken)) {
1944 HILOG_ERROR("error to write callerToken");
1945 return ERR_APPEXECFWK_PARCEL_ERROR;
1946 }
1947 MessageParcel reply;
1948 MessageOption option(MessageOption::TF_ASYNC);
1949 auto error = SendTransactCmd(
1950 IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER, data, reply, option);
1951 if (error != ERR_OK) {
1952 HILOG_ERROR("error to SendRequest:%{public}d", error);
1953 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1954 }
1955 return reply.ReadInt32();
1956 }
1957
RegisterRemoveObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1958 ErrCode FormMgrProxy::RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1959 {
1960 HILOG_DEBUG("call");
1961 MessageParcel data;
1962 if (!WriteInterfaceToken(data)) {
1963 HILOG_ERROR("write interface token failed");
1964 return ERR_APPEXECFWK_PARCEL_ERROR;
1965 }
1966 if (!data.WriteString(bundleName)) {
1967 HILOG_ERROR("write bundleName failed");
1968 return ERR_APPEXECFWK_PARCEL_ERROR;
1969 }
1970 if (!data.WriteRemoteObject(callerToken)) {
1971 HILOG_ERROR("write callerToken failed");
1972 return ERR_APPEXECFWK_PARCEL_ERROR;
1973 }
1974 MessageParcel reply;
1975 MessageOption option(MessageOption::TF_ASYNC);
1976 int error = SendTransactCmd(
1977 IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER, data, reply, option);
1978 if (error != ERR_OK) {
1979 HILOG_ERROR("SendRequest:%{public}d failed", error);
1980 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1981 }
1982 return reply.ReadInt32();
1983 }
1984
RegisterFormRouterProxy(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken)1985 ErrCode FormMgrProxy::RegisterFormRouterProxy(const std::vector<int64_t> &formIds,
1986 const sptr<IRemoteObject> &callerToken)
1987 {
1988 HILOG_DEBUG("call");
1989 MessageParcel data;
1990 if (!WriteInterfaceToken(data)) {
1991 HILOG_ERROR("write interface token failed");
1992 return ERR_APPEXECFWK_PARCEL_ERROR;
1993 }
1994 if (!data.WriteInt64Vector(formIds)) {
1995 HILOG_ERROR("write vector formIds failed");
1996 return ERR_APPEXECFWK_PARCEL_ERROR;
1997 }
1998 if (!data.WriteRemoteObject(callerToken)) {
1999 HILOG_ERROR("write callerToken failed");
2000 return ERR_APPEXECFWK_PARCEL_ERROR;
2001 }
2002 MessageParcel reply;
2003 MessageOption option;
2004 int error = SendTransactCmd(
2005 IFormMgr::Message::FORM_MGR_REGISTER_FORM_ROUTER_PROXY, data, reply, option);
2006 if (error != ERR_OK) {
2007 HILOG_ERROR("SendRequest:%{public}d failed", error);
2008 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2009 }
2010 return reply.ReadInt32();
2011 }
2012
UnregisterFormRouterProxy(const std::vector<int64_t> & formIds)2013 ErrCode FormMgrProxy::UnregisterFormRouterProxy(const std::vector<int64_t> &formIds)
2014 {
2015 HILOG_DEBUG("call");
2016 MessageParcel data;
2017 if (!WriteInterfaceToken(data)) {
2018 HILOG_ERROR("write interface token failed");
2019 return ERR_APPEXECFWK_PARCEL_ERROR;
2020 }
2021 if (!data.WriteInt64Vector(formIds)) {
2022 HILOG_ERROR("write vector formIds failed");
2023 return ERR_APPEXECFWK_PARCEL_ERROR;
2024 }
2025 MessageParcel reply;
2026 MessageOption option;
2027 int error = SendTransactCmd(
2028 IFormMgr::Message::FORM_MGR_UNREGISTER_FORM_ROUTER_PROXY, data, reply, option);
2029 if (error != ERR_OK) {
2030 HILOG_ERROR("SendRequest:%{public}d failed", error);
2031 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2032 }
2033 return reply.ReadInt32();
2034 }
2035
UpdateProxyForm(int64_t formId,const FormProviderData & FormProviderData,const std::vector<FormDataProxy> & formDataProxies)2036 ErrCode FormMgrProxy::UpdateProxyForm(int64_t formId, const FormProviderData &FormProviderData,
2037 const std::vector<FormDataProxy> &formDataProxies)
2038 {
2039 MessageParcel data;
2040 if (!WriteInterfaceToken(data)) {
2041 HILOG_ERROR("write interface token failed");
2042 return ERR_APPEXECFWK_PARCEL_ERROR;
2043 }
2044 if (!data.WriteInt64(formId)) {
2045 HILOG_ERROR("write formId failed");
2046 return ERR_APPEXECFWK_PARCEL_ERROR;
2047 }
2048 if (!data.WriteParcelable(&FormProviderData)) {
2049 HILOG_ERROR("write formBindingData failed");
2050 return ERR_APPEXECFWK_PARCEL_ERROR;
2051 }
2052 if (!WriteFormDataProxies(data, formDataProxies)) {
2053 HILOG_ERROR("write formDataProxies failed");
2054 return ERR_APPEXECFWK_PARCEL_ERROR;
2055 }
2056 MessageParcel reply;
2057 MessageOption option(MessageOption::TF_SYNC);
2058 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_PROXY_FORM, data, reply, option);
2059 if (error != ERR_OK) {
2060 HILOG_ERROR("fail SendTransactCmd");
2061 return error;
2062 }
2063 return reply.ReadInt32();
2064 }
2065
RequestPublishProxyForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId,const std::vector<FormDataProxy> & formDataProxies)2066 ErrCode FormMgrProxy::RequestPublishProxyForm(Want &want, bool withFormBindingData,
2067 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
2068 const std::vector<FormDataProxy> &formDataProxies)
2069 {
2070 MessageParcel data;
2071
2072 if (!WriteInterfaceToken(data)) {
2073 HILOG_ERROR("write interface token failed");
2074 return ERR_APPEXECFWK_PARCEL_ERROR;
2075 }
2076 if (!data.WriteParcelable(&want)) {
2077 HILOG_ERROR("write want failed");
2078 return ERR_APPEXECFWK_PARCEL_ERROR;
2079 }
2080 if (!data.WriteBool(withFormBindingData)) {
2081 HILOG_ERROR("write withFormBindingData failed");
2082 return ERR_APPEXECFWK_PARCEL_ERROR;
2083 }
2084 if (withFormBindingData) {
2085 if (!data.WriteParcelable(formBindingData.get())) {
2086 HILOG_ERROR("write formBindingData failed");
2087 return ERR_APPEXECFWK_PARCEL_ERROR;
2088 }
2089 }
2090 if (!WriteFormDataProxies(data, formDataProxies)) {
2091 HILOG_ERROR("write formDataProxies failed");
2092 return ERR_APPEXECFWK_PARCEL_ERROR;
2093 }
2094
2095 MessageParcel reply;
2096 MessageOption option(MessageOption::TF_SYNC);
2097 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_PROXY_FORM, data, reply, option);
2098 if (error != ERR_OK) {
2099 HILOG_ERROR("fail SendTransactCmd");
2100 return error;
2101 }
2102 ErrCode errCode = reply.ReadInt32();
2103 if (errCode == ERR_OK) {
2104 formId = reply.ReadInt64();
2105 }
2106 return errCode;
2107 }
2108
WriteFormDataProxies(MessageParcel & data,const std::vector<FormDataProxy> & formDataProxies)2109 bool FormMgrProxy::WriteFormDataProxies(MessageParcel &data, const std::vector<FormDataProxy> &formDataProxies)
2110 {
2111 HILOG_DEBUG("proxies size:%{public}zu", formDataProxies.size());
2112 if (!data.WriteInt32(formDataProxies.size())) {
2113 HILOG_ERROR("fail marshalling form data proxies size");
2114 return false;
2115 }
2116 for (const auto &formDataProxy : formDataProxies) {
2117 if (!data.WriteString16(Str8ToStr16(formDataProxy.key))) {
2118 HILOG_ERROR("fail marshalling formDataProxy key:%{public}s", formDataProxy.key.c_str());
2119 return false;
2120 }
2121 if (!data.WriteString16(Str8ToStr16(formDataProxy.subscribeId))) {
2122 HILOG_ERROR("fail marshalling formDataProxy subscribeId:%{public}s",
2123 formDataProxy.subscribeId.c_str());
2124 return false;
2125 }
2126 }
2127 return true;
2128 }
2129
RegisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)2130 int32_t FormMgrProxy::RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
2131 {
2132 HILOG_DEBUG("start");
2133 MessageParcel data;
2134 // write in token to help identify which stub to be called.
2135 if (!WriteInterfaceToken(data)) {
2136 HILOG_ERROR("error to write interface token");
2137 return ERR_APPEXECFWK_PARCEL_ERROR;
2138 }
2139 // write in interceptor
2140 if (!data.WriteRemoteObject(interceptorCallback)) {
2141 HILOG_ERROR("error to write interceptor");
2142 return ERR_APPEXECFWK_PARCEL_ERROR;
2143 }
2144 // send request.
2145 MessageParcel reply;
2146 MessageOption option;
2147 int error = SendTransactCmd(
2148 IFormMgr::Message::FORM_MGR_REGISTER_PUBLISH_FORM_INTERCEPTOR,
2149 data,
2150 reply,
2151 option);
2152 if (error != ERR_OK) {
2153 HILOG_ERROR("SendRequest:%{public}d failed", error);
2154 return error;
2155 }
2156 // retrieve and return result.
2157 return reply.ReadInt32();
2158 }
2159
UnregisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)2160 int32_t FormMgrProxy::UnregisterPublishFormInterceptor(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("write interface token failed");
2167 return ERR_APPEXECFWK_PARCEL_ERROR;
2168 }
2169 // write in interceptor
2170 if (!data.WriteRemoteObject(interceptorCallback)) {
2171 HILOG_ERROR("fail write interceptor");
2172 return ERR_APPEXECFWK_PARCEL_ERROR;
2173 }
2174
2175 MessageParcel reply;
2176 MessageOption option;
2177 int error = SendTransactCmd(
2178 IFormMgr::Message::FORM_MGR_UNREGISTER_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 return reply.ReadInt32();
2187 }
2188
RegisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)2189 ErrCode FormMgrProxy::RegisterClickEventObserver(
2190 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
2191 {
2192 HILOG_DEBUG("Click callback event start");
2193 MessageParcel data;
2194 if (!WriteInterfaceToken(data)) {
2195 HILOG_ERROR("write interface token failed");
2196 return ERR_APPEXECFWK_PARCEL_ERROR;
2197 }
2198
2199 if (!data.WriteString(bundleName)) {
2200 HILOG_ERROR("write bundleName failed");
2201 return ERR_APPEXECFWK_PARCEL_ERROR;
2202 }
2203
2204 if (!data.WriteString(formEventType)) {
2205 HILOG_ERROR("write formEventType failed");
2206 return ERR_APPEXECFWK_PARCEL_ERROR;
2207 }
2208
2209 if (!data.WriteRemoteObject(observer)) {
2210 HILOG_ERROR("fail write observer");
2211 return ERR_APPEXECFWK_PARCEL_ERROR;
2212 }
2213
2214 MessageParcel reply;
2215 MessageOption option(MessageOption::TF_ASYNC);
2216 int error = SendTransactCmd(
2217 IFormMgr::Message::FORM_MGR_REGISTER_CLICK_EVENT_OBSERVER, data, reply, option);
2218 if (error != ERR_OK) {
2219 HILOG_ERROR("SendRequest:%{public}d failed", error);
2220 return error;
2221 }
2222 return ERR_OK;
2223 }
2224
UnregisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)2225 ErrCode FormMgrProxy::UnregisterClickEventObserver(
2226 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
2227 {
2228 HILOG_DEBUG("Click callback event start");
2229 MessageParcel data;
2230 if (!WriteInterfaceToken(data)) {
2231 HILOG_ERROR("write interface token failed");
2232 return ERR_APPEXECFWK_PARCEL_ERROR;
2233 }
2234
2235 if (!data.WriteString(bundleName)) {
2236 HILOG_ERROR("write bundleName failed");
2237 return ERR_APPEXECFWK_PARCEL_ERROR;
2238 }
2239
2240 if (!data.WriteString(formEventType)) {
2241 HILOG_ERROR("write formEventType failed");
2242 return ERR_APPEXECFWK_PARCEL_ERROR;
2243 }
2244
2245 if (!data.WriteRemoteObject(observer)) {
2246 HILOG_ERROR("fail write observer");
2247 return ERR_APPEXECFWK_PARCEL_ERROR;
2248 }
2249
2250 MessageParcel reply;
2251 MessageOption option(MessageOption::TF_ASYNC);
2252 int error = SendTransactCmd(
2253 IFormMgr::Message::FORM_MGR_UNREGISTER_CLICK_EVENT_OBSERVER, data, reply, option);
2254 if (error != ERR_OK) {
2255 HILOG_ERROR("SendRequest:%{public}d failed", error);
2256 return error;
2257 }
2258 return ERR_OK;
2259 }
2260
SetFormsRecyclable(const std::vector<int64_t> & formIds)2261 int32_t FormMgrProxy::SetFormsRecyclable(const std::vector<int64_t> &formIds)
2262 {
2263 HILOG_DEBUG("start");
2264 MessageParcel data;
2265 if (!WriteInterfaceToken(data)) {
2266 HILOG_ERROR("write interface token failed");
2267 return ERR_APPEXECFWK_PARCEL_ERROR;
2268 }
2269 if (!data.WriteInt64Vector(formIds)) {
2270 HILOG_ERROR("write vector formIds failed");
2271 return ERR_APPEXECFWK_PARCEL_ERROR;
2272 }
2273 MessageParcel reply;
2274 MessageOption option(MessageOption::TF_SYNC);
2275 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_SET_FORMS_RECYCLABLE, data, reply, option);
2276 if (error != ERR_OK) {
2277 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2278 return error;
2279 }
2280 return reply.ReadInt32();
2281 }
2282
RecycleForms(const std::vector<int64_t> & formIds,const Want & want)2283 int32_t FormMgrProxy::RecycleForms(const std::vector<int64_t> &formIds, const Want &want)
2284 {
2285 HILOG_DEBUG("start");
2286 MessageParcel data;
2287 if (!WriteInterfaceToken(data)) {
2288 HILOG_ERROR("write interface token failed");
2289 return ERR_APPEXECFWK_PARCEL_ERROR;
2290 }
2291 if (!data.WriteInt64Vector(formIds)) {
2292 HILOG_ERROR("write vector formIds failed");
2293 return ERR_APPEXECFWK_PARCEL_ERROR;
2294 }
2295 if (!data.WriteParcelable(&want)) {
2296 HILOG_ERROR("write want failed");
2297 return ERR_APPEXECFWK_PARCEL_ERROR;
2298 }
2299 MessageParcel reply;
2300 MessageOption option(MessageOption::TF_SYNC);
2301 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_RECYCLE_FORMS, data, reply, option);
2302 if (error != ERR_OK) {
2303 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2304 return error;
2305 }
2306 return reply.ReadInt32();
2307 }
2308
RecoverForms(const std::vector<int64_t> & formIds,const Want & want)2309 int32_t FormMgrProxy::RecoverForms(const std::vector<int64_t> &formIds, const Want &want)
2310 {
2311 HILOG_DEBUG("start");
2312 MessageParcel data;
2313 if (!WriteInterfaceToken(data)) {
2314 HILOG_ERROR("write interface token failed");
2315 return ERR_APPEXECFWK_PARCEL_ERROR;
2316 }
2317 if (!data.WriteInt64Vector(formIds)) {
2318 HILOG_ERROR("write vector formIds failed");
2319 return ERR_APPEXECFWK_PARCEL_ERROR;
2320 }
2321 if (!data.WriteParcelable(&want)) {
2322 HILOG_ERROR("write want failed");
2323 return ERR_APPEXECFWK_PARCEL_ERROR;
2324 }
2325 MessageParcel reply;
2326 MessageOption option(MessageOption::TF_SYNC);
2327 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_RECOVER_FORMS, data, reply, option);
2328 if (error != ERR_OK) {
2329 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2330 return error;
2331 }
2332 return reply.ReadInt32();
2333 }
2334
UpdateFormLocation(const int64_t & formId,const int32_t & formLocation)2335 ErrCode FormMgrProxy::UpdateFormLocation(const int64_t &formId, const int32_t &formLocation)
2336 {
2337 HILOG_DEBUG("start");
2338 MessageParcel data;
2339 if (!WriteInterfaceToken(data)) {
2340 HILOG_ERROR("write interface token failed");
2341 return ERR_APPEXECFWK_PARCEL_ERROR;
2342 }
2343 if (!data.WriteInt64(formId)) {
2344 HILOG_ERROR("write formId failed");
2345 return ERR_APPEXECFWK_PARCEL_ERROR;
2346 }
2347 if (!data.WriteInt32(formLocation)) {
2348 HILOG_ERROR("fail write formLocation");
2349 return ERR_APPEXECFWK_PARCEL_ERROR;
2350 }
2351 MessageParcel reply;
2352 MessageOption option(MessageOption::TF_SYNC);
2353 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_FORM_LOCATION, data, reply, option);
2354 if (error != ERR_OK) {
2355 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2356 return error;
2357 }
2358 return reply.ReadInt32();
2359 }
2360
RequestPublishFormWithSnapshot(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId)2361 ErrCode FormMgrProxy::RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData,
2362 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
2363 {
2364 MessageParcel data;
2365 MessageParcel reply;
2366
2367 if (!WriteInterfaceToken(data)) {
2368 HILOG_ERROR("write interface token failed");
2369 return ERR_APPEXECFWK_PARCEL_ERROR;
2370 }
2371 if (!data.WriteParcelable(&want)) {
2372 HILOG_ERROR("write want failed");
2373 return ERR_APPEXECFWK_PARCEL_ERROR;
2374 }
2375 if (!data.WriteBool(withFormBindingData)) {
2376 HILOG_ERROR("write withFormBindingData failed");
2377 return ERR_APPEXECFWK_PARCEL_ERROR;
2378 }
2379 if (withFormBindingData) {
2380 if (!data.WriteParcelable(formBindingData.get())) {
2381 HILOG_ERROR("write formBindingData failed");
2382 return ERR_APPEXECFWK_PARCEL_ERROR;
2383 }
2384 }
2385
2386 MessageOption option;
2387 int32_t error = SendTransactCmd(
2388 IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM_WITH_SNAPSHOT,
2389 data,
2390 reply,
2391 option);
2392 if (error != ERR_OK) {
2393 HILOG_ERROR("SendRequest:%{public}d failed", error);
2394 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2395 }
2396 ErrCode errCode = reply.ReadInt32();
2397 if (errCode == ERR_OK) {
2398 formId = reply.ReadInt64();
2399 }
2400 return errCode;
2401 }
2402
BatchRefreshForms(const int32_t formRefreshType)2403 int32_t FormMgrProxy::BatchRefreshForms(const int32_t formRefreshType)
2404 {
2405 MessageParcel data;
2406 if (!WriteInterfaceToken(data)) {
2407 HILOG_ERROR("write interface token failed");
2408 return ERR_APPEXECFWK_PARCEL_ERROR;
2409 }
2410 if (!data.WriteInt32(formRefreshType)) {
2411 HILOG_ERROR("fail write formRefreshType");
2412 return ERR_APPEXECFWK_PARCEL_ERROR;
2413 }
2414 MessageParcel reply;
2415 MessageOption option(MessageOption::TF_SYNC);
2416 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_BATCH_REFRESH_FORMS, data, reply, option);
2417 if (error != ERR_OK) {
2418 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2419 return error;
2420 }
2421 return reply.ReadInt32();
2422 }
2423
EnableForms(const std::string bundleName,const bool enable)2424 int32_t FormMgrProxy::EnableForms(const std::string bundleName, const bool enable)
2425 {
2426 HILOG_DEBUG("EnableForms start.%{public}s", bundleName.c_str());
2427 MessageParcel data;
2428 if (!WriteInterfaceToken(data)) {
2429 HILOG_ERROR("write interface token failed");
2430 return ERR_APPEXECFWK_PARCEL_ERROR;
2431 }
2432
2433 if (!data.WriteString(bundleName)) {
2434 HILOG_ERROR("write bundleName failed");
2435 return ERR_APPEXECFWK_PARCEL_ERROR;
2436 }
2437
2438 if (!data.WriteBool(enable)) {
2439 HILOG_ERROR("fail write enable");
2440 return ERR_APPEXECFWK_PARCEL_ERROR;
2441 }
2442
2443 MessageParcel reply;
2444 MessageOption option(MessageOption::TF_SYNC);
2445 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ENABLE_FORMS, data, reply, option);
2446 if (error != ERR_OK) {
2447 HILOG_ERROR("SendRequest:%{public}d failed", error);
2448 return error;
2449 }
2450 return ERR_OK;
2451 }
2452
IsFormBundleForbidden(const std::string & bundleName)2453 bool FormMgrProxy::IsFormBundleForbidden(const std::string &bundleName)
2454 {
2455 MessageParcel data;
2456 if (!WriteInterfaceToken(data)) {
2457 HILOG_ERROR("write interface token failed");
2458 return true;
2459 }
2460
2461 if (!data.WriteString(bundleName)) {
2462 HILOG_ERROR("write bundleName failed");
2463 return true;
2464 }
2465
2466 MessageParcel reply;
2467 MessageOption option;
2468 int error = SendTransactCmd(
2469 IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_FORBIDDEN, data, reply, option);
2470 if (error != ERR_OK) {
2471 HILOG_ERROR("SendRequest:%{public}d failed", error);
2472 return false;
2473 }
2474 return reply.ReadBool();
2475 }
2476
LockForms(const std::vector<FormLockInfo> & formLockInfos,OHOS::AppExecFwk::LockChangeType type)2477 int32_t FormMgrProxy::LockForms(const std::vector<FormLockInfo> &formLockInfos, OHOS::AppExecFwk::LockChangeType type)
2478 {
2479 HILOG_DEBUG("LockForms start");
2480 MessageParcel data;
2481 if (!WriteInterfaceToken(data)) {
2482 HILOG_ERROR("write interface token failed");
2483 return ERR_APPEXECFWK_PARCEL_ERROR;
2484 }
2485
2486 if (formLockInfos.size() > static_cast<size_t>(MAX_ALLOW_SIZE)) {
2487 HILOG_ERROR("The vector/array size exceeds the security limit!");
2488 return ERR_APPEXECFWK_PARCEL_ERROR;
2489 }
2490
2491 data.WriteInt32(formLockInfos.size());
2492 for (auto it = formLockInfos.begin(); it != formLockInfos.end(); ++it) {
2493 if (!data.WriteParcelable(&(*it))) {
2494 HILOG_ERROR("Write [(*it)] failed!");
2495 return ERR_APPEXECFWK_PARCEL_ERROR;
2496 }
2497 }
2498
2499 data.WriteInt32(static_cast<int32_t>(type));
2500
2501 MessageParcel reply;
2502 MessageOption option(MessageOption::TF_SYNC);
2503 int error = SendTransactCmd(IFormMgr::Message::FORM_MGR_LOCK_FORMS, data, reply, option);
2504 if (error != ERR_OK) {
2505 HILOG_ERROR("SendRequest:%{public}d failed", error);
2506 return error;
2507 }
2508 return reply.ReadInt32();
2509 }
2510
IsFormBundleProtected(const std::string & bundleName,int64_t formId)2511 bool FormMgrProxy::IsFormBundleProtected(const std::string &bundleName, int64_t formId)
2512 {
2513 MessageParcel data;
2514 if (!WriteInterfaceToken(data)) {
2515 HILOG_ERROR("write interface token failed");
2516 return true;
2517 }
2518
2519 if (!data.WriteString(bundleName)) {
2520 HILOG_ERROR("write bundleName failed");
2521 return true;
2522 }
2523
2524 if (!data.WriteInt64(formId)) {
2525 HILOG_ERROR("fail write formId ");
2526 return true;
2527 }
2528
2529 MessageParcel reply;
2530 MessageOption option;
2531 int error = SendTransactCmd(
2532 IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_PEOTECTED, data, reply, option);
2533 if (error != ERR_OK) {
2534 HILOG_ERROR("SendRequest:%{public}d failed", error);
2535 return false;
2536 }
2537 return reply.ReadBool();
2538 }
2539
IsFormBundleExempt(int64_t formId)2540 bool FormMgrProxy::IsFormBundleExempt(int64_t formId)
2541 {
2542 MessageParcel data;
2543 if (!WriteInterfaceToken(data)) {
2544 HILOG_ERROR("write interface token failed");
2545 return true;
2546 }
2547
2548 if (!data.WriteInt64(formId)) {
2549 HILOG_ERROR("fail write formId ");
2550 return true;
2551 }
2552
2553 MessageParcel reply;
2554 MessageOption option;
2555 int error = SendTransactCmd(
2556 IFormMgr::Message::FORM_MGR_IS_FORM_BUNDLE_EXEMPT, data, reply, option);
2557 if (error != ERR_OK) {
2558 HILOG_ERROR("SendRequest:%{public}d failed", error);
2559 return false;
2560 }
2561 return reply.ReadBool();
2562 }
2563
NotifyFormLocked(const int64_t & formId,bool isLocked)2564 int32_t FormMgrProxy::NotifyFormLocked(const int64_t &formId, bool isLocked)
2565 {
2566 MessageParcel data;
2567 if (!WriteInterfaceToken(data)) {
2568 HILOG_ERROR("error to write interface token");
2569 return ERR_APPEXECFWK_PARCEL_ERROR;
2570 }
2571 if (!data.WriteInt64(formId)) {
2572 HILOG_ERROR("error to write formId");
2573 return ERR_APPEXECFWK_PARCEL_ERROR;
2574 }
2575 if (!data.WriteBool(isLocked)) {
2576 HILOG_ERROR("fail write bool isLocked");
2577 return ERR_APPEXECFWK_PARCEL_ERROR;
2578 }
2579
2580 MessageParcel reply;
2581 MessageOption option;
2582 int error = SendTransactCmd(
2583 IFormMgr::Message::FORM_MGR_NOTIFY_FORM_LOCKED,
2584 data,
2585 reply,
2586 option);
2587 if (error != ERR_OK) {
2588 HILOG_ERROR("SendRequest:%{public}d failed", error);
2589 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
2590 }
2591
2592 int32_t result = reply.ReadInt32();
2593 if (result != ERR_OK) {
2594 HILOG_ERROR("read reply result failed");
2595 return result;
2596 }
2597 return result;
2598 }
2599
UpdateFormSize(const int64_t & formId,float width,float height,float borderWidth)2600 ErrCode FormMgrProxy::UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth)
2601 {
2602 HILOG_DEBUG("start");
2603 MessageParcel data;
2604 if (!WriteInterfaceToken(data)) {
2605 HILOG_ERROR("write interface token failed");
2606 return ERR_APPEXECFWK_PARCEL_ERROR;
2607 }
2608 if (!data.WriteInt64(formId)) {
2609 HILOG_ERROR("fail write formId ");
2610 return ERR_APPEXECFWK_PARCEL_ERROR;
2611 }
2612 if (!data.WriteFloat(width)) {
2613 HILOG_ERROR("fail write width");
2614 return ERR_APPEXECFWK_PARCEL_ERROR;
2615 }
2616 if (!data.WriteFloat(height)) {
2617 HILOG_ERROR("fail write height");
2618 return ERR_APPEXECFWK_PARCEL_ERROR;
2619 }
2620 if (!data.WriteFloat(borderWidth)) {
2621 HILOG_ERROR("fail write borderWidth");
2622 return ERR_APPEXECFWK_PARCEL_ERROR;
2623 }
2624 MessageParcel reply;
2625 MessageOption option(MessageOption::TF_SYNC);
2626 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_FORM_SIZE, data, reply, option);
2627 if (error != ERR_OK) {
2628 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2629 return error;
2630 }
2631 return reply.ReadInt32();
2632 }
2633
OpenFormEditAbility(const std::string & abilityName,const int64_t & formId,bool isMainPage)2634 ErrCode FormMgrProxy::OpenFormEditAbility(const std::string &abilityName, const int64_t &formId, bool isMainPage)
2635 {
2636 HILOG_DEBUG("start");
2637 MessageParcel data;
2638 if (!WriteInterfaceToken(data)) {
2639 HILOG_ERROR("write interface token failed");
2640 return ERR_APPEXECFWK_PARCEL_ERROR;
2641 }
2642 if (!data.WriteString(abilityName)) {
2643 HILOG_ERROR("fail write abilityName ");
2644 return ERR_APPEXECFWK_PARCEL_ERROR;
2645 }
2646 if (!data.WriteInt64(formId)) {
2647 HILOG_ERROR("fail write formId ");
2648 return ERR_APPEXECFWK_PARCEL_ERROR;
2649 }
2650 if (!data.WriteBool(isMainPage)) {
2651 HILOG_ERROR("fail write isMainPage ");
2652 return ERR_APPEXECFWK_PARCEL_ERROR;
2653 }
2654
2655 MessageParcel reply;
2656 MessageOption option(MessageOption::TF_SYNC);
2657 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_OPEN_FORM_EDIT_ABILITY, data, reply, option);
2658 if (error != ERR_OK) {
2659 HILOG_ERROR("SendTransactCmd:%{public}d failed", error);
2660 return error;
2661 }
2662 return reply.ReadInt32();
2663 }
2664 } // namespace AppExecFwk
2665 } // namespace OHOS
2666