1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
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 "string_ex.h"
22
23 namespace OHOS {
24 namespace AppExecFwk {
25 namespace {
26 static constexpr int32_t MAX_ALLOW_SIZE = 8 * 1024;
27 }
FormMgrProxy(const sptr<IRemoteObject> & impl)28 FormMgrProxy::FormMgrProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IFormMgr>(impl)
29 {}
30 /**
31 * @brief Add form with want, send want to form manager service.
32 * @param formId The Id of the forms to add.
33 * @param want The want of the form to add.
34 * @param callerToken Caller ability token.
35 * @param formInfo Form info.
36 * @return Returns ERR_OK on success, others on failure.
37 */
AddForm(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken,FormJsInfo & formInfo)38 int FormMgrProxy::AddForm(
39 const int64_t formId,
40 const Want &want,
41 const sptr<IRemoteObject> &callerToken,
42 FormJsInfo &formInfo)
43 {
44 MessageParcel data;
45 if (!WriteInterfaceToken(data)) {
46 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
47 return ERR_APPEXECFWK_PARCEL_ERROR;
48 }
49 if (!data.WriteInt64(formId)) {
50 HILOG_ERROR("%{public}s, failed to write formId", __func__);
51 return ERR_APPEXECFWK_PARCEL_ERROR;
52 }
53 if (!data.WriteParcelable(&want)) {
54 HILOG_ERROR("%{public}s, failed to write want", __func__);
55 return ERR_APPEXECFWK_PARCEL_ERROR;
56 }
57
58 if (!data.WriteRemoteObject(callerToken)) {
59 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
60 return ERR_APPEXECFWK_PARCEL_ERROR;
61 }
62
63 int error = GetParcelableInfo<FormJsInfo>(IFormMgr::Message::FORM_MGR_ADD_FORM, data, formInfo);
64 if (error != ERR_OK) {
65 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
66 }
67
68 return error;
69 }
70
71 /**
72 * @brief Delete forms with formIds, send formIds to form manager service.
73 * @param formId The Id of the forms to delete.
74 * @param callerToken Caller ability token.
75 * @return Returns ERR_OK on success, others on failure.
76 */
DeleteForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)77 int FormMgrProxy::DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
78 {
79 MessageParcel data;
80 if (!WriteInterfaceToken(data)) {
81 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
82 return ERR_APPEXECFWK_PARCEL_ERROR;
83 }
84 if (!data.WriteInt64(formId)) {
85 HILOG_ERROR("%{public}s, failed to write want", __func__);
86 return ERR_APPEXECFWK_PARCEL_ERROR;
87 }
88 if (!data.WriteRemoteObject(callerToken)) {
89 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
90 return ERR_APPEXECFWK_PARCEL_ERROR;
91 }
92 MessageParcel reply;
93 MessageOption option;
94 int error = Remote()->SendRequest(
95 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_DELETE_FORM),
96 data,
97 reply,
98 option);
99 if (error != ERR_OK) {
100 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
101 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
102 }
103 return reply.ReadInt32();
104 }
105
StopRenderingForm(const int64_t formId,const std::string & compId)106 int FormMgrProxy::StopRenderingForm(const int64_t formId, const std::string &compId)
107 {
108 MessageParcel data;
109 if (!WriteInterfaceToken(data)) {
110 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
111 return ERR_APPEXECFWK_PARCEL_ERROR;
112 }
113 if (!data.WriteInt64(formId)) {
114 HILOG_ERROR("%{public}s, failed to write want", __func__);
115 return ERR_APPEXECFWK_PARCEL_ERROR;
116 }
117 if (!data.WriteString(compId)) {
118 HILOG_ERROR("%{public}s, failed to write compId", __func__);
119 return ERR_APPEXECFWK_PARCEL_ERROR;
120 }
121 MessageParcel reply;
122 MessageOption option;
123 int error = Remote()->SendRequest(
124 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_STOP_RENDERING_FORM),
125 data,
126 reply,
127 option);
128 if (error != ERR_OK) {
129 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
130 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
131 }
132 return reply.ReadInt32();
133 }
134
135 /**
136 * @brief Release forms with formIds, send formIds to form manager service.
137 * @param formId The Id of the forms to release.
138 * @param callerToken Caller ability token.
139 * @param delCache Delete Cache or not.
140 * @return Returns ERR_OK on success, others on failure.
141 */
ReleaseForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const bool delCache)142 int FormMgrProxy::ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache)
143 {
144 MessageParcel data;
145 if (!WriteInterfaceToken(data)) {
146 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
147 return ERR_APPEXECFWK_PARCEL_ERROR;
148 }
149 if (!data.WriteInt64(formId)) {
150 HILOG_ERROR("%{public}s, failed to write want", __func__);
151 return ERR_APPEXECFWK_PARCEL_ERROR;
152 }
153 if (!data.WriteRemoteObject(callerToken)) {
154 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
155 return ERR_APPEXECFWK_PARCEL_ERROR;
156 }
157 if (!data.WriteBool(delCache)) {
158 HILOG_ERROR("%{public}s, failed to write delCache", __func__);
159 return ERR_APPEXECFWK_PARCEL_ERROR;
160 }
161
162 MessageParcel reply;
163 MessageOption option;
164 int error = Remote()->SendRequest(
165 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RELEASE_FORM),
166 data,
167 reply,
168 option);
169 if (error != ERR_OK) {
170 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
171 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
172 }
173 return reply.ReadInt32();
174 }
175
176 /**
177 * @brief Update form with formId, send formId to form manager service.
178 * @param formId The Id of the form to update.
179 * @param bundleName Provider ability bundleName.
180 * @param FormProviderData Form binding data.
181 * @return Returns ERR_OK on success, others on failure.
182 */
UpdateForm(const int64_t formId,const FormProviderData & FormProviderData)183 int FormMgrProxy::UpdateForm(const int64_t formId, const FormProviderData &FormProviderData)
184 {
185 MessageParcel data;
186 if (!WriteInterfaceToken(data)) {
187 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
188 return ERR_APPEXECFWK_PARCEL_ERROR;
189 }
190 if (!data.WriteInt64(formId)) {
191 HILOG_ERROR("%{public}s, failed to write formId", __func__);
192 return ERR_APPEXECFWK_PARCEL_ERROR;
193 }
194 if (!data.WriteParcelable(&FormProviderData)) {
195 HILOG_ERROR("%{public}s, failed to write formBindingData", __func__);
196 return ERR_APPEXECFWK_PARCEL_ERROR;
197 }
198 MessageParcel reply;
199 MessageOption option;
200 int error = Remote()->SendRequest(
201 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UPDATE_FORM),
202 data,
203 reply,
204 option);
205 if (error != ERR_OK) {
206 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
207 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
208 }
209 return reply.ReadInt32();
210 }
211
212 /**
213 * @brief Set next refresh time.
214 * @param formId The Id of the form to update.
215 * @param bundleName Provider ability bundleName.
216 * @param nextTime Next refresh time.
217 * @return Returns ERR_OK on success, others on failure.
218 */
SetNextRefreshTime(const int64_t formId,const int64_t nextTime)219 int FormMgrProxy::SetNextRefreshTime(const int64_t formId, const int64_t nextTime)
220 {
221 MessageParcel data;
222 MessageParcel reply;
223
224 if (!WriteInterfaceToken(data)) {
225 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
226 return ERR_APPEXECFWK_PARCEL_ERROR;
227 }
228 if (!data.WriteInt64(formId)) {
229 HILOG_ERROR("%{public}s, failed to write formId", __func__);
230 return ERR_APPEXECFWK_PARCEL_ERROR;
231 }
232 if (!data.WriteInt64(nextTime)) {
233 HILOG_ERROR("%{public}s, failed to write nextTime", __func__);
234 return ERR_APPEXECFWK_PARCEL_ERROR;
235 }
236 MessageOption option;
237 int error = Remote()->SendRequest(
238 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_SET_NEXT_REFRESH_TIME),
239 data,
240 reply,
241 option);
242 if (error != ERR_OK) {
243 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
244 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
245 }
246 return reply.ReadInt32();
247 }
248
ReleaseRenderer(int64_t formId,const std::string & compId)249 int FormMgrProxy::ReleaseRenderer(int64_t formId, const std::string &compId)
250 {
251 MessageParcel data;
252 MessageParcel reply;
253
254 if (!WriteInterfaceToken(data)) {
255 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
256 return ERR_APPEXECFWK_PARCEL_ERROR;
257 }
258 if (!data.WriteInt64(formId)) {
259 HILOG_ERROR("%{public}s, failed to write formId", __func__);
260 return ERR_APPEXECFWK_PARCEL_ERROR;
261 }
262 if (!data.WriteString(compId)) {
263 HILOG_ERROR("%{public}s, failed to write compId", __func__);
264 return ERR_APPEXECFWK_PARCEL_ERROR;
265 }
266 MessageOption option;
267 int error = Remote()->SendRequest(
268 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RELEASE_RENDERER),
269 data,
270 reply,
271 option);
272 if (error != ERR_OK) {
273 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
274 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
275 }
276 return reply.ReadInt32();
277 }
278
RequestPublishForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId)279 ErrCode FormMgrProxy::RequestPublishForm(Want &want, bool withFormBindingData,
280 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
281 {
282 MessageParcel data;
283 MessageParcel reply;
284
285 if (!WriteInterfaceToken(data)) {
286 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
287 return ERR_APPEXECFWK_PARCEL_ERROR;
288 }
289 if (!data.WriteParcelable(&want)) {
290 HILOG_ERROR("%{public}s, failed to write want", __func__);
291 return ERR_APPEXECFWK_PARCEL_ERROR;
292 }
293 if (!data.WriteBool(withFormBindingData)) {
294 HILOG_ERROR("%{public}s, failed to write withFormBindingData", __func__);
295 return ERR_APPEXECFWK_PARCEL_ERROR;
296 }
297 if (withFormBindingData) {
298 if (!data.WriteParcelable(formBindingData.get())) {
299 HILOG_ERROR("%{public}s, failed to write formBindingData", __func__);
300 return ERR_APPEXECFWK_PARCEL_ERROR;
301 }
302 }
303
304 MessageOption option;
305 int32_t error = Remote()->SendRequest(
306 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM),
307 data,
308 reply,
309 option);
310 if (error != ERR_OK) {
311 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
312 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
313 }
314 ErrCode errCode = reply.ReadInt32();
315 if (errCode == ERR_OK) {
316 formId = reply.ReadInt64();
317 }
318 return errCode;
319 }
320
LifecycleUpdate(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,bool updateType)321 int FormMgrProxy::LifecycleUpdate(
322 const std::vector<int64_t> &formIds,
323 const sptr<IRemoteObject> &callerToken,
324 bool updateType)
325 {
326 MessageParcel data;
327 MessageParcel reply;
328
329 if (!WriteInterfaceToken(data)) {
330 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
331 return ERR_APPEXECFWK_PARCEL_ERROR;
332 }
333 if (!data.WriteInt64Vector(formIds)) {
334 HILOG_ERROR("%{public}s, failed to write formId", __func__);
335 return ERR_APPEXECFWK_PARCEL_ERROR;
336 }
337 if (!data.WriteRemoteObject(callerToken)) {
338 HILOG_ERROR("%{public}s, failed to write bundleName", __func__);
339 return ERR_APPEXECFWK_PARCEL_ERROR;
340 }
341 if (!data.WriteBool(updateType)) {
342 HILOG_ERROR("%{public}s, failed to write nextTime", __func__);
343 return ERR_APPEXECFWK_PARCEL_ERROR;
344 }
345 MessageOption option;
346 int error = Remote()->SendRequest(
347 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_LIFECYCLE_UPDATE),
348 data,
349 reply,
350 option);
351 if (error != ERR_OK) {
352 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
353 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
354 }
355
356 return reply.ReadInt32();
357 }
358 /**
359 * @brief Request form with formId and want, send formId and want to form manager service.
360 * @param formId The Id of the form to update.
361 * @param callerToken Caller ability token.
362 * @param want The want of the form to add.
363 * @return Returns ERR_OK on success, others on failure.
364 */
RequestForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const Want & want)365 int FormMgrProxy::RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want)
366 {
367 HILOG_INFO("%{public}s called.", __func__);
368
369 MessageParcel data;
370 if (!WriteInterfaceToken(data)) {
371 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
372 return ERR_APPEXECFWK_PARCEL_ERROR;
373 }
374 if (!data.WriteInt64(formId)) {
375 HILOG_ERROR("%{public}s, failed to write formId", __func__);
376 return ERR_APPEXECFWK_PARCEL_ERROR;
377 }
378 if (!data.WriteRemoteObject(callerToken)) {
379 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
380 return ERR_APPEXECFWK_PARCEL_ERROR;
381 }
382 if (!data.WriteParcelable(&want)) {
383 HILOG_ERROR("%{public}s, failed to write want", __func__);
384 return ERR_APPEXECFWK_PARCEL_ERROR;
385 }
386
387 MessageParcel reply;
388 MessageOption option;
389 int error = Remote()->SendRequest(
390 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_FORM),
391 data,
392 reply,
393 option);
394 if (error != ERR_OK) {
395 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
396 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
397 }
398 return reply.ReadInt32();
399 }
400
401 /**
402 * @brief Form visible/invisible notify, send formIds to form manager service.
403 * @param formIds The Id list of the forms to notify.
404 * @param callerToken Caller ability token.
405 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
406 * @return Returns ERR_OK on success, others on failure.
407 */
NotifyWhetherVisibleForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,const int32_t formVisibleType)408 int FormMgrProxy::NotifyWhetherVisibleForms(
409 const std::vector<int64_t> &formIds,
410 const sptr<IRemoteObject> &callerToken,
411 const int32_t formVisibleType)
412 {
413 MessageParcel data;
414 if (!WriteInterfaceToken(data)) {
415 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
416 return ERR_APPEXECFWK_PARCEL_ERROR;
417 }
418
419 if (!data.WriteInt64Vector(formIds)) {
420 HILOG_ERROR("%{public}s, failed to write formIds", __func__);
421 return ERR_APPEXECFWK_PARCEL_ERROR;
422 }
423
424 if (!data.WriteRemoteObject(callerToken)) {
425 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
426 return ERR_APPEXECFWK_PARCEL_ERROR;
427 }
428
429 if (!data.WriteInt32(formVisibleType)) {
430 HILOG_ERROR("%{public}s, failed to write formVisibleType", __func__);
431 return ERR_APPEXECFWK_PARCEL_ERROR;
432 }
433
434 MessageParcel reply;
435 MessageOption option;
436 int error = Remote()->SendRequest(
437 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORM_WHETHER_VISIBLE),
438 data,
439 reply,
440 option);
441 if (error != ERR_OK) {
442 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
443 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
444 }
445 return reply.ReadInt32();
446 }
447
448 /**
449 * @brief temp form to normal form.
450 * @param formId The Id of the form.
451 * @param callerToken Caller ability token.
452 * @return Returns ERR_OK on success, others on failure.
453 */
CastTempForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)454 int FormMgrProxy::CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
455 {
456 MessageParcel data;
457 if (!WriteInterfaceToken(data)) {
458 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
459 return ERR_APPEXECFWK_PARCEL_ERROR;
460 }
461 if (!data.WriteInt64(formId)) {
462 HILOG_ERROR("%{public}s, failed to write want", __func__);
463 return ERR_APPEXECFWK_PARCEL_ERROR;
464 }
465 if (!data.WriteRemoteObject(callerToken)) {
466 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
467 return ERR_APPEXECFWK_PARCEL_ERROR;
468 }
469
470 MessageParcel reply;
471 MessageOption option;
472 int error = Remote()->SendRequest(
473 static_cast<uint32_t>(
474 IFormMgr::Message::FORM_MGR_CAST_TEMP_FORM),
475 data,
476 reply,
477 option);
478 if (error != ERR_OK) {
479 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
480 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
481 }
482 return reply.ReadInt32();
483 }
484 /**
485 * @brief Dump all of form storage infos.
486 * @param formInfos All of form storage infos.
487 * @return Returns ERR_OK on success, others on failure.
488 */
DumpStorageFormInfos(std::string & formInfos)489 int FormMgrProxy::DumpStorageFormInfos(std::string &formInfos)
490 {
491 MessageParcel data;
492 if (!WriteInterfaceToken(data)) {
493 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
494 return ERR_APPEXECFWK_PARCEL_ERROR;
495 }
496
497 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_STORAGE_FORM_INFOS, data, formInfos);
498 if (error != ERR_OK) {
499 HILOG_ERROR("%{public}s, failed to GetStringInfo: %{public}d", __func__, error);
500 }
501
502 return error;
503 }
504 /**
505 * @brief Dump form info by a bundle name.
506 * @param bundleName The bundle name of form provider.
507 * @param formInfos Form infos.
508 * @return Returns ERR_OK on success, others on failure.
509 */
DumpFormInfoByBundleName(const std::string & bundleName,std::string & formInfos)510 int FormMgrProxy::DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos)
511 {
512 MessageParcel data;
513 if (!WriteInterfaceToken(data)) {
514 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
515 return ERR_APPEXECFWK_PARCEL_ERROR;
516 }
517
518 if (!data.WriteString(bundleName)) {
519 HILOG_ERROR("%{public}s, failed to write bundleName", __func__);
520 return ERR_APPEXECFWK_PARCEL_ERROR;
521 }
522
523 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_NAME, data, formInfos);
524 if (error != ERR_OK) {
525 HILOG_ERROR("%{public}s, failed to GetStringInfo: %{public}d", __func__, error);
526 }
527
528 return error;
529 }
530 /**
531 * @brief Dump form info by a bundle name.
532 * @param formId The id of the form.
533 * @param formInfo Form info.
534 * @return Returns ERR_OK on success, others on failure.
535 */
DumpFormInfoByFormId(const std::int64_t formId,std::string & formInfo)536 int FormMgrProxy::DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo)
537 {
538 MessageParcel data;
539 if (!WriteInterfaceToken(data)) {
540 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
541 return ERR_APPEXECFWK_PARCEL_ERROR;
542 }
543 if (!data.WriteInt64(formId)) {
544 HILOG_ERROR("%{public}s, failed to write formId", __func__);
545 return ERR_APPEXECFWK_PARCEL_ERROR;
546 }
547
548 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID, data, formInfo);
549 if (error != ERR_OK) {
550 HILOG_ERROR("%{public}s, failed to GetStringInfo: %{public}d", __func__, error);
551 }
552
553 return error;
554 }
555 /**
556 * @brief Dump timer info by form id.
557 * @param formId The id of the form.
558 * @param formInfo Form timer info.
559 * @return Returns ERR_OK on success, others on failure.
560 */
DumpFormTimerByFormId(const std::int64_t formId,std::string & isTimingService)561 int FormMgrProxy::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService)
562 {
563 MessageParcel data;
564 if (!WriteInterfaceToken(data)) {
565 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
566 return ERR_APPEXECFWK_PARCEL_ERROR;
567 }
568 if (!data.WriteInt64(formId)) {
569 HILOG_ERROR("%{public}s, failed to write formId", __func__);
570 return ERR_APPEXECFWK_PARCEL_ERROR;
571 }
572
573 int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID, data, isTimingService);
574 if (error != ERR_OK) {
575 HILOG_ERROR("%{public}s, failed to GetStringInfo: %{public}d", __func__, error);
576 }
577
578 return error;
579 }
580 /**
581 * @brief Process js message event.
582 * @param formId Indicates the unique id of form.
583 * @param want information passed to supplier.
584 * @param callerToken Caller ability token.
585 * @return Returns true if execute success, false otherwise.
586 */
MessageEvent(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)587 int FormMgrProxy::MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken)
588 {
589 MessageParcel data;
590 if (!WriteInterfaceToken(data)) {
591 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
592 return ERR_APPEXECFWK_PARCEL_ERROR;
593 }
594 if (!data.WriteInt64(formId)) {
595 HILOG_ERROR("%{public}s, failed to write formId", __func__);
596 return ERR_APPEXECFWK_PARCEL_ERROR;
597 }
598 if (!data.WriteParcelable(&want)) {
599 HILOG_ERROR("%{public}s, failed to write want", __func__);
600 return ERR_APPEXECFWK_PARCEL_ERROR;
601 }
602
603 if (!data.WriteRemoteObject(callerToken)) {
604 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
605 return ERR_APPEXECFWK_PARCEL_ERROR;
606 }
607
608 MessageParcel reply;
609 MessageOption option;
610 int error = Remote()->SendRequest(static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_MESSAGE_EVENT),
611 data, reply, option);
612 if (error != ERR_OK) {
613 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
614 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
615 }
616 return reply.ReadInt32();
617 }
618
619 /**
620 * @brief Process Background event.
621 * @param formId Indicates the unique id of form.
622 * @param want the want of the ability to start.
623 * @param callerToken Caller ability token.
624 * @return Returns true if execute success, false otherwise.
625 */
BackgroundEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)626 int FormMgrProxy::BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
627 {
628 MessageParcel data;
629 if (!WriteInterfaceToken(data)) {
630 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
631 return ERR_APPEXECFWK_PARCEL_ERROR;
632 }
633 if (!data.WriteInt64(formId)) {
634 HILOG_ERROR("%{public}s, failed to write formId", __func__);
635 return ERR_APPEXECFWK_PARCEL_ERROR;
636 }
637 if (!data.WriteParcelable(&want)) {
638 HILOG_ERROR("%{public}s, failed to write want", __func__);
639 return ERR_APPEXECFWK_PARCEL_ERROR;
640 }
641
642 if (!data.WriteRemoteObject(callerToken)) {
643 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
644 return ERR_APPEXECFWK_PARCEL_ERROR;
645 }
646
647 MessageParcel reply;
648 MessageOption option;
649 int error = Remote()->SendRequest(static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_BACKGROUND_EVENT),
650 data, reply, option);
651 if (error != ERR_OK) {
652 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
653 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
654 }
655 return reply.ReadInt32();
656 }
657
658 /**
659 * @brief Process js router event.
660 * @param formId Indicates the unique id of form.
661 * @param want the want of the ability to start.
662 * @param callerToken Caller ability token.
663 * @return Returns true if execute success, false otherwise.
664 */
RouterEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)665 int FormMgrProxy::RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
666 {
667 MessageParcel data;
668 if (!WriteInterfaceToken(data)) {
669 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
670 return ERR_APPEXECFWK_PARCEL_ERROR;
671 }
672 if (!data.WriteInt64(formId)) {
673 HILOG_ERROR("%{public}s, failed to write formId", __func__);
674 return ERR_APPEXECFWK_PARCEL_ERROR;
675 }
676 if (!data.WriteParcelable(&want)) {
677 HILOG_ERROR("%{public}s, failed to write want", __func__);
678 return ERR_APPEXECFWK_PARCEL_ERROR;
679 }
680
681 if (!data.WriteRemoteObject(callerToken)) {
682 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
683 return ERR_APPEXECFWK_PARCEL_ERROR;
684 }
685
686 MessageParcel reply;
687 MessageOption option;
688 int error = Remote()->SendRequest(static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ROUTER_EVENT),
689 data, reply, option);
690 if (error != ERR_OK) {
691 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
692 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
693 }
694 return reply.ReadInt32();
695 }
696
697 template<typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)698 int FormMgrProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
699 {
700 int32_t infoSize = reply.ReadInt32();
701 if (infoSize < 0 || infoSize > MAX_ALLOW_SIZE) {
702 HILOG_ERROR("%{public}s invalid size: %{public}d", __func__, infoSize);
703 return ERR_APPEXECFWK_PARCEL_ERROR;
704 }
705 for (int32_t i = 0; i < infoSize; i++) {
706 std::unique_ptr<T> info(reply.ReadParcelable<T>());
707 if (!info) {
708 HILOG_ERROR("%{public}s, failed to Read Parcelable infos", __func__);
709 return ERR_APPEXECFWK_PARCEL_ERROR;
710 }
711 parcelableInfos.emplace_back(*info);
712 }
713 HILOG_INFO("get parcelable infos success");
714 return ERR_OK;
715 }
WriteInterfaceToken(MessageParcel & data)716 bool FormMgrProxy::WriteInterfaceToken(MessageParcel &data)
717 {
718 if (!data.WriteInterfaceToken(IFormMgr::GetDescriptor())) {
719 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
720 return false;
721 }
722 return true;
723 }
GetStringInfo(IFormMgr::Message code,MessageParcel & data,std::string & stringInfo)724 int FormMgrProxy::GetStringInfo(IFormMgr::Message code, MessageParcel &data, std::string &stringInfo)
725 {
726 int error;
727 MessageParcel reply;
728 error = SendTransactCmd(code, data, reply);
729 if (error != ERR_OK) {
730 return error;
731 }
732
733 error = reply.ReadInt32();
734 if (error != ERR_OK) {
735 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
736 return error;
737 }
738 std::vector<std::string> stringInfoList;
739 if (!reply.ReadStringVector(&stringInfoList)) {
740 HILOG_ERROR("%{public}s, failed to read string vector from reply", __func__);
741 return false;
742 }
743 if (stringInfoList.empty()) {
744 HILOG_INFO("%{public}s, No string info", __func__);
745 return ERR_APPEXECFWK_FORM_COMMON_CODE;
746 }
747 for (const auto &info : stringInfoList) {
748 stringInfo += info;
749 }
750 HILOG_DEBUG("get string info success");
751 return ERR_OK;
752 }
GetFormsInfo(IFormMgr::Message code,MessageParcel & data,std::vector<FormInfo> & formInfos)753 int FormMgrProxy::GetFormsInfo(IFormMgr::Message code, MessageParcel &data, std::vector<FormInfo> &formInfos)
754 {
755 int error;
756 MessageParcel reply;
757 error = SendTransactCmd(code, data, reply);
758 if (error != ERR_OK) {
759 return error;
760 }
761
762 error = reply.ReadInt32();
763 if (error != ERR_OK) {
764 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
765 return error;
766 }
767
768 return GetParcelableInfos<FormInfo>(reply, formInfos);
769 }
770
GetRunningFormInfos(IFormMgr::Message code,MessageParcel & data,std::vector<RunningFormInfo> & runningFormInfos)771 ErrCode FormMgrProxy::GetRunningFormInfos(IFormMgr::Message code, MessageParcel &data,
772 std::vector<RunningFormInfo> &runningFormInfos)
773 {
774 ErrCode error;
775 MessageParcel reply;
776 error = SendTransactCmd(code, data, reply);
777 if (error != ERR_OK) {
778 return error;
779 }
780
781 error = reply.ReadInt32();
782 if (error != ERR_OK) {
783 HILOG_ERROR("failed to read reply result");
784 return error;
785 }
786 return GetParcelableInfos<RunningFormInfo>(reply, runningFormInfos);
787 }
788
789 template<typename T>
GetParcelableInfo(IFormMgr::Message code,MessageParcel & data,T & parcelableInfo)790 int FormMgrProxy::GetParcelableInfo(IFormMgr::Message code, MessageParcel &data, T &parcelableInfo)
791 {
792 int error;
793 MessageParcel reply;
794 error = SendTransactCmd(code, data, reply);
795 if (error != ERR_OK) {
796 return error;
797 }
798
799 error = reply.ReadInt32();
800 if (error != ERR_OK) {
801 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
802 return error;
803 }
804
805 std::unique_ptr<T> info(reply.ReadParcelable<T>());
806 if (!info) {
807 HILOG_ERROR("%{public}s, failed to readParcelableInfo", __func__);
808 return ERR_APPEXECFWK_PARCEL_ERROR;
809 }
810 parcelableInfo = *info;
811 HILOG_DEBUG("get parcelable info success");
812 return ERR_OK;
813 }
SendTransactCmd(IFormMgr::Message code,MessageParcel & data,MessageParcel & reply)814 int FormMgrProxy::SendTransactCmd(IFormMgr::Message code, MessageParcel &data, MessageParcel &reply)
815 {
816 MessageOption option(MessageOption::TF_SYNC);
817
818 sptr<IRemoteObject> remote = Remote();
819 if (!remote) {
820 HILOG_ERROR("%{public}s, failed to get remote object, cmd: %{public}d", __func__, code);
821 return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED;
822 }
823 int32_t result = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
824 if (result != ERR_OK) {
825 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d, cmd: %{public}d", __func__, result, code);
826 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
827 }
828 return ERR_OK;
829 }
830
831 /**
832 * @brief Delete the invalid forms.
833 * @param formIds Indicates the ID of the valid forms.
834 * @param callerToken Caller ability token.
835 * @param numFormsDeleted Returns the number of the deleted forms.
836 * @return Returns ERR_OK on success, others on failure.
837 */
DeleteInvalidForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,int32_t & numFormsDeleted)838 int FormMgrProxy::DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
839 int32_t &numFormsDeleted)
840 {
841 MessageParcel data;
842 if (!WriteInterfaceToken(data)) {
843 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
844 return ERR_APPEXECFWK_PARCEL_ERROR;
845 }
846 if (!data.WriteInt64Vector(formIds)) {
847 HILOG_ERROR("%{public}s, failed to write vector formIds", __func__);
848 return ERR_APPEXECFWK_PARCEL_ERROR;
849 }
850 if (!data.WriteRemoteObject(callerToken)) {
851 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
852 return ERR_APPEXECFWK_PARCEL_ERROR;
853 }
854
855 MessageParcel reply;
856 MessageOption option;
857 int error = Remote()->SendRequest(
858 static_cast<uint32_t>(
859 IFormMgr::Message::FORM_MGR_DELETE_INVALID_FORMS),
860 data,
861 reply,
862 option);
863 if (error != ERR_OK) {
864 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
865 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
866 }
867
868 int32_t result = reply.ReadInt32();
869 if (result != ERR_OK) {
870 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
871 return result;
872 }
873 numFormsDeleted = reply.ReadInt32();
874 return result;
875 }
876
877 /**
878 * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
879 * @param want Indicates a set of parameters to be transparently passed to the form provider.
880 * @param callerToken Caller ability token.
881 * @param stateInfo Returns the form's state info of the specify.
882 * @return Returns ERR_OK on success, others on failure.
883 */
AcquireFormState(const Want & want,const sptr<IRemoteObject> & callerToken,FormStateInfo & stateInfo)884 int FormMgrProxy::AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo)
885 {
886 MessageParcel data;
887 if (!WriteInterfaceToken(data)) {
888 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
889 return ERR_APPEXECFWK_PARCEL_ERROR;
890 }
891 if (!data.WriteParcelable(&want)) {
892 HILOG_ERROR("%{public}s, failed to write want", __func__);
893 return ERR_APPEXECFWK_PARCEL_ERROR;
894 }
895 if (!data.WriteRemoteObject(callerToken)) {
896 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
897 return ERR_APPEXECFWK_PARCEL_ERROR;
898 }
899
900 MessageParcel reply;
901 MessageOption option;
902 int error = Remote()->SendRequest(
903 static_cast<uint32_t>(
904 IFormMgr::Message::FORM_MGR_ACQUIRE_FORM_STATE),
905 data,
906 reply,
907 option);
908 if (error != ERR_OK) {
909 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
910 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
911 }
912
913 int32_t result = reply.ReadInt32();
914 if (result != ERR_OK) {
915 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
916 return result;
917 }
918 stateInfo.state = (FormState)reply.ReadInt32();
919 stateInfo.want = want;
920 return result;
921 }
922
923 /**
924 * @brief Notify the form is visible or not.
925 * @param formIds Indicates the ID of the forms.
926 * @param isVisible Visible or not.
927 * @param callerToken Host client.
928 * @return Returns ERR_OK on success, others on failure.
929 */
NotifyFormsVisible(const std::vector<int64_t> & formIds,bool isVisible,const sptr<IRemoteObject> & callerToken)930 int FormMgrProxy::NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
931 const sptr<IRemoteObject> &callerToken)
932 {
933 MessageParcel data;
934 if (!WriteInterfaceToken(data)) {
935 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
936 return ERR_APPEXECFWK_PARCEL_ERROR;
937 }
938 if (!data.WriteInt64Vector(formIds)) {
939 HILOG_ERROR("%{public}s, failed to write vector formIds", __func__);
940 return ERR_APPEXECFWK_PARCEL_ERROR;
941 }
942 if (!data.WriteBool(isVisible)) {
943 HILOG_ERROR("%{public}s, failed to write bool isVisible", __func__);
944 return ERR_APPEXECFWK_PARCEL_ERROR;
945 }
946 if (!data.WriteRemoteObject(callerToken)) {
947 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
948 return ERR_APPEXECFWK_PARCEL_ERROR;
949 }
950
951 MessageParcel reply;
952 MessageOption option;
953 int error = Remote()->SendRequest(
954 static_cast<uint32_t>(
955 IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_VISIBLE),
956 data,
957 reply,
958 option);
959 if (error != ERR_OK) {
960 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
961 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
962 }
963
964 int32_t result = reply.ReadInt32();
965 if (result != ERR_OK) {
966 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
967 return result;
968 }
969 return result;
970 }
971
NotifyFormsPrivacyProtected(const std::vector<int64_t> & formIds,bool isProtected,const sptr<IRemoteObject> & callerToken)972 int FormMgrProxy::NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
973 const sptr<IRemoteObject> &callerToken)
974 {
975 MessageParcel data;
976 if (!WriteInterfaceToken(data)) {
977 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
978 return ERR_APPEXECFWK_PARCEL_ERROR;
979 }
980 if (!data.WriteInt64Vector(formIds)) {
981 HILOG_ERROR("%{public}s, failed to write vector formIds", __func__);
982 return ERR_APPEXECFWK_PARCEL_ERROR;
983 }
984 if (!data.WriteBool(isProtected)) {
985 HILOG_ERROR("%{public}s, failed to write bool isProtected", __func__);
986 return ERR_APPEXECFWK_PARCEL_ERROR;
987 }
988 if (!data.WriteRemoteObject(callerToken)) {
989 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
990 return ERR_APPEXECFWK_PARCEL_ERROR;
991 }
992
993 MessageParcel reply;
994 MessageOption option;
995 int error = Remote()->SendRequest(
996 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_PRIVACY_PROTECTED),
997 data,
998 reply,
999 option);
1000 if (error != ERR_OK) {
1001 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
1002 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1003 }
1004
1005 int32_t result = reply.ReadInt32();
1006 if (result != ERR_OK) {
1007 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
1008 return result;
1009 }
1010 return result;
1011 }
1012
1013 /**
1014 * @brief Notify the form is enable to be updated or not.
1015 * @param formIds Indicates the ID of the forms.
1016 * @param isEnableUpdate enable update or not.
1017 * @param callerToken Host client.
1018 * @return Returns ERR_OK on success, others on failure.
1019 */
NotifyFormsEnableUpdate(const std::vector<int64_t> & formIds,bool isEnableUpdate,const sptr<IRemoteObject> & callerToken)1020 int FormMgrProxy::NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
1021 const sptr<IRemoteObject> &callerToken)
1022 {
1023 MessageParcel data;
1024 if (!WriteInterfaceToken(data)) {
1025 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1026 return ERR_APPEXECFWK_PARCEL_ERROR;
1027 }
1028 if (!data.WriteInt64Vector(formIds)) {
1029 HILOG_ERROR("%{public}s, failed to write vector formIds", __func__);
1030 return ERR_APPEXECFWK_PARCEL_ERROR;
1031 }
1032 if (!data.WriteBool(isEnableUpdate)) {
1033 HILOG_ERROR("%{public}s, failed to write bool isEnableUpdate", __func__);
1034 return ERR_APPEXECFWK_PARCEL_ERROR;
1035 }
1036 if (!data.WriteRemoteObject(callerToken)) {
1037 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
1038 return ERR_APPEXECFWK_PARCEL_ERROR;
1039 }
1040
1041 MessageParcel reply;
1042 MessageOption option;
1043 int error = Remote()->SendRequest(
1044 static_cast<uint32_t>(
1045 IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_ENABLE_UPDATE),
1046 data,
1047 reply,
1048 option);
1049 if (error != ERR_OK) {
1050 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
1051 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1052 }
1053
1054 int32_t result = reply.ReadInt32();
1055 if (result != ERR_OK) {
1056 HILOG_ERROR("%{public}s, failed to read reply result", __func__);
1057 return result;
1058 }
1059 return result;
1060 }
1061
1062 /**
1063 * @brief Get All FormsInfo.
1064 * @param formInfos Return the forms' information of all forms provided.
1065 * @return Returns ERR_OK on success, others on failure.
1066 */
GetAllFormsInfo(std::vector<FormInfo> & formInfos)1067 int FormMgrProxy::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
1068 {
1069 MessageParcel data;
1070 if (!WriteInterfaceToken(data)) {
1071 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1072 return ERR_APPEXECFWK_PARCEL_ERROR;
1073 }
1074
1075 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_ALL_FORMS_INFO, data, formInfos);
1076 if (error != ERR_OK) {
1077 HILOG_ERROR("%{public}s, failed to GetAllFormsInfo: %{public}d", __func__, error);
1078 }
1079
1080 return error;
1081 }
1082
1083 /**
1084 * @brief Get forms info by bundle name .
1085 * @param bundleName Application name.
1086 * @param formInfos Return the forms' information of the specify application name.
1087 * @return Returns ERR_OK on success, others on failure.
1088 */
GetFormsInfoByApp(std::string & bundleName,std::vector<FormInfo> & formInfos)1089 int FormMgrProxy::GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos)
1090 {
1091 MessageParcel data;
1092 if (!WriteInterfaceToken(data)) {
1093 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1094 return ERR_APPEXECFWK_PARCEL_ERROR;
1095 }
1096
1097 if (!data.WriteString(bundleName)) {
1098 HILOG_ERROR("%{public}s, failed to write bundleName", __func__);
1099 return ERR_APPEXECFWK_PARCEL_ERROR;
1100 }
1101
1102 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_APP, data, formInfos);
1103 if (error != ERR_OK) {
1104 HILOG_ERROR("%{public}s, failed to GetAllFormsInfo: %{public}d", __func__, error);
1105 }
1106
1107 return error;
1108 }
1109
1110 /**
1111 * @brief Get forms info by bundle name and module name.
1112 * @param bundleName bundle name.
1113 * @param moduleName Module name of hap.
1114 * @param formInfos Return the forms' information of the specify bundle name and module name.
1115 * @return Returns ERR_OK on success, others on failure.
1116 */
GetFormsInfoByModule(std::string & bundleName,std::string & moduleName,std::vector<FormInfo> & formInfos)1117 int FormMgrProxy::GetFormsInfoByModule(std::string &bundleName, std::string &moduleName,
1118 std::vector<FormInfo> &formInfos)
1119 {
1120 MessageParcel data;
1121 if (!WriteInterfaceToken(data)) {
1122 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1123 return ERR_APPEXECFWK_PARCEL_ERROR;
1124 }
1125
1126 if (!data.WriteString(bundleName)) {
1127 HILOG_ERROR("%{public}s, failed to write bundleName", __func__);
1128 return ERR_APPEXECFWK_PARCEL_ERROR;
1129 }
1130
1131 if (!data.WriteString(moduleName)) {
1132 HILOG_ERROR("%{public}s, failed to write moduleName", __func__);
1133 return ERR_APPEXECFWK_PARCEL_ERROR;
1134 }
1135
1136 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_MODULE, data, formInfos);
1137 if (error != ERR_OK) {
1138 HILOG_ERROR("%{public}s, failed to GetAllFormsInfo: %{public}d", __func__, error);
1139 }
1140
1141 return error;
1142 }
1143
GetRunningFormInfos(std::vector<RunningFormInfo> & runningFormInfos)1144 ErrCode FormMgrProxy::GetRunningFormInfos(std::vector<RunningFormInfo> &runningFormInfos)
1145 {
1146 MessageParcel data;
1147 if (!WriteInterfaceToken(data)) {
1148 HILOG_ERROR("failed to write interface token");
1149 return ERR_APPEXECFWK_PARCEL_ERROR;
1150 }
1151
1152 ErrCode error = GetRunningFormInfos(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS, data, runningFormInfos);
1153 if (error != ERR_OK) {
1154 HILOG_ERROR("failed to GetRunningFormInfos: %{public}d", error);
1155 }
1156 return error;
1157 }
1158
GetRunningFormInfosByBundleName(const std::string & bundleName,std::vector<RunningFormInfo> & runningFormInfos)1159 ErrCode FormMgrProxy::GetRunningFormInfosByBundleName(const std::string &bundleName,
1160 std::vector<RunningFormInfo> &runningFormInfos)
1161 {
1162 MessageParcel data;
1163 if (!WriteInterfaceToken(data)) {
1164 HILOG_ERROR("failed to write interface token");
1165 return ERR_APPEXECFWK_PARCEL_ERROR;
1166 }
1167
1168 if (!data.WriteString(bundleName)) {
1169 HILOG_ERROR("failed to write bundleName");
1170 return ERR_APPEXECFWK_PARCEL_ERROR;
1171 }
1172
1173 ErrCode error = GetRunningFormInfos(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS_BY_BUNDLE,
1174 data, runningFormInfos);
1175 if (error != ERR_OK) {
1176 HILOG_ERROR("failed to GetRunningFormInfosByBundleName: %{public}d", error);
1177 }
1178 return error;
1179 }
1180
GetFormsInfo(const FormInfoFilter & filter,std::vector<FormInfo> & formInfos)1181 int32_t FormMgrProxy::GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos)
1182 {
1183 HILOG_INFO("%{public}s start.", __func__);
1184 MessageParcel data;
1185 // write in token to help identify which stub to be called.
1186 if (!WriteInterfaceToken(data)) {
1187 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1188 return ERR_APPEXECFWK_PARCEL_ERROR;
1189 }
1190 if (!data.WriteParcelable(&filter)) {
1191 HILOG_ERROR("%{public}s, failed to write FormInfoFilter", __func__);
1192 return ERR_APPEXECFWK_PARCEL_ERROR;
1193 }
1194 // call private GetFormsInfo with Message which will send request to tell stub which handle function to be used.
1195 int error = GetFormsInfo(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO, data, formInfos);
1196 // formInfos should have been fulfilled at this point.
1197 if (error != ERR_OK) {
1198 HILOG_ERROR("%{public}s, failed to GetAllFormsInfo: %{public}d", __func__, error);
1199 }
1200
1201 return error;
1202 }
1203
IsRequestPublishFormSupported()1204 bool FormMgrProxy::IsRequestPublishFormSupported()
1205 {
1206 HILOG_INFO("%{public}s start.", __func__);
1207 MessageParcel data;
1208 // write in token to help identify which stub to be called.
1209 if (!WriteInterfaceToken(data)) {
1210 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1211 return false;
1212 }
1213 // send request.
1214 MessageParcel reply;
1215 MessageOption option;
1216 int error = Remote()->SendRequest(
1217 static_cast<uint32_t>(
1218 IFormMgr::Message::FORM_MGR_IS_REQUEST_PUBLISH_FORM_SUPPORTED),
1219 data,
1220 reply,
1221 option);
1222 if (error != ERR_OK) {
1223 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
1224 return false;
1225 }
1226 // retrieve and return result.
1227 return reply.ReadBool();
1228 }
1229
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken)1230 int32_t FormMgrProxy::StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken)
1231 {
1232 HILOG_INFO("%{public}s start.", __func__);
1233 MessageParcel data;
1234 // write in token to help identify which stub to be called.
1235 if (!WriteInterfaceToken(data)) {
1236 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1237 return ERR_APPEXECFWK_PARCEL_ERROR;
1238 }
1239 // write in want
1240 if (!data.WriteParcelable(&want)) {
1241 HILOG_ERROR("%{public}s, failed to write want", __func__);
1242 return ERR_APPEXECFWK_PARCEL_ERROR;
1243 }
1244 // write in callerToken
1245 if (!data.WriteRemoteObject(callerToken)) {
1246 HILOG_ERROR("%{public}s, failed to write callerToken", __func__);
1247 return ERR_APPEXECFWK_PARCEL_ERROR;
1248 }
1249 // send request.
1250 MessageParcel reply;
1251 MessageOption option;
1252 int error = Remote()->SendRequest(
1253 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_START_ABILITY),
1254 data,
1255 reply,
1256 option);
1257 if (error != ERR_OK) {
1258 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
1259 return error;
1260 }
1261 // retrieve and return result.
1262 return reply.ReadInt32();
1263 }
1264
ShareForm(int64_t formId,const std::string & deviceId,const sptr<IRemoteObject> & callerToken,int64_t requestCode)1265 int32_t FormMgrProxy::ShareForm(int64_t formId, const std::string &deviceId, const sptr<IRemoteObject> &callerToken,
1266 int64_t requestCode)
1267 {
1268 MessageParcel data;
1269 if (!WriteInterfaceToken(data)) {
1270 HILOG_ERROR("failed to write interface token.");
1271 return ERR_APPEXECFWK_PARCEL_ERROR;
1272 }
1273
1274 if (!data.WriteInt64(formId)) {
1275 HILOG_ERROR("failed to write formId.");
1276 return ERR_APPEXECFWK_PARCEL_ERROR;
1277 }
1278
1279 if (!data.WriteString(deviceId)) {
1280 HILOG_ERROR("failed to write deviceId.");
1281 return ERR_APPEXECFWK_PARCEL_ERROR;
1282 }
1283
1284 if (!data.WriteRemoteObject(callerToken)) {
1285 HILOG_ERROR("failed to write callerToken.");
1286 return ERR_APPEXECFWK_PARCEL_ERROR;
1287 }
1288
1289 if (!data.WriteInt64(requestCode)) {
1290 HILOG_ERROR("failed to write requestCode.");
1291 return ERR_APPEXECFWK_PARCEL_ERROR;
1292 }
1293
1294 MessageParcel reply;
1295 MessageOption option;
1296 auto error = Remote()->SendRequest(
1297 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_SHARE_FORM), data, reply, option);
1298 if (error != ERR_OK) {
1299 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1300 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1301 }
1302 return reply.ReadInt32();
1303 }
1304
AcquireFormData(int64_t formId,int64_t requestCode,const sptr<IRemoteObject> & callerToken,AAFwk::WantParams & formData)1305 int32_t FormMgrProxy::AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
1306 AAFwk::WantParams &formData)
1307 {
1308 MessageParcel data;
1309 if (!WriteInterfaceToken(data)) {
1310 HILOG_ERROR("failed to write interface token.");
1311 return ERR_APPEXECFWK_PARCEL_ERROR;
1312 }
1313
1314 if (!data.WriteInt64(formId)) {
1315 HILOG_ERROR("failed to write formId.");
1316 return ERR_APPEXECFWK_PARCEL_ERROR;
1317 }
1318
1319 if (!data.WriteInt64(requestCode)) {
1320 HILOG_ERROR("failed to write requestCode.");
1321 return ERR_APPEXECFWK_PARCEL_ERROR;
1322 }
1323
1324 if (!data.WriteRemoteObject(callerToken)) {
1325 HILOG_ERROR("failed to write callerToken.");
1326 return ERR_APPEXECFWK_PARCEL_ERROR;
1327 }
1328
1329 int error;
1330 MessageParcel reply;
1331 error = SendTransactCmd(IFormMgr::Message::FORM_MGR_ACQUIRE_DATA, data, reply);
1332 if (error != ERR_OK) {
1333 return error;
1334 }
1335
1336 error = reply.ReadInt32();
1337 if (error != ERR_OK) {
1338 HILOG_ERROR("failed to read reply result");
1339 return error;
1340 }
1341 std::shared_ptr<AAFwk::WantParams> wantParams(reply.ReadParcelable<AAFwk::WantParams>());
1342 if (wantParams == nullptr) {
1343 HILOG_ERROR("failed to ReadParcelable<wantParams>");
1344 return ERR_APPEXECFWK_PARCEL_ERROR;
1345 }
1346 formData = *wantParams;
1347 return ERR_OK;
1348 }
1349
RecvFormShareInfoFromRemote(const FormShareInfo & info)1350 int32_t FormMgrProxy::RecvFormShareInfoFromRemote(const FormShareInfo &info)
1351 {
1352 MessageParcel data;
1353 if (!WriteInterfaceToken(data)) {
1354 HILOG_ERROR("failed to write interface token.");
1355 return ERR_APPEXECFWK_PARCEL_ERROR;
1356 }
1357
1358 if (!data.WriteParcelable(&info)) {
1359 HILOG_ERROR("failed to write form share info.");
1360 return ERR_APPEXECFWK_PARCEL_ERROR;
1361 }
1362
1363 MessageParcel reply;
1364 MessageOption option;
1365 auto error = Remote()->SendRequest(
1366 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RECV_FORM_SHARE_INFO_FROM_REMOTE), data, reply, option);
1367 if (error != ERR_OK) {
1368 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1369 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1370 }
1371 return reply.ReadInt32();
1372 }
1373
CheckFMSReady()1374 bool FormMgrProxy::CheckFMSReady()
1375 {
1376 HILOG_INFO("%{public}s start.", __func__);
1377 MessageParcel data;
1378 // write in token to help identify which stub to be called
1379 if (!WriteInterfaceToken(data)) {
1380 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1381 return false;
1382 }
1383 // send request
1384 MessageParcel reply;
1385 MessageOption option;
1386 int error = Remote()->SendRequest(
1387 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_CHECK_FMS_READY), data, reply, option);
1388 if (error != ERR_OK) {
1389 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
1390 return false;
1391 }
1392 // retrieve and return result;
1393 return reply.ReadBool();
1394 }
1395
SetBackgroundFunction(const std::string funcName,const std::string params)1396 int32_t FormMgrProxy::SetBackgroundFunction(const std::string funcName, const std::string params)
1397 {
1398 HILOG_DEBUG("start");
1399 MessageParcel data;
1400 // write in token to help identify which stub to be called
1401 if (!data.WriteString16(Str8ToStr16(funcName))) {
1402 HILOG_ERROR("failed to write funcName");
1403 return ERR_APPEXECFWK_PARCEL_ERROR;
1404 }
1405 if (!data.WriteString16(Str8ToStr16(params))) {
1406 HILOG_ERROR("failed to write params");
1407 return ERR_APPEXECFWK_PARCEL_ERROR;
1408 }
1409 // send request
1410 MessageParcel reply;
1411 MessageOption option;
1412 int error = Remote()->SendRequest(Constants::EVENT_CALL_NOTIFY, data, reply, option);
1413 if (error != ERR_OK) {
1414 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1415 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1416 }
1417 // retrieve and return result;
1418 return reply.ReadInt32();
1419 }
1420
GetFormsCount(bool isTempFormFlag,int32_t & formCount)1421 int32_t FormMgrProxy::GetFormsCount(bool isTempFormFlag, int32_t &formCount)
1422 {
1423 HILOG_INFO("%{public}s start.", __func__);
1424 MessageParcel data;
1425 if (!WriteInterfaceToken(data)) {
1426 HILOG_ERROR("failed to write interface token.");
1427 return ERR_APPEXECFWK_PARCEL_ERROR;
1428 }
1429 if (!data.WriteBool(isTempFormFlag)) {
1430 HILOG_ERROR("%{public}s, failed to write bool isEnableUpdate", __func__);
1431 return ERR_APPEXECFWK_PARCEL_ERROR;
1432 }
1433 MessageParcel reply;
1434 MessageOption option;
1435 int error = Remote()->SendRequest(
1436 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_COUNT), data, reply, option);
1437 if (error != ERR_OK) {
1438 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
1439 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1440 }
1441 int32_t result = reply.ReadInt32();
1442 formCount = reply.ReadInt32();
1443 return result;
1444 }
1445
RegisterFormAddObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1446 ErrCode FormMgrProxy::RegisterFormAddObserverByBundle(const std::string bundleName,
1447 const sptr<IRemoteObject> &callerToken)
1448 {
1449 HILOG_DEBUG("start.");
1450 MessageParcel data;
1451 if (!WriteInterfaceToken(data)) {
1452 HILOG_ERROR("failed to write interface token.");
1453 return ERR_APPEXECFWK_PARCEL_ERROR;
1454 }
1455
1456 if (!data.WriteString(bundleName)) {
1457 HILOG_ERROR("failed to write bundleName.");
1458 return ERR_APPEXECFWK_PARCEL_ERROR;
1459 }
1460
1461 if (!data.WriteRemoteObject(callerToken)) {
1462 HILOG_ERROR("failed to write callerToken.");
1463 return ERR_APPEXECFWK_PARCEL_ERROR;
1464 }
1465
1466 MessageParcel reply;
1467 MessageOption option(MessageOption::TF_ASYNC);
1468 auto error = Remote()->SendRequest(
1469 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_FORM_ADD_OBSERVER_BY_BUNDLE), data, reply, option);
1470 if (error != ERR_OK) {
1471 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1472 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1473 }
1474 return reply.ReadInt32();
1475 }
1476
RegisterFormRemoveObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1477 ErrCode FormMgrProxy::RegisterFormRemoveObserverByBundle(const std::string bundleName,
1478 const sptr<IRemoteObject> &callerToken)
1479 {
1480 HILOG_DEBUG("start.");
1481 MessageParcel data;
1482 if (!WriteInterfaceToken(data)) {
1483 HILOG_ERROR("failed to write interface token.");
1484 return ERR_APPEXECFWK_PARCEL_ERROR;
1485 }
1486
1487 if (!data.WriteString(bundleName)) {
1488 HILOG_ERROR("failed to write bundleName.");
1489 return ERR_APPEXECFWK_PARCEL_ERROR;
1490 }
1491
1492 if (!data.WriteRemoteObject(callerToken)) {
1493 HILOG_ERROR("failed to write callerToken.");
1494 return ERR_APPEXECFWK_PARCEL_ERROR;
1495 }
1496
1497 MessageParcel reply;
1498 MessageOption option(MessageOption::TF_ASYNC);
1499 auto error = Remote()->SendRequest(
1500 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_FORM_REMOVE_OBSERVER_BY_BUNDLE),
1501 data, reply, option);
1502 if (error != ERR_OK) {
1503 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1504 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1505 }
1506 return reply.ReadInt32();
1507 }
1508
GetHostFormsCount(std::string & bundleName,int32_t & formCount)1509 int32_t FormMgrProxy::GetHostFormsCount(std::string &bundleName, int32_t &formCount)
1510 {
1511 HILOG_INFO("%{public}s start.", __func__);
1512 MessageParcel data;
1513 if (!WriteInterfaceToken(data)) {
1514 HILOG_ERROR("failed to write interface token.");
1515 return ERR_APPEXECFWK_PARCEL_ERROR;
1516 }
1517 if (!data.WriteString(bundleName)) {
1518 HILOG_ERROR("%{public}s, failed to write bundleName", __func__);
1519 return ERR_APPEXECFWK_PARCEL_ERROR;
1520 }
1521 MessageParcel reply;
1522 MessageOption option;
1523 int error = Remote()->SendRequest(
1524 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_HOST_FORMS_COUNT), data, reply, option);
1525 if (error != ERR_OK) {
1526 HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d", __func__, error);
1527 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1528 }
1529 int32_t result = reply.ReadInt32();
1530 formCount = reply.ReadInt32();
1531 return result;
1532 }
1533
GetFormInstancesByFilter(const FormInstancesFilter & formInstancesFilter,std::vector<FormInstance> & formInstances)1534 int32_t FormMgrProxy::GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
1535 std::vector<FormInstance> &formInstances)
1536 {
1537 HILOG_DEBUG("start.");
1538 MessageParcel data;
1539 // write in token to help identify which stub to be called.
1540 if (!WriteInterfaceToken(data)) {
1541 HILOG_ERROR("failed to write interface token");
1542 return ERR_APPEXECFWK_PARCEL_ERROR;
1543 }
1544 if (!data.WriteParcelable(&formInstancesFilter)) {
1545 HILOG_ERROR("failed to write formInstancesFilter");
1546 return ERR_APPEXECFWK_PARCEL_ERROR;
1547 }
1548 auto error = GetFormInstance(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_FILTER, data, formInstances);
1549 if (error != ERR_OK) {
1550 HILOG_ERROR("failed to get form instances by filter: %{public}d", error);
1551 }
1552
1553 return error;
1554 }
1555
GetFormInstanceById(const int64_t formId,FormInstance & formInstance)1556 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, FormInstance &formInstance)
1557 {
1558 HILOG_DEBUG("start.");
1559 MessageParcel data;
1560 // write in token to help identify which stub to be called.
1561 if (!WriteInterfaceToken(data)) {
1562 HILOG_ERROR("failed to write interface token");
1563 return ERR_APPEXECFWK_PARCEL_ERROR;
1564 }
1565 if (!data.WriteInt64(formId)) {
1566 HILOG_ERROR("failed to write formId");
1567 return ERR_APPEXECFWK_PARCEL_ERROR;
1568 }
1569 auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1570 data, formInstance);
1571 if (error != ERR_OK) {
1572 HILOG_ERROR("failed to get parcelable info.");
1573 }
1574
1575 return error;
1576 }
1577
GetFormInstanceById(const int64_t formId,bool isIncludeUnused,FormInstance & formInstance)1578 ErrCode FormMgrProxy::GetFormInstanceById(const int64_t formId, bool isIncludeUnused, FormInstance &formInstance)
1579 {
1580 HILOG_DEBUG("start.");
1581 MessageParcel data;
1582 // write in token to help identify which stub to be called.
1583 if (!WriteInterfaceToken(data)) {
1584 HILOG_ERROR("failed to write interface token");
1585 return ERR_APPEXECFWK_PARCEL_ERROR;
1586 }
1587 if (!data.WriteInt64(formId)) {
1588 HILOG_ERROR("failed to write formId");
1589 return ERR_APPEXECFWK_PARCEL_ERROR;
1590 }
1591 if (!data.WriteBool(isIncludeUnused)) {
1592 HILOG_ERROR("failed to write isIncludeUnused");
1593 return ERR_APPEXECFWK_PARCEL_ERROR;
1594 }
1595
1596 auto error = GetParcelableInfo<FormInstance>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID,
1597 data, formInstance);
1598 if (error != ERR_OK) {
1599 HILOG_ERROR("failed to get parcelable info.");
1600 }
1601
1602 return error;
1603 }
1604
GetFormInstance(IFormMgr::Message code,MessageParcel & data,std::vector<FormInstance> & formInstances)1605 ErrCode FormMgrProxy::GetFormInstance(IFormMgr::Message code, MessageParcel &data,
1606 std::vector<FormInstance> &formInstances)
1607 {
1608 int error;
1609 MessageParcel reply;
1610 error = SendTransactCmd(code, data, reply);
1611 if (error != ERR_OK) {
1612 return error;
1613 }
1614 error = reply.ReadInt32();
1615 if (error != ERR_OK) {
1616 HILOG_ERROR("failed to read reply result");
1617 return error;
1618 }
1619 auto ret = GetParcelableInfos<FormInstance>(reply, formInstances);
1620 if (ret != ERR_OK) {
1621 HILOG_ERROR("failed to get parcelable infos.");
1622 return ERR_APPEXECFWK_PARCEL_ERROR;
1623 }
1624 return ret;
1625 }
1626
RegisterAddObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1627 ErrCode FormMgrProxy::RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1628 {
1629 HILOG_DEBUG("called.");
1630 MessageParcel data;
1631 if (!WriteInterfaceToken(data)) {
1632 HILOG_ERROR("failed to write interface token.");
1633 return ERR_APPEXECFWK_PARCEL_ERROR;
1634 }
1635 if (!data.WriteString(bundleName)) {
1636 HILOG_ERROR("failed to write bundleName.");
1637 return ERR_APPEXECFWK_PARCEL_ERROR;
1638 }
1639 if (!data.WriteRemoteObject(callerToken)) {
1640 HILOG_ERROR("failed to write callerToken.");
1641 return ERR_APPEXECFWK_PARCEL_ERROR;
1642 }
1643 MessageParcel reply;
1644 MessageOption option(MessageOption::TF_ASYNC);
1645 auto error = Remote()->SendRequest(
1646 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER), data, reply, option);
1647 if (error != ERR_OK) {
1648 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1649 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1650 }
1651 return reply.ReadInt32();
1652 }
1653
RegisterRemoveObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1654 ErrCode FormMgrProxy::RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1655 {
1656 HILOG_DEBUG("called.");
1657 MessageParcel data;
1658 if (!WriteInterfaceToken(data)) {
1659 HILOG_ERROR("failed to write interface token.");
1660 return ERR_APPEXECFWK_PARCEL_ERROR;
1661 }
1662 if (!data.WriteString(bundleName)) {
1663 HILOG_ERROR("failed to write bundleName.");
1664 return ERR_APPEXECFWK_PARCEL_ERROR;
1665 }
1666 if (!data.WriteRemoteObject(callerToken)) {
1667 HILOG_ERROR("failed to write callerToken.");
1668 return ERR_APPEXECFWK_PARCEL_ERROR;
1669 }
1670 MessageParcel reply;
1671 MessageOption option(MessageOption::TF_ASYNC);
1672 auto error = Remote()->SendRequest(
1673 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER), data, reply, option);
1674 if (error != ERR_OK) {
1675 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1676 return ERR_APPEXECFWK_FORM_SEND_FMS_MSG;
1677 }
1678 return reply.ReadInt32();
1679 }
1680
UpdateProxyForm(int64_t formId,const FormProviderData & FormProviderData,const std::vector<FormDataProxy> & formDataProxies)1681 ErrCode FormMgrProxy::UpdateProxyForm(int64_t formId, const FormProviderData &FormProviderData,
1682 const std::vector<FormDataProxy> &formDataProxies)
1683 {
1684 MessageParcel data;
1685 if (!WriteInterfaceToken(data)) {
1686 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1687 return ERR_APPEXECFWK_PARCEL_ERROR;
1688 }
1689 if (!data.WriteInt64(formId)) {
1690 HILOG_ERROR("%{public}s, failed to write formId", __func__);
1691 return ERR_APPEXECFWK_PARCEL_ERROR;
1692 }
1693 if (!data.WriteParcelable(&FormProviderData)) {
1694 HILOG_ERROR("%{public}s, failed to write formBindingData", __func__);
1695 return ERR_APPEXECFWK_PARCEL_ERROR;
1696 }
1697 if (!WriteFormDataProxies(data, formDataProxies)) {
1698 HILOG_ERROR("failed to write form data proxies.");
1699 return ERR_APPEXECFWK_PARCEL_ERROR;
1700 }
1701 MessageParcel reply;
1702 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_UPDATE_PROXY_FORM, data, reply);
1703 if (error != ERR_OK) {
1704 HILOG_ERROR("failed to SendTransactCmd.");
1705 return error;
1706 }
1707 return reply.ReadInt32();
1708 }
1709
RequestPublishProxyForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId,const std::vector<FormDataProxy> & formDataProxies)1710 ErrCode FormMgrProxy::RequestPublishProxyForm(Want &want, bool withFormBindingData,
1711 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
1712 const std::vector<FormDataProxy> &formDataProxies)
1713 {
1714 MessageParcel data;
1715
1716 if (!WriteInterfaceToken(data)) {
1717 HILOG_ERROR("%{public}s, failed to write interface token", __func__);
1718 return ERR_APPEXECFWK_PARCEL_ERROR;
1719 }
1720 if (!data.WriteParcelable(&want)) {
1721 HILOG_ERROR("%{public}s, failed to write want", __func__);
1722 return ERR_APPEXECFWK_PARCEL_ERROR;
1723 }
1724 if (!data.WriteBool(withFormBindingData)) {
1725 HILOG_ERROR("%{public}s, failed to write withFormBindingData", __func__);
1726 return ERR_APPEXECFWK_PARCEL_ERROR;
1727 }
1728 if (withFormBindingData) {
1729 if (!data.WriteParcelable(formBindingData.get())) {
1730 HILOG_ERROR("%{public}s, failed to write formBindingData", __func__);
1731 return ERR_APPEXECFWK_PARCEL_ERROR;
1732 }
1733 }
1734 if (!WriteFormDataProxies(data, formDataProxies)) {
1735 HILOG_ERROR("failed to write form data proxies.");
1736 return ERR_APPEXECFWK_PARCEL_ERROR;
1737 }
1738
1739 MessageParcel reply;
1740 int32_t error = SendTransactCmd(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_PROXY_FORM, data, reply);
1741 if (error != ERR_OK) {
1742 HILOG_ERROR("failed to SendTransactCmd.");
1743 return error;
1744 }
1745 ErrCode errCode = reply.ReadInt32();
1746 if (errCode == ERR_OK) {
1747 formId = reply.ReadInt64();
1748 }
1749 return errCode;
1750 }
1751
WriteFormDataProxies(MessageParcel & data,const std::vector<FormDataProxy> & formDataProxies)1752 bool FormMgrProxy::WriteFormDataProxies(MessageParcel &data, const std::vector<FormDataProxy> &formDataProxies)
1753 {
1754 HILOG_DEBUG("proxies size: %{public}zu.", formDataProxies.size());
1755 if (!data.WriteInt32(formDataProxies.size())) {
1756 HILOG_ERROR("failed to marshalling form data proxies size.");
1757 return false;
1758 }
1759 for (const auto &formDataProxy : formDataProxies) {
1760 if (!data.WriteString16(Str8ToStr16(formDataProxy.key))) {
1761 HILOG_ERROR("failed to marshalling form data proxies key: %{public}s.", formDataProxy.key.c_str());
1762 return false;
1763 }
1764 if (!data.WriteString16(Str8ToStr16(formDataProxy.subscribeId))) {
1765 HILOG_ERROR("failed to marshalling form data proxies subscribeId: %{public}s.",
1766 formDataProxy.subscribeId.c_str());
1767 return false;
1768 }
1769 }
1770 return true;
1771 }
1772
RegisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)1773 int32_t FormMgrProxy::RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
1774 {
1775 HILOG_DEBUG("start.");
1776 MessageParcel data;
1777 // write in token to help identify which stub to be called.
1778 if (!WriteInterfaceToken(data)) {
1779 HILOG_ERROR("failed to write interface token");
1780 return ERR_APPEXECFWK_PARCEL_ERROR;
1781 }
1782 // write in interceptor
1783 if (!data.WriteRemoteObject(interceptorCallback)) {
1784 HILOG_ERROR("failed to write interceptor");
1785 return ERR_APPEXECFWK_PARCEL_ERROR;
1786 }
1787 // send request.
1788 MessageParcel reply;
1789 MessageOption option;
1790 int error = Remote()->SendRequest(
1791 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_PUBLISH_FORM_INTERCEPTOR),
1792 data,
1793 reply,
1794 option);
1795 if (error != ERR_OK) {
1796 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1797 return error;
1798 }
1799 // retrieve and return result.
1800 return reply.ReadInt32();
1801 }
1802
UnregisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)1803 int32_t FormMgrProxy::UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
1804 {
1805 HILOG_DEBUG("start.");
1806 MessageParcel data;
1807 // write in token to help identify which stub to be called.
1808 if (!WriteInterfaceToken(data)) {
1809 HILOG_ERROR("failed to write interface token");
1810 return ERR_APPEXECFWK_PARCEL_ERROR;
1811 }
1812 // write in interceptor
1813 if (!data.WriteRemoteObject(interceptorCallback)) {
1814 HILOG_ERROR("failed to write interceptor");
1815 return ERR_APPEXECFWK_PARCEL_ERROR;
1816 }
1817 // send request.
1818 MessageParcel reply;
1819 MessageOption option;
1820 int error = Remote()->SendRequest(
1821 static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UNREGISTER_PUBLISH_FORM_INTERCEPTOR),
1822 data,
1823 reply,
1824 option);
1825 if (error != ERR_OK) {
1826 HILOG_ERROR("failed to SendRequest: %{public}d", error);
1827 return error;
1828 }
1829 // retrieve and return result.
1830 return reply.ReadInt32();
1831 }
1832 } // namespace AppExecFwk
1833 } // namespace OHOS
1834