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_stub.h"
17
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_info.h"
21 #include "form_mgr_errors.h"
22 #include "ipc_skeleton.h"
23 #include "ipc_types.h"
24 #include "iremote_object.h"
25 #include <vector>
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 const int32_t LIMIT_PARCEL_SIZE = 1024;
30
SplitString(const std::string & source,std::vector<std::string> & strings)31 void SplitString(const std::string &source, std::vector<std::string> &strings)
32 {
33 size_t splitSize = (source.size() / LIMIT_PARCEL_SIZE);
34 if ((source.size() % LIMIT_PARCEL_SIZE) != 0) {
35 splitSize++;
36 }
37 HILOG_DEBUG("the dump string split into %{public}zu size", splitSize);
38 for (size_t i = 0; i < splitSize; i++) {
39 size_t start = LIMIT_PARCEL_SIZE * i;
40 strings.emplace_back(source.substr(start, LIMIT_PARCEL_SIZE));
41 }
42 }
43
FormMgrStub()44 FormMgrStub::FormMgrStub()
45 {
46 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ADD_FORM)] =
47 &FormMgrStub::HandleAddForm;
48 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_DELETE_FORM)] =
49 &FormMgrStub::HandleDeleteForm;
50 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RELEASE_FORM)] =
51 &FormMgrStub::HandleReleaseForm;
52 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UPDATE_FORM)] =
53 &FormMgrStub::HandleUpdateForm;
54 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_FORM)] =
55 &FormMgrStub::HandleRequestForm;
56 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORM_WHETHER_VISIBLE)] =
57 &FormMgrStub::HandleNotifyWhetherVisibleForms;
58 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_CAST_TEMP_FORM)] =
59 &FormMgrStub::HandleCastTempForm;
60 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_STORAGE_FORM_INFOS)] =
61 &FormMgrStub::HandleDumpStorageFormInfos;
62 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_NAME)] =
63 &FormMgrStub::HandleDumpFormInfoByBundleName;
64 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID)] =
65 &FormMgrStub::HandleDumpFormInfoByFormId;
66 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID)] =
67 &FormMgrStub::HandleDumpFormTimerByFormId;
68 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_SET_NEXT_REFRESH_TIME)] =
69 &FormMgrStub::HandleSetNextRefreshTime;
70 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_LIFECYCLE_UPDATE)] =
71 &FormMgrStub::HandleLifecycleUpdate;
72 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_MESSAGE_EVENT)] =
73 &FormMgrStub::HandleMessageEvent;
74 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_DELETE_INVALID_FORMS)] =
75 &FormMgrStub::HandleDeleteInvalidForms;
76 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ACQUIRE_FORM_STATE)] =
77 &FormMgrStub::HandleAcquireFormState;
78 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_VISIBLE)] =
79 &FormMgrStub::HandleNotifyFormsVisible;
80 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_PRIVACY_PROTECTED)] =
81 &FormMgrStub::HandleNotifyFormsPrivacyProtected;
82 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_NOTIFY_FORMS_ENABLE_UPDATE)] =
83 &FormMgrStub::HandleNotifyFormsEnableUpdate;
84 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_ALL_FORMS_INFO)] =
85 &FormMgrStub::HandleGetAllFormsInfo;
86 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_APP)] =
87 &FormMgrStub::HandleGetFormsInfoByApp;
88 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO_BY_MODULE)] =
89 &FormMgrStub::HandleGetFormsInfoByModule;
90 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_INFO)] =
91 &FormMgrStub::HandleGetFormsInfo;
92 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ROUTER_EVENT)] =
93 &FormMgrStub::HandleRouterEvent;
94 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_BACKGROUND_EVENT)] =
95 &FormMgrStub::HandleBackgroundEvent;
96 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_FORM)] =
97 &FormMgrStub::HandleRequestPublishForm;
98 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_SHARE_FORM)] =
99 &FormMgrStub::HandleShareForm;
100 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RECV_FORM_SHARE_INFO_FROM_REMOTE)] =
101 &FormMgrStub::HandleRecvFormShareInfoFromRemote;
102 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_IS_REQUEST_PUBLISH_FORM_SUPPORTED)] =
103 &FormMgrStub::HandleIsRequestPublishFormSupported;
104 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_START_ABILITY)] =
105 &FormMgrStub::HandleStartAbility;
106 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_CHECK_FMS_READY)] =
107 &FormMgrStub::HandleCheckFMSReady;
108 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_STOP_RENDERING_FORM)] =
109 &FormMgrStub::HandleStopRenderingForm;
110 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_FORM_ADD_OBSERVER_BY_BUNDLE)] =
111 &FormMgrStub::HandleRegisterFormAddObserverByBundle;
112 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_FORM_REMOVE_OBSERVER_BY_BUNDLE)] =
113 &FormMgrStub::HandleRegisterFormRemoveObserverByBundle;
114 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_ACQUIRE_DATA)] =
115 &FormMgrStub::HandleAcquireFormData;
116 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORMS_COUNT)] =
117 &FormMgrStub::HandleGetFormsCount;
118 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_HOST_FORMS_COUNT)] =
119 &FormMgrStub::HandleGetHostFormsCount;
120 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS)] =
121 &FormMgrStub::HandleGetRunningFormInfos;
122 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_RUNNING_FORM_INFOS_BY_BUNDLE)] =
123 &FormMgrStub::HandleGetRunningFormInfosByBundleName;
124 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_FILTER)] =
125 &FormMgrStub::HandleGetFormInstancesByFilter;
126 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_GET_FORM_INSTANCES_FROM_BY_ID)] =
127 &FormMgrStub::HandleGetFormInstanceById;
128 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_ADD_OBSERVER)] =
129 &FormMgrStub::HandleRegisterAddObserver;
130 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_REMOVE_OBSERVER)] =
131 &FormMgrStub::HandleRegisterRemoveObserver;
132 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UPDATE_PROXY_FORM)] =
133 &FormMgrStub::HandleUpdateProxyForm;
134 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REQUEST_PUBLISH_PROXY_FORM)] =
135 &FormMgrStub::HandleRequestPublishProxyForm;
136 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_RELEASE_RENDERER)] =
137 &FormMgrStub::HandleReleaseRenderer;
138 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_REGISTER_PUBLISH_FORM_INTERCEPTOR)] =
139 &FormMgrStub::HandleRegisterPublishFormInterceptor;
140 memberFuncMap_[static_cast<uint32_t>(IFormMgr::Message::FORM_MGR_UNREGISTER_PUBLISH_FORM_INTERCEPTOR)] =
141 &FormMgrStub::HandleUnregisterPublishFormInterceptor;
142 }
143
~FormMgrStub()144 FormMgrStub::~FormMgrStub()
145 {
146 memberFuncMap_.clear();
147 }
148
149 /**
150 * @brief handle remote request.
151 * @param data input param.
152 * @param reply output param.
153 * @param option message option.
154 * @return Returns ERR_OK on success, others on failure.
155 */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)156 int FormMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
157 {
158 HILOG_INFO("FormMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
159 std::u16string descriptor = FormMgrStub::GetDescriptor();
160 std::u16string remoteDescriptor = data.ReadInterfaceToken();
161 if (descriptor != remoteDescriptor) {
162 HILOG_ERROR("%{public}s failed, local descriptor is not equal to remote", __func__);
163 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
164 }
165
166 auto itFunc = memberFuncMap_.find(code);
167 if (itFunc != memberFuncMap_.end()) {
168 auto memberFunc = itFunc->second;
169 if (memberFunc != nullptr) {
170 return (this->*memberFunc)(data, reply);
171 }
172 }
173 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
174 }
175 /**
176 * @brief handle AddForm message.
177 * @param data input param.
178 * @param reply output param.
179 * @return Returns ERR_OK on success, others on failure.
180 */
HandleAddForm(MessageParcel & data,MessageParcel & reply)181 int32_t FormMgrStub::HandleAddForm(MessageParcel &data, MessageParcel &reply)
182 {
183 int64_t formId = data.ReadInt64();
184 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
185 if (!want) {
186 HILOG_ERROR("%{public}s, failed to ReadParcelable<FormReqInfo>", __func__);
187 return ERR_APPEXECFWK_PARCEL_ERROR;
188 }
189
190 sptr<IRemoteObject> client = data.ReadRemoteObject();
191 if (client == nullptr) {
192 HILOG_ERROR("%{public}s, failed to RemoteObject invalidate", __func__);
193 return ERR_APPEXECFWK_PARCEL_ERROR;
194 }
195
196 FormJsInfo formJsInfo;
197 int32_t result = AddForm(formId, *want, client, formJsInfo);
198 reply.WriteInt32(result);
199 reply.WriteParcelable(&formJsInfo);
200
201 return result;
202 }
203 /**
204 * @brief handle DeleteForm message.
205 * @param data input param.
206 * @param reply output param.
207 * @return Returns ERR_OK on success, others on failure.
208 */
HandleDeleteForm(MessageParcel & data,MessageParcel & reply)209 int32_t FormMgrStub::HandleDeleteForm(MessageParcel &data, MessageParcel &reply)
210 {
211 int64_t formId = data.ReadInt64();
212 sptr<IRemoteObject> client = data.ReadRemoteObject();
213 if (client == nullptr) {
214 return ERR_APPEXECFWK_PARCEL_ERROR;
215 }
216 int32_t result = DeleteForm(formId, client);
217 reply.WriteInt32(result);
218 return result;
219 }
220 /**
221 * @brief handle DeleteFormByCompId message.
222 * @param data input param.
223 * @param reply output param.
224 * @return Returns ERR_OK on success, others on failure.
225 */
HandleStopRenderingForm(MessageParcel & data,MessageParcel & reply)226 int32_t FormMgrStub::HandleStopRenderingForm(MessageParcel &data, MessageParcel &reply)
227 {
228 int64_t formId = data.ReadInt64();
229 std::string compId = data.ReadString();
230 int32_t result = StopRenderingForm(formId, compId);
231 reply.WriteInt32(result);
232 return result;
233 }
234 /**
235 * @brief handle ReleaseForm message.
236 * @param data input param.
237 * @param reply output param.
238 * @return Returns ERR_OK on success, others on failure.
239 */
HandleReleaseForm(MessageParcel & data,MessageParcel & reply)240 int32_t FormMgrStub::HandleReleaseForm(MessageParcel &data, MessageParcel &reply)
241 {
242 int64_t formId = data.ReadInt64();
243 sptr<IRemoteObject> client = data.ReadRemoteObject();
244 if (client == nullptr) {
245 return ERR_APPEXECFWK_PARCEL_ERROR;
246 }
247 bool delCache = data.ReadBool();
248
249 int32_t result = ReleaseForm(formId, client, delCache);
250 reply.WriteInt32(result);
251 return result;
252 }
253 /**
254 * @brief handle UpdateForm message.
255 * @param data input param.
256 * @param reply output param.
257 * @return Returns ERR_OK on success, others on failure.
258 */
HandleUpdateForm(MessageParcel & data,MessageParcel & reply)259 int32_t FormMgrStub::HandleUpdateForm(MessageParcel &data, MessageParcel &reply)
260 {
261 int64_t formId = data.ReadInt64();
262 std::unique_ptr<FormProviderData> formBindingData(data.ReadParcelable<FormProviderData>());
263 if (formBindingData == nullptr) {
264 HILOG_ERROR("%{public}s, failed to get formBindingData.", __func__);
265 return ERR_APPEXECFWK_PARCEL_ERROR;
266 }
267 int32_t result = UpdateForm(formId, *formBindingData);
268 reply.WriteInt32(result);
269 return result;
270 }
271 /**
272 * @brief handle SetNextRefreshTime message.
273 * @param data input param.
274 * @param reply output param.
275 * @return Returns ERR_OK on success, others on failure.
276 */
HandleSetNextRefreshTime(MessageParcel & data,MessageParcel & reply)277 int32_t FormMgrStub::HandleSetNextRefreshTime(MessageParcel &data, MessageParcel &reply)
278 {
279 int64_t formId = data.ReadInt64();
280 int64_t nextTime = data.ReadInt64();
281 int32_t result = SetNextRefreshTime(formId, nextTime);
282 reply.WriteInt32(result);
283 return result;
284 }
285
286 /**
287 * @brief handle ReleaseRenderer message.
288 * @param data input param.
289 * @param reply output param.
290 * @return Returns ERR_OK on success, others on failure.
291 */
HandleReleaseRenderer(MessageParcel & data,MessageParcel & reply)292 int32_t FormMgrStub::HandleReleaseRenderer(MessageParcel &data, MessageParcel &reply)
293 {
294 int64_t formId = data.ReadInt64();
295 std::string compId = data.ReadString();
296 int32_t result = ReleaseRenderer(formId, compId);
297 reply.WriteInt32(result);
298 return result;
299 }
300
301 /**
302 * @brief handle RequestPublishForm message.
303 * @param data input param.
304 * @param reply output param.
305 * @return Returns ERR_OK on success, others on failure.
306 */
HandleRequestPublishForm(MessageParcel & data,MessageParcel & reply)307 ErrCode FormMgrStub::HandleRequestPublishForm(MessageParcel &data, MessageParcel &reply)
308 {
309 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
310 if (want == nullptr) {
311 HILOG_ERROR("%{public}s, failed to get want.", __func__);
312 return ERR_APPEXECFWK_PARCEL_ERROR;
313 }
314
315 bool withFormBindingData = data.ReadBool();
316 std::unique_ptr<FormProviderData> formProviderData = nullptr;
317 if (withFormBindingData) {
318 formProviderData.reset(data.ReadParcelable<FormProviderData>());
319 if (formProviderData == nullptr) {
320 HILOG_ERROR("%{public}s, failed to get formProviderData.", __func__);
321 return ERR_APPEXECFWK_PARCEL_ERROR;
322 }
323 }
324
325 int64_t formId = 0;
326 ErrCode result = RequestPublishForm(*want, withFormBindingData, formProviderData, formId);
327 reply.WriteInt32(result);
328 if (result == ERR_OK) {
329 reply.WriteInt64(formId);
330 }
331 return result;
332 }
333 /**
334 * @brief handle LifecycleUpdate message.
335 * @param data input param.
336 * @param reply output param.
337 * @return Returns ERR_OK on success, others on failure.
338 */
HandleLifecycleUpdate(MessageParcel & data,MessageParcel & reply)339 int32_t FormMgrStub::HandleLifecycleUpdate(MessageParcel &data, MessageParcel &reply)
340 {
341 std::vector<int64_t> formIds;
342 bool ret = data.ReadInt64Vector(&formIds);
343 if (!ret) {
344 return ERR_APPEXECFWK_PARCEL_ERROR;
345 }
346 sptr<IRemoteObject> client = data.ReadRemoteObject();
347 if (client == nullptr) {
348 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
349 return ERR_APPEXECFWK_PARCEL_ERROR;
350 }
351 bool updateType = data.ReadBool();
352 int32_t result = LifecycleUpdate(formIds, client, updateType);
353 reply.WriteInt32(result);
354 return result;
355 }
356 /**
357 * @brief handle RequestForm message.
358 * @param data input param.
359 * @param reply output param.
360 * @return Returns ERR_OK on success, others on failure.
361 */
HandleRequestForm(MessageParcel & data,MessageParcel & reply)362 int32_t FormMgrStub::HandleRequestForm(MessageParcel &data, MessageParcel &reply)
363 {
364 HILOG_INFO("%{public}s called.", __func__);
365
366 int64_t formId = data.ReadInt64();
367
368 sptr<IRemoteObject> client = data.ReadRemoteObject();
369 if (client == nullptr) {
370 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
371 return ERR_APPEXECFWK_PARCEL_ERROR;
372 }
373
374 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
375 if (!want) {
376 HILOG_ERROR("%{public}s, failed to ReadParcelable<Want>", __func__);
377 return ERR_APPEXECFWK_PARCEL_ERROR;
378 }
379
380 int32_t result = RequestForm(formId, client, *want);
381 reply.WriteInt32(result);
382 return result;
383 }
384 /**
385 * @brief handle NotifyVisibleForms message.
386 * @param data input param.
387 * @param reply output param.
388 * @return Returns ERR_OK on success, others on failure.
389 */
HandleNotifyWhetherVisibleForms(MessageParcel & data,MessageParcel & reply)390 int32_t FormMgrStub::HandleNotifyWhetherVisibleForms(MessageParcel &data, MessageParcel &reply)
391 {
392 std::vector<int64_t> formIds;
393 bool ret = data.ReadInt64Vector(&formIds);
394 if (!ret) {
395 return ERR_APPEXECFWK_PARCEL_ERROR;
396 }
397
398 sptr<IRemoteObject> client = data.ReadRemoteObject();
399 if (client == nullptr) {
400 return ERR_APPEXECFWK_PARCEL_ERROR;
401 }
402 int32_t formVisibleType = data.ReadInt32();
403
404 int32_t result = NotifyWhetherVisibleForms(formIds, client, formVisibleType);
405 reply.WriteInt32(result);
406 return result;
407 }
408
409 /**
410 * @brief handle CastTempForm message.
411 * @param data input param.
412 * @param reply output param.
413 * @return Returns ERR_OK on success, others on failure.
414 */
HandleCastTempForm(MessageParcel & data,MessageParcel & reply)415 int32_t FormMgrStub::HandleCastTempForm(MessageParcel &data, MessageParcel &reply)
416 {
417 int64_t formId = data.ReadInt64();
418 sptr<IRemoteObject> client = data.ReadRemoteObject();
419 if (client == nullptr) {
420 return ERR_APPEXECFWK_PARCEL_ERROR;
421 }
422
423 int32_t result = CastTempForm(formId, client);
424 reply.WriteInt32(result);
425 return result;
426 }
427 /**
428 * @brief Handle DumpStorageFormInfos message.
429 * @param data input param.
430 * @param reply output param.
431 * @return Returns ERR_OK on success, others on failure.
432 */
HandleDumpStorageFormInfos(MessageParcel & data,MessageParcel & reply)433 int32_t FormMgrStub::HandleDumpStorageFormInfos(MessageParcel &data, MessageParcel &reply)
434 {
435 std::string formInfos;
436 int32_t result = DumpStorageFormInfos(formInfos);
437 reply.WriteInt32(result);
438 if (result == ERR_OK) {
439 std::vector<std::string> dumpInfos;
440 SplitString(formInfos, dumpInfos);
441 if (!reply.WriteStringVector(dumpInfos)) {
442 HILOG_ERROR("%{public}s, failed to WriteStringVector<dumpInfos>", __func__);
443 return ERR_APPEXECFWK_PARCEL_ERROR;
444 }
445 }
446
447 return result;
448 }
449 /**
450 * @brief Handle DumpFormInfoByBundleName message.
451 * @param data input param.
452 * @param reply output param.
453 * @return Returns ERR_OK on success, others on failure.
454 */
HandleDumpFormInfoByBundleName(MessageParcel & data,MessageParcel & reply)455 int32_t FormMgrStub::HandleDumpFormInfoByBundleName(MessageParcel &data, MessageParcel &reply)
456 {
457 std::string bundleName = data.ReadString();
458 std::string formInfos;
459 int32_t result = DumpFormInfoByBundleName(bundleName, formInfos);
460 reply.WriteInt32(result);
461 if (result == ERR_OK) {
462 HILOG_DEBUG("%{public}s, formInfos: %{public}s", __func__, formInfos.c_str());
463 std::vector<std::string> dumpInfos;
464 SplitString(formInfos, dumpInfos);
465 if (!reply.WriteStringVector(dumpInfos)) {
466 HILOG_ERROR("%{public}s, failed to WriteStringVector<dumpInfos>", __func__);
467 return ERR_APPEXECFWK_PARCEL_ERROR;
468 }
469 }
470
471 return result;
472 }
473 /**
474 * @brief Handle DumpFormInfoByFormId message.
475 * @param data input param.
476 * @param reply output param.
477 * @return Returns ERR_OK on success, others on failure.
478 */
HandleDumpFormInfoByFormId(MessageParcel & data,MessageParcel & reply)479 int32_t FormMgrStub::HandleDumpFormInfoByFormId(MessageParcel &data, MessageParcel &reply)
480 {
481 int64_t formId = data.ReadInt64();
482 std::string formInfo;
483 int32_t result = DumpFormInfoByFormId(formId, formInfo);
484 reply.WriteInt32(result);
485 if (result == ERR_OK) {
486 std::vector<std::string> dumpInfos;
487 SplitString(formInfo, dumpInfos);
488 if (!reply.WriteStringVector(dumpInfos)) {
489 HILOG_ERROR("%{public}s, failed to WriteStringVector<dumpInfos>", __func__);
490 return ERR_APPEXECFWK_PARCEL_ERROR;
491 }
492 }
493 return result;
494 }
495 /**
496 * @brief Handle DumpFormTimerByFormId message.
497 * @param data input param.
498 * @param reply output param.
499 * @return Returns ERR_OK on success, others on failure.
500 */
HandleDumpFormTimerByFormId(MessageParcel & data,MessageParcel & reply)501 int32_t FormMgrStub::HandleDumpFormTimerByFormId(MessageParcel &data, MessageParcel &reply)
502 {
503 int64_t formId = data.ReadInt64();
504 std::string isTimingService;
505 int32_t result = DumpFormTimerByFormId(formId, isTimingService);
506 reply.WriteInt32(result);
507 if (result == ERR_OK) {
508 std::vector<std::string> dumpInfos;
509 SplitString(isTimingService, dumpInfos);
510 if (!reply.WriteStringVector(dumpInfos)) {
511 HILOG_ERROR("%{public}s, failed to WriteStringVector<dumpInfos>", __func__);
512 return ERR_APPEXECFWK_PARCEL_ERROR;
513 }
514 }
515 return result;
516 }
517
518 /**
519 * @brief Handle DumpFormInfoByFormId message.
520 * @param data input param.
521 * @param reply output param.
522 * @return Returns ERR_OK on success, others on failure.
523 */
HandleMessageEvent(MessageParcel & data,MessageParcel & reply)524 int32_t FormMgrStub::HandleMessageEvent(MessageParcel &data, MessageParcel &reply)
525 {
526 HILOG_INFO("%{public}s called.", __func__);
527 int64_t formId = data.ReadInt64();
528 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
529 if (!want) {
530 HILOG_ERROR("%{public}s, failed to ReadParcelable<Want>", __func__);
531 return ERR_APPEXECFWK_PARCEL_ERROR;
532 }
533
534 sptr<IRemoteObject> client = data.ReadRemoteObject();
535 if (client == nullptr) {
536 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
537 return ERR_APPEXECFWK_PARCEL_ERROR;
538 }
539
540 int32_t result = MessageEvent(formId, *want, client);
541 reply.WriteInt32(result);
542 return result;
543 }
544
545 /**
546 * @brief Handle RouterEvent message.
547 * @param data input param.
548 * @param reply output param.
549 * @return Returns ERR_OK on success, others on failure.
550 */
HandleRouterEvent(MessageParcel & data,MessageParcel & reply)551 int32_t FormMgrStub::HandleRouterEvent(MessageParcel &data, MessageParcel &reply)
552 {
553 HILOG_INFO("%{public}s called.", __func__);
554 int64_t formId = data.ReadInt64();
555 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
556 if (!want) {
557 HILOG_ERROR("%{public}s, failed to ReadParcelable<Want>", __func__);
558 return ERR_APPEXECFWK_PARCEL_ERROR;
559 }
560 sptr<IRemoteObject> client = data.ReadRemoteObject();
561 if (client == nullptr) {
562 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
563 return ERR_APPEXECFWK_PARCEL_ERROR;
564 }
565
566 int32_t result = RouterEvent(formId, *want, client);
567 reply.WriteInt32(result);
568 return result;
569 }
570
571 /**
572 * @brief Handle Background message.
573 * @param data input param.
574 * @param reply output param.
575 * @return Returns ERR_OK on success, others on failure.
576 */
HandleBackgroundEvent(MessageParcel & data,MessageParcel & reply)577 int32_t FormMgrStub::HandleBackgroundEvent(MessageParcel &data, MessageParcel &reply)
578 {
579 HILOG_INFO("%{public}s called.", __func__);
580 int64_t formId = data.ReadInt64();
581 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
582 if (!want) {
583 HILOG_ERROR("%{public}s, failed to ReadParcelable<Want>", __func__);
584 return ERR_APPEXECFWK_PARCEL_ERROR;
585 }
586 sptr<IRemoteObject> client = data.ReadRemoteObject();
587 if (client == nullptr) {
588 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
589 return ERR_APPEXECFWK_PARCEL_ERROR;
590 }
591
592 int32_t result = BackgroundEvent(formId, *want, client);
593 reply.WriteInt32(result);
594 return result;
595 }
596
597 /**
598 * @brief Handle DeleteInvalidForms message.
599 * @param data input param.
600 * @param reply output param.
601 * @return Returns ERR_OK on success, others on failure.
602 */
HandleDeleteInvalidForms(MessageParcel & data,MessageParcel & reply)603 int32_t FormMgrStub::HandleDeleteInvalidForms(MessageParcel &data, MessageParcel &reply)
604 {
605 HILOG_INFO("%{public}s called.", __func__);
606 std::vector<int64_t> formIds;
607 if (!data.ReadInt64Vector(&formIds)) {
608 HILOG_ERROR("%{public}s, failed to ReadInt64Vector", __func__);
609 return ERR_APPEXECFWK_PARCEL_ERROR;
610 }
611 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
612 if (callerToken == nullptr) {
613 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
614 return ERR_APPEXECFWK_PARCEL_ERROR;
615 }
616 int32_t numFormsDeleted = 0;
617 int32_t result = DeleteInvalidForms(formIds, callerToken, numFormsDeleted);
618 if (!reply.WriteInt32(result)) {
619 HILOG_ERROR("%{public}s, failed to write result", __func__);
620 return ERR_APPEXECFWK_PARCEL_ERROR;
621 }
622 if (!reply.WriteInt32(numFormsDeleted)) {
623 HILOG_ERROR("%{public}s, failed to write numFormsDeleted", __func__);
624 return ERR_APPEXECFWK_PARCEL_ERROR;
625 }
626 return result;
627 }
628
629 /**
630 * @brief Handle AcquireFormState message.
631 * @param data input param.
632 * @param reply output param.
633 * @return Returns ERR_OK on success, others on failure.
634 */
HandleAcquireFormState(MessageParcel & data,MessageParcel & reply)635 int32_t FormMgrStub::HandleAcquireFormState(MessageParcel &data, MessageParcel &reply)
636 {
637 HILOG_INFO("%{public}s called.", __func__);
638 FormStateInfo stateInfo {};
639 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
640 if (want == nullptr) {
641 HILOG_ERROR("%{public}s, failed to ReadParcelable want", __func__);
642 return ERR_APPEXECFWK_PARCEL_ERROR;
643 }
644 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
645 if (callerToken == nullptr) {
646 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
647 return ERR_APPEXECFWK_PARCEL_ERROR;
648 }
649 int32_t result = AcquireFormState(*want, callerToken, stateInfo);
650 if (!reply.WriteInt32(result)) {
651 HILOG_ERROR("%{public}s, failed to write result", __func__);
652 return ERR_APPEXECFWK_PARCEL_ERROR;
653 }
654 if (!reply.WriteInt32((int32_t)stateInfo.state)) {
655 HILOG_ERROR("%{public}s, failed to write state", __func__);
656 return ERR_APPEXECFWK_PARCEL_ERROR;
657 }
658 return result;
659 }
660
661 /**
662 * @brief Handle NotifyFormsVisible message.
663 * @param data input param.
664 * @param reply output param.
665 * @return Returns ERR_OK on success, others on failure.
666 */
HandleNotifyFormsVisible(MessageParcel & data,MessageParcel & reply)667 int32_t FormMgrStub::HandleNotifyFormsVisible(MessageParcel &data, MessageParcel &reply)
668 {
669 HILOG_INFO("%{public}s called.", __func__);
670 std::vector<int64_t> formIds;
671 if (!data.ReadInt64Vector(&formIds)) {
672 HILOG_ERROR("%{public}s, failed to ReadInt64Vector", __func__);
673 return ERR_APPEXECFWK_PARCEL_ERROR;
674 }
675 bool isVisible = false;
676 if (!data.ReadBool(isVisible)) {
677 HILOG_ERROR("%{public}s, failed to ReadBool", __func__);
678 return ERR_APPEXECFWK_PARCEL_ERROR;
679 }
680 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
681 if (callerToken == nullptr) {
682 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
683 return ERR_APPEXECFWK_PARCEL_ERROR;
684 }
685
686 int32_t result = NotifyFormsVisible(formIds, isVisible, callerToken);
687 if (!reply.WriteInt32(result)) {
688 HILOG_ERROR("%{public}s, failed to write result", __func__);
689 return ERR_APPEXECFWK_PARCEL_ERROR;
690 }
691 return result;
692 }
693
HandleNotifyFormsPrivacyProtected(MessageParcel & data,MessageParcel & reply)694 int32_t FormMgrStub::HandleNotifyFormsPrivacyProtected(MessageParcel &data, MessageParcel &reply)
695 {
696 HILOG_DEBUG("%{public}s called.", __func__);
697 std::vector<int64_t> formIds;
698 if (!data.ReadInt64Vector(&formIds)) {
699 HILOG_ERROR("%{public}s, failed to ReadInt64Vector", __func__);
700 return ERR_APPEXECFWK_PARCEL_ERROR;
701 }
702 bool isProtected = false;
703 if (!data.ReadBool(isProtected)) {
704 HILOG_ERROR("%{public}s, failed to ReadBool", __func__);
705 return ERR_APPEXECFWK_PARCEL_ERROR;
706 }
707 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
708 if (callerToken == nullptr) {
709 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
710 return ERR_APPEXECFWK_PARCEL_ERROR;
711 }
712
713 int32_t result = NotifyFormsPrivacyProtected(formIds, isProtected, callerToken);
714 if (!reply.WriteInt32(result)) {
715 HILOG_ERROR("%{public}s, failed to write result", __func__);
716 return ERR_APPEXECFWK_PARCEL_ERROR;
717 }
718 return result;
719 }
720
721 /**
722 * @brief Handle NotifyFormsEnableUpdate message.
723 * @param data input param.
724 * @param reply output param.
725 * @return Returns ERR_OK on success, others on failure.
726 */
HandleNotifyFormsEnableUpdate(MessageParcel & data,MessageParcel & reply)727 int32_t FormMgrStub::HandleNotifyFormsEnableUpdate(MessageParcel &data, MessageParcel &reply)
728 {
729 HILOG_INFO("%{public}s called.", __func__);
730 std::vector<int64_t> formIds;
731 if (!data.ReadInt64Vector(&formIds)) {
732 HILOG_ERROR("%{public}s, failed to ReadInt64Vector", __func__);
733 return ERR_APPEXECFWK_PARCEL_ERROR;
734 }
735 bool isEnableUpdate = false;
736 if (!data.ReadBool(isEnableUpdate)) {
737 HILOG_ERROR("%{public}s, failed to ReadBool", __func__);
738 return ERR_APPEXECFWK_PARCEL_ERROR;
739 }
740 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
741 if (callerToken == nullptr) {
742 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
743 return ERR_APPEXECFWK_PARCEL_ERROR;
744 }
745
746 int32_t result = NotifyFormsEnableUpdate(formIds, isEnableUpdate, callerToken);
747 if (!reply.WriteInt32(result)) {
748 HILOG_ERROR("%{public}s, failed to write result", __func__);
749 return ERR_APPEXECFWK_PARCEL_ERROR;
750 }
751 return result;
752 }
753
754 /**
755 * @brief Handle GetAllFormsInfo message.
756 * @param data input param.
757 * @param reply output param.
758 * @return Returns ERR_OK on success, others on failure.
759 */
HandleGetAllFormsInfo(MessageParcel & data,MessageParcel & reply)760 int32_t FormMgrStub::HandleGetAllFormsInfo(MessageParcel &data, MessageParcel &reply)
761 {
762 HILOG_INFO("%{public}s called.", __func__);
763 std::vector<FormInfo> infos;
764 int32_t result = GetAllFormsInfo(infos);
765 reply.WriteInt32(result);
766 if (result == ERR_OK) {
767 if (!WriteParcelableVector(infos, reply)) {
768 HILOG_ERROR("write failed");
769 return ERR_APPEXECFWK_PARCEL_ERROR;
770 }
771 }
772 return result;
773 }
774
775 /**
776 * @brief Handle GetFormsInfoByApp message.
777 * @param data input param.
778 * @param reply output param.
779 * @return Returns ERR_OK on success, others on failure.
780 */
HandleGetFormsInfoByApp(MessageParcel & data,MessageParcel & reply)781 int32_t FormMgrStub::HandleGetFormsInfoByApp(MessageParcel &data, MessageParcel &reply)
782 {
783 HILOG_INFO("%{public}s called.", __func__);
784 std::string bundleName = data.ReadString();
785 std::vector<FormInfo> infos;
786 int32_t result = GetFormsInfoByApp(bundleName, infos);
787 reply.WriteInt32(result);
788 if (result == ERR_OK) {
789 if (!WriteParcelableVector(infos, reply)) {
790 HILOG_ERROR("write failed");
791 return ERR_APPEXECFWK_PARCEL_ERROR;
792 }
793 }
794 return result;
795 }
796
797 /**
798 * @brief Handle GetFormsInfoByModule message.
799 * @param data input param.
800 * @param reply output param.
801 * @return Returns ERR_OK on success, others on failure.
802 */
HandleGetFormsInfoByModule(MessageParcel & data,MessageParcel & reply)803 int32_t FormMgrStub::HandleGetFormsInfoByModule(MessageParcel &data, MessageParcel &reply)
804 {
805 HILOG_INFO("%{public}s called.", __func__);
806 std::string bundleName = data.ReadString();
807 std::string moduleName = data.ReadString();
808 std::vector<FormInfo> infos;
809 int32_t result = GetFormsInfoByModule(bundleName, moduleName, infos);
810 reply.WriteInt32(result);
811 if (result == ERR_OK) {
812 if (!WriteParcelableVector(infos, reply)) {
813 HILOG_ERROR("write failed");
814 return ERR_APPEXECFWK_PARCEL_ERROR;
815 }
816 }
817 return result;
818 }
819
HandleGetFormsInfo(MessageParcel & data,MessageParcel & reply)820 int32_t FormMgrStub::HandleGetFormsInfo(MessageParcel &data, MessageParcel &reply)
821 {
822 HILOG_INFO("%{public}s called.", __func__);
823 // read filter from data.
824 std::unique_ptr<FormInfoFilter> filter(data.ReadParcelable<FormInfoFilter>());
825 if (filter == nullptr) {
826 HILOG_ERROR("%{public}s, failed to get filter.", __func__);
827 return ERR_APPEXECFWK_PARCEL_ERROR;
828 }
829 // write result of calling FMS into reply.
830 std::vector<FormInfo> infos;
831 // call FormMgrService to get formInfos into infos.
832 int32_t result = GetFormsInfo(*filter, infos);
833 reply.WriteBool(result);
834 if (result == ERR_OK) {
835 // write fetched formInfos into reply.
836 if (!WriteParcelableVector(infos, reply)) {
837 HILOG_ERROR("write failed");
838 return ERR_APPEXECFWK_PARCEL_ERROR;
839 }
840 }
841 return result;
842 }
843
HandleShareForm(MessageParcel & data,MessageParcel & reply)844 int32_t FormMgrStub::HandleShareForm(MessageParcel &data, MessageParcel &reply)
845 {
846 HILOG_DEBUG("%{public}s called.", __func__);
847 int64_t formId = data.ReadInt64();
848 std::string deviceId = data.ReadString();
849 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
850 if (callerToken == nullptr) {
851 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
852 return ERR_APPEXECFWK_PARCEL_ERROR;
853 }
854 int64_t requestCode = data.ReadInt64();
855
856 auto result = ShareForm(formId, deviceId, callerToken, requestCode);
857 reply.WriteInt32(result);
858 return result;
859 }
860
HandleAcquireFormData(MessageParcel & data,MessageParcel & reply)861 int32_t FormMgrStub::HandleAcquireFormData(MessageParcel &data, MessageParcel &reply)
862 {
863 HILOG_INFO("called.");
864 int64_t formId = data.ReadInt64();
865 int64_t requestCode = data.ReadInt64();
866 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
867 if (callerToken == nullptr) {
868 HILOG_ERROR("failed to get remote object.");
869 return ERR_APPEXECFWK_PARCEL_ERROR;
870 }
871 // write result of calling FMS into reply.
872 AAFwk::WantParams customizeData;
873 // call FormMgrService to get formData into data.
874 int32_t result = AcquireFormData(formId, requestCode, callerToken, customizeData);
875 reply.WriteInt32(result);
876 reply.WriteParcelable(&customizeData);
877 return result;
878 }
879
HandleRecvFormShareInfoFromRemote(MessageParcel & data,MessageParcel & reply)880 int32_t FormMgrStub::HandleRecvFormShareInfoFromRemote(MessageParcel &data, MessageParcel &reply)
881 {
882 HILOG_DEBUG("%{public}s called.", __func__);
883 std::unique_ptr<FormShareInfo> info(data.ReadParcelable<FormShareInfo>());
884 if (!info) {
885 HILOG_ERROR("failed to ReadParcelable<FormShareInfo>");
886 return ERR_APPEXECFWK_PARCEL_ERROR;
887 }
888 auto result = RecvFormShareInfoFromRemote(*info);
889 reply.WriteInt32(result);
890 return result;
891 }
892
HandleIsRequestPublishFormSupported(MessageParcel & data,MessageParcel & reply)893 int32_t FormMgrStub::HandleIsRequestPublishFormSupported(MessageParcel &data, MessageParcel &reply)
894 {
895 HILOG_INFO("%{public}s called.", __func__);
896 bool result = IsRequestPublishFormSupported();
897 if (!reply.WriteBool(result)) {
898 HILOG_ERROR("%{public}s, failed to write action", __func__);
899 return ERR_APPEXECFWK_PARCEL_ERROR;
900 }
901 return ERR_OK;
902 }
903
HandleStartAbility(MessageParcel & data,MessageParcel & reply)904 int32_t FormMgrStub::HandleStartAbility(MessageParcel &data, MessageParcel &reply)
905 {
906 HILOG_INFO("%{public}s called.", __func__);
907 // retrieve want
908 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
909 if (want == nullptr) {
910 HILOG_ERROR("%{public}s, failed to get want.", __func__);
911 return ERR_APPEXECFWK_PARCEL_ERROR;
912 }
913 // retrieve callerToken
914 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
915 if (callerToken == nullptr) {
916 HILOG_ERROR("%{public}s, failed to get remote object.", __func__);
917 return ERR_APPEXECFWK_PARCEL_ERROR;
918 }
919 int32_t result = StartAbility(*want, callerToken);
920 if (!reply.WriteInt32(result)) {
921 HILOG_ERROR("%{public}s, failed to write result", __func__);
922 return ERR_APPEXECFWK_PARCEL_ERROR;
923 }
924 return result;
925 }
926
HandleCheckFMSReady(MessageParcel & data,MessageParcel & reply)927 int32_t FormMgrStub::HandleCheckFMSReady(MessageParcel &data, MessageParcel &reply)
928 {
929 HILOG_INFO("%{public}s called.", __func__);
930 bool result = CheckFMSReady();
931 if (!reply.WriteBool(result)) {
932 HILOG_ERROR("%{public}s, failed to write action", __func__);
933 return ERR_APPEXECFWK_PARCEL_ERROR;
934 }
935 return ERR_OK;
936 }
937
HandleRegisterFormAddObserverByBundle(MessageParcel & data,MessageParcel & reply)938 int32_t FormMgrStub::HandleRegisterFormAddObserverByBundle(MessageParcel &data, MessageParcel &reply)
939 {
940 HILOG_DEBUG("called.");
941
942 std::string bundleName = data.ReadString();
943 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
944 if (callerToken == nullptr) {
945 HILOG_ERROR("failed to get remote object.");
946 return ERR_APPEXECFWK_PARCEL_ERROR;
947 }
948 auto result = RegisterFormAddObserverByBundle(bundleName, callerToken);
949 reply.WriteInt32(result);
950 return result;
951 }
952
HandleRegisterFormRemoveObserverByBundle(MessageParcel & data,MessageParcel & reply)953 int32_t FormMgrStub::HandleRegisterFormRemoveObserverByBundle(MessageParcel &data, MessageParcel &reply)
954 {
955 HILOG_DEBUG("called.");
956
957 std::string bundleName = data.ReadString();
958 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
959 if (callerToken == nullptr) {
960 HILOG_ERROR("failed to get remote object.");
961 return ERR_APPEXECFWK_PARCEL_ERROR;
962 }
963 auto result = RegisterFormRemoveObserverByBundle(bundleName, callerToken);
964 reply.WriteInt32(result);
965 return result;
966 }
967
HandleGetFormsCount(MessageParcel & data,MessageParcel & reply)968 int32_t FormMgrStub::HandleGetFormsCount(MessageParcel &data, MessageParcel &reply)
969 {
970 HILOG_INFO("%{public}s called.", __func__);
971 bool isTempFormFlag = false;
972 if (!data.ReadBool(isTempFormFlag)) {
973 HILOG_ERROR("%{public}s, failed to read temp flag", __func__);
974 return ERR_APPEXECFWK_PARCEL_ERROR;
975 }
976
977 int32_t formCount = 0;
978 int32_t result = GetFormsCount(isTempFormFlag, formCount);
979 if (!reply.WriteInt32(result)) {
980 HILOG_ERROR("write result failed");
981 return ERR_APPEXECFWK_PARCEL_ERROR;
982 }
983 if (!reply.WriteInt32(formCount)) {
984 HILOG_ERROR("write formCount failed");
985 return ERR_APPEXECFWK_PARCEL_ERROR;
986 }
987 return result;
988 }
989
HandleGetFormInstancesByFilter(MessageParcel & data,MessageParcel & reply)990 int32_t FormMgrStub::HandleGetFormInstancesByFilter(MessageParcel &data, MessageParcel &reply)
991 {
992 HILOG_DEBUG("called.");
993 std::unique_ptr<FormInstancesFilter> filter(data.ReadParcelable<FormInstancesFilter>());
994 if (filter == nullptr) {
995 HILOG_ERROR("failed to get filter.");
996 return ERR_APPEXECFWK_PARCEL_ERROR;
997 }
998 std::vector<FormInstance> infos;
999 auto result = GetFormInstancesByFilter(*filter, infos);
1000 HILOG_DEBUG("info size = %{public}zu", infos.size());
1001 reply.WriteInt32(result);
1002 if (result == ERR_OK) {
1003 HILOG_INFO("result i true.");
1004 if (!WriteParcelableVector(infos, reply)) {
1005 HILOG_ERROR("write failed");
1006 return ERR_APPEXECFWK_PARCEL_ERROR;
1007 }
1008 }
1009 return ERR_OK;
1010 }
1011
HandleGetFormInstanceById(MessageParcel & data,MessageParcel & reply)1012 int32_t FormMgrStub::HandleGetFormInstanceById(MessageParcel &data, MessageParcel &reply)
1013 {
1014 HILOG_DEBUG("called.");
1015 int64_t formId = data.ReadInt64();
1016 bool isIncludeUnused = data.ReadBool();
1017 FormInstance info;
1018 auto result = GetFormInstanceById(formId, isIncludeUnused, info);
1019 reply.WriteInt32(result);
1020 if (result == ERR_OK) {
1021 if (!reply.WriteParcelable(&info)) {
1022 HILOG_ERROR("write failed");
1023 return ERR_APPEXECFWK_PARCEL_ERROR;
1024 }
1025 }
1026 return ERR_OK;
1027 }
1028
HandleGetHostFormsCount(MessageParcel & data,MessageParcel & reply)1029 int32_t FormMgrStub::HandleGetHostFormsCount(MessageParcel &data, MessageParcel &reply)
1030 {
1031 HILOG_INFO("%{public}s called.", __func__);
1032 std::string bundleName = data.ReadString();
1033
1034 int32_t formCount = 0;
1035 int32_t result = GetHostFormsCount(bundleName, formCount);
1036 if (!reply.WriteInt32(result)) {
1037 HILOG_ERROR("write result failed");
1038 return ERR_APPEXECFWK_PARCEL_ERROR;
1039 }
1040 if (!reply.WriteInt32(formCount)) {
1041 HILOG_ERROR("write formCount failed");
1042 return ERR_APPEXECFWK_PARCEL_ERROR;
1043 }
1044 return result;
1045 }
1046
HandleGetRunningFormInfos(MessageParcel & data,MessageParcel & reply)1047 ErrCode FormMgrStub::HandleGetRunningFormInfos(MessageParcel &data, MessageParcel &reply)
1048 {
1049 HILOG_DEBUG("called.");
1050 std::vector<RunningFormInfo> runningFormInfos;
1051 ErrCode result = GetRunningFormInfos(runningFormInfos);
1052 reply.WriteInt32(result);
1053 if (result == ERR_OK) {
1054 if (!WriteParcelableVector(runningFormInfos, reply)) {
1055 HILOG_ERROR("write failed");
1056 return ERR_APPEXECFWK_PARCEL_ERROR;
1057 }
1058 }
1059 return result;
1060 }
1061
HandleGetRunningFormInfosByBundleName(MessageParcel & data,MessageParcel & reply)1062 ErrCode FormMgrStub::HandleGetRunningFormInfosByBundleName(MessageParcel &data, MessageParcel &reply)
1063 {
1064 HILOG_DEBUG("called.");
1065 std::string bundleName = data.ReadString();
1066 std::vector<RunningFormInfo> runningFormInfos;
1067 ErrCode result = GetRunningFormInfosByBundleName(bundleName, runningFormInfos);
1068 reply.WriteInt32(result);
1069 if (result == ERR_OK) {
1070 if (!WriteParcelableVector(runningFormInfos, reply)) {
1071 HILOG_ERROR("write failed");
1072 return ERR_APPEXECFWK_PARCEL_ERROR;
1073 }
1074 }
1075 return result;
1076 }
1077
HandleRegisterPublishFormInterceptor(MessageParcel & data,MessageParcel & reply)1078 int32_t FormMgrStub::HandleRegisterPublishFormInterceptor(MessageParcel &data, MessageParcel &reply)
1079 {
1080 HILOG_DEBUG("called.");
1081 sptr<IRemoteObject> interceptor = data.ReadRemoteObject();
1082 if (interceptor == nullptr) {
1083 HILOG_ERROR("failed to get remote object.");
1084 return ERR_APPEXECFWK_PARCEL_ERROR;
1085 }
1086 int32_t result = RegisterPublishFormInterceptor(interceptor);
1087 if (!reply.WriteInt32(result)) {
1088 HILOG_ERROR("failed to write result");
1089 return ERR_APPEXECFWK_PARCEL_ERROR;
1090 }
1091 return result;
1092 }
1093
HandleUnregisterPublishFormInterceptor(MessageParcel & data,MessageParcel & reply)1094 int32_t FormMgrStub::HandleUnregisterPublishFormInterceptor(MessageParcel &data, MessageParcel &reply)
1095 {
1096 HILOG_DEBUG("called.");
1097 sptr<IRemoteObject> interceptor = data.ReadRemoteObject();
1098 if (interceptor == nullptr) {
1099 HILOG_ERROR("failed to get remote object.");
1100 return ERR_APPEXECFWK_PARCEL_ERROR;
1101 }
1102 int32_t result = UnregisterPublishFormInterceptor(interceptor);
1103 if (!reply.WriteInt32(result)) {
1104 HILOG_ERROR("failed to write result");
1105 return ERR_APPEXECFWK_PARCEL_ERROR;
1106 }
1107 return result;
1108 }
1109
1110 /**
1111 * @brief Write a parcelabe vector objects to the proxy node.
1112 * @param parcelableVector Indicates the objects to be write.
1113 * @param reply Indicates the reply to be sent;
1114 * @return Returns true if objects send successfully; returns false otherwise.
1115 */
1116 template<typename T>
WriteParcelableVector(std::vector<T> & parcelableVector,Parcel & reply)1117 bool FormMgrStub::WriteParcelableVector(std::vector<T> &parcelableVector, Parcel &reply)
1118 {
1119 if (!reply.WriteInt32(parcelableVector.size())) {
1120 HILOG_ERROR("write ParcelableVector failed");
1121 return false;
1122 }
1123
1124 for (auto &parcelable: parcelableVector) {
1125 if (!reply.WriteParcelable(&parcelable)) {
1126 HILOG_ERROR("write ParcelableVector failed");
1127 return false;
1128 }
1129 }
1130 return true;
1131 }
1132
HandleRegisterAddObserver(MessageParcel & data,MessageParcel & reply)1133 ErrCode FormMgrStub::HandleRegisterAddObserver(MessageParcel &data, MessageParcel &reply)
1134 {
1135 HILOG_DEBUG("called.");
1136 std::string bundleName = data.ReadString();
1137 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1138 if (callerToken == nullptr) {
1139 HILOG_ERROR("failed to get remote object.");
1140 return ERR_APPEXECFWK_PARCEL_ERROR;
1141 }
1142 auto result = RegisterAddObserver(bundleName, callerToken);
1143 reply.WriteInt32(result);
1144 return result;
1145 }
1146
HandleRegisterRemoveObserver(MessageParcel & data,MessageParcel & reply)1147 ErrCode FormMgrStub::HandleRegisterRemoveObserver(MessageParcel &data, MessageParcel &reply)
1148 {
1149 HILOG_DEBUG("called.");
1150 std::string bundleName = data.ReadString();
1151 sptr<IRemoteObject> callerToken = data.ReadRemoteObject();
1152 if (callerToken == nullptr) {
1153 HILOG_ERROR("failed to get remote object.");
1154 return ERR_APPEXECFWK_PARCEL_ERROR;
1155 }
1156 auto result = RegisterRemoveObserver(bundleName, callerToken);
1157 reply.WriteInt32(result);
1158 return result;
1159 }
1160
HandleUpdateProxyForm(MessageParcel & data,MessageParcel & reply)1161 ErrCode FormMgrStub::HandleUpdateProxyForm(MessageParcel &data, MessageParcel &reply)
1162 {
1163 int64_t formId = data.ReadInt64();
1164 std::unique_ptr<FormProviderData> formProviderData(data.ReadParcelable<FormProviderData>());
1165 if (formProviderData == nullptr) {
1166 HILOG_ERROR("%{public}s, failed to get formProviderData.", __func__);
1167 return ERR_APPEXECFWK_PARCEL_ERROR;
1168 }
1169 std::vector<FormDataProxy> formDataProxies;
1170 if (!ReadFormDataProxies(data, formDataProxies)) {
1171 HILOG_ERROR("failed to get formDataProxies.");
1172 return ERR_APPEXECFWK_PARCEL_ERROR;
1173 }
1174 int32_t result = UpdateProxyForm(formId, *formProviderData, formDataProxies);
1175 reply.WriteInt32(result);
1176 return result;
1177 }
1178
HandleRequestPublishProxyForm(MessageParcel & data,MessageParcel & reply)1179 ErrCode FormMgrStub::HandleRequestPublishProxyForm(MessageParcel &data, MessageParcel &reply)
1180 {
1181 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
1182 if (want == nullptr) {
1183 HILOG_ERROR("%{public}s, failed to get want.", __func__);
1184 return ERR_APPEXECFWK_PARCEL_ERROR;
1185 }
1186
1187 bool withFormBindingData = data.ReadBool();
1188 std::unique_ptr<FormProviderData> formProviderData = nullptr;
1189 if (withFormBindingData) {
1190 formProviderData.reset(data.ReadParcelable<FormProviderData>());
1191 if (formProviderData == nullptr) {
1192 HILOG_ERROR("%{public}s, failed to get formProviderData.", __func__);
1193 return ERR_APPEXECFWK_PARCEL_ERROR;
1194 }
1195 }
1196 std::vector<FormDataProxy> formDataProxies;
1197 if (!ReadFormDataProxies(data, formDataProxies)) {
1198 HILOG_ERROR("failed to get formDataProxies.");
1199 return ERR_APPEXECFWK_PARCEL_ERROR;
1200 }
1201 int64_t formId = 0;
1202 ErrCode result = RequestPublishProxyForm(*want, withFormBindingData, formProviderData, formId, formDataProxies);
1203 reply.WriteInt32(result);
1204 if (result == ERR_OK) {
1205 reply.WriteInt64(formId);
1206 }
1207 return result;
1208 }
ReadFormDataProxies(MessageParcel & data,std::vector<FormDataProxy> & formDataProxies)1209 bool FormMgrStub::ReadFormDataProxies(MessageParcel &data, std::vector<FormDataProxy> &formDataProxies)
1210 {
1211 auto number = data.ReadInt32();
1212 HILOG_DEBUG("proxies number: %{public}d.", number);
1213 if (number < 0 || number > INT16_MAX) {
1214 HILOG_ERROR("proxies number over limit: %{public}d.", number);
1215 return false;
1216 }
1217
1218 for (auto i = 0; i < number; i++) {
1219 FormDataProxy formDataProxy("", "");
1220 formDataProxy.key = Str16ToStr8(data.ReadString16());
1221 formDataProxy.subscribeId = Str16ToStr8(data.ReadString16());
1222 formDataProxies.push_back(formDataProxy);
1223 }
1224 return true;
1225 }
1226 } // namespace AppExecFwk
1227 } // namespace OHOS
1228