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_service.h"
17
18 #include <chrono>
19 #include <ctime>
20 #include <iomanip>
21 #include <sstream>
22
23 #include "accesstoken_kit.h"
24 #include "bundle_common_event.h"
25 #include "common_event_manager.h"
26 #include "common_event_support.h"
27 #include "fms_log_wrapper.h"
28 #include "form_ams_helper.h"
29 #include "form_bms_helper.h"
30 #include "form_cache_mgr.h"
31 #include "form_constants.h"
32 #include "form_data_mgr.h"
33 #include "form_data_proxy_mgr.h"
34 #include "form_db_cache.h"
35 #include "form_event_handler.h"
36 #include "form_event_report.h"
37 #include "form_info_mgr.h"
38 #include "form_mgr_adapter.h"
39 #include "form_mgr_errors.h"
40 #include "form_serial_queue.h"
41 #include "form_share_mgr.h"
42 #include "form_task_mgr.h"
43 #include "form_timer_mgr.h"
44 #include "form_trust_mgr.h"
45 #include "form_util.h"
46 #include "form_xml_parser.h"
47 #include "in_process_call_wrapper.h"
48 #include "ipc_skeleton.h"
49 #include "iservice_registry.h"
50 #include "mem_status_listener.h"
51 #include "os_account_manager.h"
52 #include "permission_constants.h"
53 #include "permission_verification.h"
54 #include "system_ability_definition.h"
55 #include "tokenid_kit.h"
56 #include "hisysevent.h"
57 #include "xcollie/watchdog.h"
58 #include "mem_mgr_client.h"
59
60 namespace OHOS {
61 namespace AppExecFwk {
62 namespace {
63 const int32_t MAIN_USER_ID = 100;
64 constexpr int32_t GET_CALLING_UID_TRANSFORM_DIVISOR = 200000;
65 constexpr int MILLISECOND_WIDTH = 3;
66 constexpr char MILLISECOND_FILLCHAR = '0';
67 }
68 using namespace std::chrono;
69
70 const bool REGISTER_RESULT =
71 SystemAbility::MakeAndRegisterAbility(DelayedSingleton<FormMgrService>::GetInstance().get());
72
73 const std::string NAME_FORM_MGR_SERVICE = "FormMgrService";
74
75 const std::string FORM_MGR_SERVICE_QUEUE = "FormMgrServiceQueue";
76
77 constexpr int32_t FORM_DUMP_ARGC_MAX = 2;
78
79 const std::string FORM_DUMP_HELP = "options list:\n"
80 " -h, --help list available commands\n"
81 " -b, --bundle-form-info query all form infos from bundle, Un-added form info will also be dumped\n"
82 " -s, --storage query form storage info\n"
83 " -t, --temp query temporary form info\n"
84 " -n <bundle-name> query form info by a bundle name\n"
85 " -i <form-id> query form info by a form ID\n";
86
87 const std::map<std::string, FormMgrService::DumpKey> FormMgrService::dumpKeyMap_ = {
88 {"-h", FormMgrService::DumpKey::KEY_DUMP_HELP},
89 {"--help", FormMgrService::DumpKey::KEY_DUMP_HELP},
90 {"-b", FormMgrService::DumpKey::KEY_DUMP_STATIC}, // *****
91 {"--bundle-form-info", FormMgrService::DumpKey::KEY_DUMP_STATIC},
92 {"-s", FormMgrService::DumpKey::KEY_DUMP_STORAGE},
93 {"--storage", FormMgrService::DumpKey::KEY_DUMP_STORAGE},
94 {"-t", FormMgrService::DumpKey::KEY_DUMP_TEMPORARY},
95 {"--temp", FormMgrService::DumpKey::KEY_DUMP_TEMPORARY},
96 {"-n", FormMgrService::DumpKey::KEY_DUMP_BY_BUNDLE_NAME},
97 {"-i", FormMgrService::DumpKey::KEY_DUMP_BY_FORM_ID},
98 };
99
FormMgrService()100 FormMgrService::FormMgrService()
101 : SystemAbility(FORM_MGR_SERVICE_ID, true),
102 state_(ServiceRunningState::STATE_NOT_START),
103 serialQueue_(nullptr)
104 {
105 HILOG_INFO("called");
106 DumpInit();
107 }
108
~FormMgrService()109 FormMgrService::~FormMgrService()
110 {
111 FMS_CALL_INFO_ENTER;
112 if (formSysEventReceiver_ != nullptr) {
113 EventFwk::CommonEventManager::UnSubscribeCommonEvent(formSysEventReceiver_);
114 formSysEventReceiver_ = nullptr;
115 FormBmsHelper::GetInstance().UnregisterBundleEventCallback();
116 }
117 if (memStatusListener_ != nullptr) {
118 Memory::MemMgrClient::GetInstance().UnsubscribeAppState(*memStatusListener_);
119 }
120 }
121
IsReady() const122 bool FormMgrService::IsReady() const
123 {
124 if (state_ != ServiceRunningState::STATE_RUNNING) {
125 return false;
126 }
127
128 int32_t userId = FormUtil::GetCurrentAccountId();
129 if (userId == Constants::ANY_USERID) {
130 HILOG_ERROR("%{public}s fail, account is empty", __func__);
131 return false;
132 }
133 return FormInfoMgr::GetInstance().HasReloadedFormInfos();
134 }
135
136 /**
137 * @brief Check form manager service ready.
138 * @return Return true if form manager service Ready; return false otherwise.
139 */
140
CheckFMSReady()141 bool FormMgrService::CheckFMSReady()
142 {
143 return IsReady();
144 }
145
146 /**
147 * @brief Add form with want, send want to form manager service.
148 * @param formId The Id of the forms to add.
149 * @param want The want of the form to add.
150 * @param callerToken Caller ability token.
151 * @param formInfo Form info.
152 * @return Returns ERR_OK on success, others on failure.
153 */
AddForm(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken,FormJsInfo & formInfo)154 int FormMgrService::AddForm(const int64_t formId, const Want &want,
155 const sptr<IRemoteObject> &callerToken, FormJsInfo &formInfo)
156 {
157 HILOG_INFO("FMS AddForm called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
158 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
159 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
160
161 ErrCode ret = CheckFormPermission();
162 FormEventInfo eventInfo;
163 eventInfo.formId = formId;
164 eventInfo.bundleName = want.GetElement().GetBundleName();
165 eventInfo.moduleName = want.GetStringParam(AppExecFwk::Constants::PARAM_MODULE_NAME_KEY);
166 eventInfo.abilityName = want.GetElement().GetAbilityName();
167 sptr iBundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
168 if (iBundleMgr != nullptr) {
169 int uid = IPCSkeleton::GetCallingUid();
170 int32_t result = IN_PROCESS_CALL(iBundleMgr->GetNameForUid(uid, eventInfo.hostBundleName));
171 if (result != ERR_OK || eventInfo.hostBundleName.empty()) {
172 HILOG_ERROR("%{public}s fail, cannot get host bundle name by uid:%{public}d", __func__, uid);
173 }
174 } else {
175 HILOG_ERROR("%{public}s, failed to get IBundleMgr.", __func__);
176 }
177 FormEventReport::SendFormEvent(FormEventName::ADD_FORM, HiSysEventType::BEHAVIOR, eventInfo);
178 if (ret != ERR_OK) {
179 HILOG_ERROR("%{public}s fail, add form permission denied", __func__);
180 return ret;
181 }
182 return FormMgrAdapter::GetInstance().AddForm(formId, want, callerToken, formInfo);
183 }
184
185 /**
186 * @brief Delete forms with formIds, send formIds to form manager service.
187 * @param formId The Id of the forms to delete.
188 * @param callerToken Caller ability token.
189 * @return Returns ERR_OK on success, others on failure.
190 */
DeleteForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)191 int FormMgrService::DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
192 {
193 HILOG_INFO("FMS DeleteForm called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
194 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
195 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
196
197 ErrCode ret = CheckFormPermission();
198 if (ret != ERR_OK) {
199 HILOG_ERROR("%{public}s fail, delete form permission denied", __func__);
200 return ret;
201 }
202 FormEventInfo eventInfo;
203 eventInfo.formId = formId;
204 std::vector<FormHostRecord> formHostRecords;
205 FormDataMgr::GetInstance().GetFormHostRecord(formId, formHostRecords);
206 if (formHostRecords.size() != 0) {
207 eventInfo.hostBundleName = formHostRecords.begin()->GetHostBundleName();
208 }
209 FormEventReport::SendSecondFormEvent(FormEventName::DELETE_FORM, HiSysEventType::BEHAVIOR, eventInfo);
210
211 return FormMgrAdapter::GetInstance().DeleteForm(formId, callerToken);
212 }
213
214 /**
215 * @brief Stop rendering form.
216 * @param formId The Id of the forms to delete.
217 * @param compId The compId of the forms to delete.
218 * @return Returns ERR_OK on success, others on failure.
219 */
StopRenderingForm(const int64_t formId,const std::string & compId)220 int FormMgrService::StopRenderingForm(const int64_t formId, const std::string &compId)
221 {
222 ErrCode ret = CheckFormPermission();
223 if (ret != ERR_OK) {
224 HILOG_ERROR("%{public}s fail, delete form permission denied", __func__);
225 return ret;
226 }
227
228 ret = FormDataMgr::GetInstance().CheckInvalidForm(formId);
229 if (ret != ERR_OK) {
230 HILOG_ERROR("fail, the form id is invalid or not under the current active user.");
231 return ret;
232 }
233 return FormMgrAdapter::GetInstance().StopRenderingForm(formId, compId);
234 }
235
236 /**
237 * @brief Release forms with formIds, send formIds to form manager service.
238 * @param formId The Id of the forms to release.
239 * @param callerToken Caller ability token.
240 * @param delCache Delete Cache or not.
241 * @return Returns ERR_OK on success, others on failure.
242 */
ReleaseForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const bool delCache)243 int FormMgrService::ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache)
244 {
245 HILOG_INFO("FMS ReleaseForm called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
246 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
247 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
248
249 ErrCode ret = CheckFormPermission();
250 if (ret != ERR_OK) {
251 HILOG_ERROR("%{public}s fail, release form permission denied", __func__);
252 return ret;
253 }
254 FormEventInfo eventInfo;
255 eventInfo.formId = formId;
256 FormEventReport::SendSecondFormEvent(FormEventName::RELEASE_FORM, HiSysEventType::BEHAVIOR, eventInfo);
257
258 return FormMgrAdapter::GetInstance().ReleaseForm(formId, callerToken, delCache);
259 }
260
261 /**
262 * @brief Update form with formId, send formId to form manager service.
263 * @param formId The Id of the form to update.
264 * @param formBindingData Form binding data.
265 * @return Returns ERR_OK on success, others on failure.
266 */
UpdateForm(const int64_t formId,const FormProviderData & formBindingData)267 int FormMgrService::UpdateForm(const int64_t formId, const FormProviderData &formBindingData)
268 {
269 HILOG_DEBUG("called.");
270 auto callingUid = IPCSkeleton::GetCallingUid();
271 return FormMgrAdapter::GetInstance().UpdateForm(formId, callingUid, formBindingData);
272 }
273
274 /**
275 * @brief Request form with formId and want, send formId and want to form manager service.
276 * @param formId The Id of the form to update.
277 * @param callerToken Caller ability token.
278 * @param want The want of the form to add.
279 * @return Returns ERR_OK on success, others on failure.
280 */
RequestForm(const int64_t formId,const sptr<IRemoteObject> & callerToken,const Want & want)281 int FormMgrService::RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want)
282 {
283 HILOG_INFO("FMS RequestForm called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
284 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
285 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
286
287 ErrCode ret = CheckFormPermission();
288 if (ret != ERR_OK) {
289 HILOG_ERROR("%{public}s fail, request form permission denied", __func__);
290 return ret;
291 }
292 FormEventInfo eventInfo;
293 eventInfo.formId = formId;
294 eventInfo.bundleName = want.GetElement().GetBundleName();
295 eventInfo.moduleName = want.GetStringParam(AppExecFwk::Constants::PARAM_MODULE_NAME_KEY);
296 eventInfo.abilityName = want.GetElement().GetAbilityName();
297 FormEventReport::SendSecondFormEvent(FormEventName::REQUEST_FORM, HiSysEventType::BEHAVIOR, eventInfo);
298
299 return FormMgrAdapter::GetInstance().RequestForm(formId, callerToken, want);
300 }
301
302 /**
303 * @brief set next refresh time.
304 * @param formId The id of the form.
305 * @param nextTime next refresh time.
306 * @return Returns ERR_OK on success, others on failure.
307 */
SetNextRefreshTime(const int64_t formId,const int64_t nextTime)308 int FormMgrService::SetNextRefreshTime(const int64_t formId, const int64_t nextTime)
309 {
310 HILOG_INFO("%{public}s called.", __func__);
311 FormEventInfo eventInfo;
312 eventInfo.formId = formId;
313 FormEventReport::SendSecondFormEvent(
314 FormEventName::SET_NEXT_REFRESH_TIME_FORM, HiSysEventType::BEHAVIOR, eventInfo);
315
316 return FormMgrAdapter::GetInstance().SetNextRefreshTime(formId, nextTime);
317 }
318
ReleaseRenderer(int64_t formId,const std::string & compId)319 int FormMgrService::ReleaseRenderer(int64_t formId, const std::string &compId)
320 {
321 HILOG_INFO("%{public}s called.", __func__);
322 ErrCode ret = CheckFormPermission();
323 if (ret != ERR_OK) {
324 HILOG_ERROR("%{public}s fail, request form permission denied", __func__);
325 return ret;
326 }
327 return FormMgrAdapter::GetInstance().ReleaseRenderer(formId, compId);
328 }
329
RequestPublishForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId)330 ErrCode FormMgrService::RequestPublishForm(Want &want, bool withFormBindingData,
331 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId)
332 {
333 HILOG_INFO("FMS RequestPublishForm called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
334 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
335 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
336 bool isFormAgent = want.GetBoolParam(Constants::IS_FORM_AGENT, false);
337 HILOG_INFO("RequestPublishForm called, isFormAgent: %{public}d", isFormAgent);
338 if (isFormAgent) {
339 ErrCode ret = CheckFormPermission(AppExecFwk::Constants::PERMISSION_AGENT_REQUIRE_FORM);
340 if (ret != ERR_OK) {
341 HILOG_ERROR("%{public}s fail, request form permission denied", __func__);
342 return ret;
343 }
344 } else {
345 if (!CheckCallerIsSystemApp()) {
346 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
347 }
348 }
349 return FormMgrAdapter::GetInstance().RequestPublishForm(want, withFormBindingData, formBindingData, formId);
350 }
351
352 /**
353 * @brief Form visible/invisible notify, send formIds to form manager service.
354 * @param formIds The Id list of the forms to notify.
355 * @param callerToken Caller ability token.
356 * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
357 * @return Returns ERR_OK on success, others on failure.
358 */
NotifyWhetherVisibleForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,const int32_t formVisibleType)359 int FormMgrService::NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds,
360 const sptr<IRemoteObject> &callerToken, const int32_t formVisibleType)
361 {
362 HILOG_DEBUG("called.");
363
364 ErrCode ret = CheckFormPermission();
365 if (ret != ERR_OK) {
366 HILOG_ERROR("%{public}s fail, event notify visible permission denied", __func__);
367 return ret;
368 }
369 return FormMgrAdapter::GetInstance().NotifyWhetherVisibleForms(formIds, callerToken, formVisibleType);
370 }
371
372 /**
373 * @brief temp form to normal form.
374 * @param formId The Id of the form.
375 * @param callerToken Caller ability token.
376 * @return Returns ERR_OK on success, others on failure.
377 */
CastTempForm(const int64_t formId,const sptr<IRemoteObject> & callerToken)378 int FormMgrService::CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken)
379 {
380 HILOG_DEBUG("called.");
381
382 ErrCode ret = CheckFormPermission();
383 if (ret != ERR_OK) {
384 HILOG_ERROR("%{public}s fail, cast temp form permission denied", __func__);
385 return ret;
386 }
387 ret = FormDataMgr::GetInstance().CheckInvalidForm(formId);
388 if (ret != ERR_OK) {
389 HILOG_ERROR("fail, the form id is invalid or not under the current active user.");
390 return ret;
391 }
392 FormEventInfo eventInfo;
393 eventInfo.formId = formId;
394 FormEventReport::SendSecondFormEvent(FormEventName::CASTTEMP_FORM, HiSysEventType::BEHAVIOR, eventInfo);
395
396 return FormMgrAdapter::GetInstance().CastTempForm(formId, callerToken);
397 }
398
399 /**
400 * @brief lifecycle update.
401 * @param formIds formIds of host client.
402 * @param callerToken Caller ability token.
403 * @param updateType update type,enable or disable.
404 * @return Returns true on success, false on failure.
405 */
LifecycleUpdate(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,bool updateType)406 int FormMgrService::LifecycleUpdate(const std::vector<int64_t> &formIds,
407 const sptr<IRemoteObject> &callerToken, bool updateType)
408 {
409 HILOG_INFO("lifecycleUpdate. %{public}d", updateType);
410
411 ErrCode ret = CheckFormPermission();
412 if (ret != ERR_OK) {
413 HILOG_ERROR("fail, delete form permission denied");
414 return ret;
415 }
416
417 if (updateType) {
418 return FormMgrAdapter::GetInstance().EnableUpdateForm(formIds, callerToken);
419 } else {
420 return FormMgrAdapter::GetInstance().DisableUpdateForm(formIds, callerToken);
421 }
422 }
423 /**
424 * @brief Dump all of form storage infos.
425 * @param formInfos All of form storage infos.
426 * @return Returns ERR_OK on success, others on failure.
427 */
DumpStorageFormInfos(std::string & formInfos)428 int FormMgrService::DumpStorageFormInfos(std::string &formInfos)
429 {
430 if (!CheckCallerIsSystemApp()) {
431 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
432 }
433 return FormMgrAdapter::GetInstance().DumpStorageFormInfos(formInfos);
434 }
435 /**
436 * @brief Dump form info by a bundle name.
437 * @param bundleName The bundle name of form provider.
438 * @param formInfos Form infos.
439 * @return Returns ERR_OK on success, others on failure.
440 */
DumpFormInfoByBundleName(const std::string & bundleName,std::string & formInfos)441 int FormMgrService::DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos)
442 {
443 if (!CheckCallerIsSystemApp()) {
444 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
445 }
446 return FormMgrAdapter::GetInstance().DumpFormInfoByBundleName(bundleName, formInfos);
447 }
448 /**
449 * @brief Dump form info by a bundle name.
450 * @param formId The id of the form.
451 * @param formInfo Form info.
452 * @return Returns ERR_OK on success, others on failure.
453 */
DumpFormInfoByFormId(const std::int64_t formId,std::string & formInfo)454 int FormMgrService::DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo)
455 {
456 if (!CheckCallerIsSystemApp()) {
457 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
458 }
459 return FormMgrAdapter::GetInstance().DumpFormInfoByFormId(formId, formInfo);
460 }
461 /**
462 * @brief Dump form timer by form id.
463 * @param formId The id of the form.
464 * @param formInfo Form info.
465 * @return Returns ERR_OK on success, others on failure.
466 */
DumpFormTimerByFormId(const std::int64_t formId,std::string & isTimingService)467 int FormMgrService::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService)
468 {
469 if (!CheckCallerIsSystemApp()) {
470 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
471 }
472 return FormMgrAdapter::GetInstance().DumpFormTimerByFormId(formId, isTimingService);
473 }
474 /**
475 * @brief Process js message event.
476 * @param formId Indicates the unique id of form.
477 * @param want information passed to supplier.
478 * @param callerToken Caller ability token.
479 * @return Returns true if execute success, false otherwise.
480 */
MessageEvent(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)481 int FormMgrService::MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken)
482 {
483 HILOG_INFO("FMS MessageEvent called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
484 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
485 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
486 ErrCode ret = CheckFormPermission();
487 if (ret != ERR_OK) {
488 HILOG_ERROR("%{public}s fail, request form permission denied", __func__);
489 return ret;
490 }
491 ret = FormDataMgr::GetInstance().CheckInvalidForm(formId);
492 if (ret != ERR_OK) {
493 HILOG_ERROR("fail, the form id is invalid or not under the current active user.");
494 return ret;
495 }
496 FormEventInfo eventInfo;
497 eventInfo.bundleName = want.GetElement().GetBundleName();
498 eventInfo.moduleName = want.GetStringParam(AppExecFwk::Constants::PARAM_MODULE_NAME_KEY);
499 eventInfo.abilityName = want.GetElement().GetAbilityName();
500 std::vector<FormHostRecord> formHostRecords;
501 FormDataMgr::GetInstance().GetFormHostRecord(formId, formHostRecords);
502 if (formHostRecords.size() != 0) {
503 eventInfo.hostBundleName = formHostRecords.begin()->GetHostBundleName();
504 }
505 FormEventReport::SendFormEvent(FormEventName::MESSAGE_EVENT_FORM, HiSysEventType::BEHAVIOR, eventInfo);
506 return FormMgrAdapter::GetInstance().MessageEvent(formId, want, callerToken);
507 }
508
509 /**
510 * @brief Process js router event.
511 * @param formId Indicates the unique id of form.
512 * @param want the want of the ability to start.
513 * @param callerToken Caller ability token.
514 * @return Returns true if execute success, false otherwise.
515 */
RouterEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)516 int FormMgrService::RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
517 {
518 HILOG_INFO("FMS RouterEvent called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
519 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
520 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
521 ErrCode ret = CheckFormPermission();
522 if (ret != ERR_OK) {
523 HILOG_ERROR("%{public}s error, request form permission denied", __func__);
524 return ret;
525 }
526 ret = FormDataMgr::GetInstance().CheckInvalidForm(formId);
527 if (ret != ERR_OK) {
528 HILOG_ERROR("error, the form id is invalid or not under the current active user.");
529 return ret;
530 }
531 FormEventInfo eventInfo;
532 eventInfo.formId = formId;
533 eventInfo.bundleName = want.GetElement().GetBundleName();
534 eventInfo.moduleName = want.GetStringParam(AppExecFwk::Constants::PARAM_MODULE_NAME_KEY);
535 eventInfo.abilityName = want.GetElement().GetAbilityName();
536 std::vector<FormHostRecord> formHostRecords;
537 FormDataMgr::GetInstance().GetFormHostRecord(formId, formHostRecords);
538 if (formHostRecords.size() != 0) {
539 eventInfo.hostBundleName = formHostRecords.begin()->GetHostBundleName();
540 }
541 FormEventReport::SendFormEvent(FormEventName::ROUTE_EVENT_FORM, HiSysEventType::BEHAVIOR, eventInfo);
542 return FormMgrAdapter::GetInstance().RouterEvent(formId, want, callerToken);
543 }
544
545 /**
546 * @brief Process Background event.
547 * @param formId Indicates the unique id of form.
548 * @param want the want of the ability to start.
549 * @param callerToken Caller ability token.
550 * @return Returns true if execute success, false otherwise.
551 */
BackgroundEvent(const int64_t formId,Want & want,const sptr<IRemoteObject> & callerToken)552 int FormMgrService::BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken)
553 {
554 HILOG_INFO("FMS BackgroundEvent called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
555 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
556 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
557 ErrCode ret = CheckFormPermission();
558 if (ret != ERR_OK) {
559 HILOG_ERROR("%{public}s fail, request form permission denied.", __func__);
560 return ret;
561 }
562 ret = FormDataMgr::GetInstance().CheckInvalidForm(formId);
563 if (ret != ERR_OK) {
564 HILOG_ERROR("fail, the form id is not under the current active user or invalid.");
565 return ret;
566 }
567 FormEventInfo eventInfo;
568 eventInfo.formId = formId;
569 eventInfo.bundleName = want.GetElement().GetBundleName();
570 eventInfo.moduleName = want.GetStringParam(AppExecFwk::Constants::PARAM_MODULE_NAME_KEY);
571 eventInfo.abilityName = want.GetElement().GetAbilityName();
572 FormEventReport::SendSecondFormEvent(FormEventName::BACKGROUND_EVENT_FORM, HiSysEventType::BEHAVIOR, eventInfo);
573 return FormMgrAdapter::GetInstance().BackgroundEvent(formId, want, callerToken);
574 }
575
576 /**
577 * @brief Start event for the form manager service.
578 */
OnStart()579 void FormMgrService::OnStart()
580 {
581 if (state_ == ServiceRunningState::STATE_RUNNING) {
582 HILOG_WARN("%{public}s fail, Failed to start service since it's already running", __func__);
583 return;
584 }
585
586 onStartBeginTime_ = GetCurrentDateTime();
587 HILOG_INFO("Form Mgr Service start, time: %{public}s", onStartBeginTime_.c_str());
588 ErrCode errCode = Init();
589 if (errCode != ERR_OK) {
590 HILOG_ERROR("%{public}s fail, Failed to init, errCode: %{public}08x", __func__, errCode);
591 return;
592 }
593
594 state_ = ServiceRunningState::STATE_RUNNING;
595 // listener for FormDataProxyMgr
596 AddSystemAbilityListener(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID);
597 AddSystemAbilityListener(MEMORY_MANAGER_SA_ID);
598 onStartEndTime_ = GetCurrentDateTime();
599 HILOG_INFO("Form Mgr Service start success, time: %{public}s, onKvDataServiceAddTime: %{public}s",
600 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
601 }
602 /**
603 * @brief Stop event for the form manager service.
604 */
OnStop()605 void FormMgrService::OnStop()
606 {
607 HILOG_INFO("stop service");
608
609 state_ = ServiceRunningState::STATE_NOT_START;
610
611 if (serialQueue_) {
612 serialQueue_.reset();
613 }
614
615 if (handler_) {
616 handler_.reset();
617 }
618 }
619
ReadFormConfigXML()620 ErrCode FormMgrService::ReadFormConfigXML()
621 {
622 FormXMLParser parser;
623 int32_t ret = parser.Parse();
624 if (ret != ERR_OK) {
625 HILOG_WARN("parse form config failed, use the default vaule.");
626 return ret;
627 }
628 const std::map<std::string, int32_t> &configMap = parser.GetConfigMap();
629 FormDataMgr::GetInstance().SetConfigMap(configMap);
630 return ERR_OK;
631 }
632
633
SubscribeSysEventReceiver()634 void FormMgrService::SubscribeSysEventReceiver()
635 {
636 if (formSysEventReceiver_ == nullptr) {
637 EventFwk::MatchingSkills matchingSkills;
638 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED);
639 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED);
640 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED);
641 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED);
642 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BUNDLE_SCAN_FINISHED);
643 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
644 // init TimerReceiver
645 EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills);
646 subscribeInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
647 formSysEventReceiver_ = std::make_shared<FormSysEventReceiver>(subscribeInfo);
648 formSysEventReceiver_->SetSerialQueue(serialQueue_);
649 EventFwk::CommonEventManager::SubscribeCommonEvent(formSysEventReceiver_);
650 }
651 }
652
653 /**
654 * @brief initialization of form manager service.
655 */
Init()656 ErrCode FormMgrService::Init()
657 {
658 FMS_CALL_INFO_ENTER;
659 serialQueue_ = std::make_shared<FormSerialQueue>(FORM_MGR_SERVICE_QUEUE.c_str());
660 if (serialQueue_ == nullptr) {
661 HILOG_ERROR("Init fail, Failed to init due to create serialQueue_ error");
662 return ERR_INVALID_OPERATION;
663 }
664
665 handler_ = std::make_shared<FormEventHandler>(serialQueue_);
666 if (handler_ == nullptr) {
667 HILOG_ERROR("%{public}s fail, Failed to init due to create handler error", __func__);
668 return ERR_INVALID_OPERATION;
669 }
670 FormTaskMgr::GetInstance().SetSerialQueue(serialQueue_);
671 FormAmsHelper::GetInstance().SetSerialQueue(serialQueue_);
672 /* Publish service maybe failed, so we need call this function at the last,
673 * so it can't affect the TDD test program */
674 if (!Publish(DelayedSingleton<FormMgrService>::GetInstance().get())) {
675 HILOG_ERROR("FormMgrService::Init Publish failed!");
676 return ERR_INVALID_OPERATION;
677 }
678 onStartPublishTime_ = GetCurrentDateTime();
679 HILOG_INFO("FMS onStart publish done, time: %{public}s", onStartPublishTime_.c_str());
680
681 SubscribeSysEventReceiver();
682
683 memStatusListener_ = std::make_shared<MemStatusListener>();
684 Memory::MemMgrClient::GetInstance().SubscribeAppState(*memStatusListener_);
685
686 FormInfoMgr::GetInstance().Start();
687 FormDbCache::GetInstance().Start();
688 FormTimerMgr::GetInstance(); // Init FormTimerMgr
689 FormCacheMgr::GetInstance().Start();
690
691 // read param form form_config.xml.
692 if (ReadFormConfigXML() != ERR_OK) {
693 HILOG_WARN("parse form config failed, use the default vaule.");
694 }
695 FormMgrAdapter::GetInstance().Init();
696 return ERR_OK;
697 }
698
CheckFormObserverPermission()699 ErrCode FormMgrService::CheckFormObserverPermission()
700 {
701 HILOG_DEBUG("called.");
702
703 if (FormUtil::IsSACall()) {
704 return ERR_OK;
705 }
706
707 // check if system app
708 if (!CheckCallerIsSystemApp()) {
709 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
710 }
711
712 if (!CheckAcrossLocalAccountsPermission()) {
713 HILOG_ERROR("Across local accounts permission failed.");
714 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
715 }
716
717 if (!FormUtil::VerifyCallingPermission(AppExecFwk::Constants::PERMISSION_OBSERVE_FORM_RUNNING)) {
718 HILOG_ERROR("verify calling permission failed!");
719 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
720 }
721 HILOG_DEBUG("Form Observer permission verification ok!");
722 return ERR_OK;
723 }
724
CheckFormPermission(const std::string & permission)725 ErrCode FormMgrService::CheckFormPermission(const std::string &permission)
726 {
727 HILOG_DEBUG("called.");
728
729 if (FormUtil::IsSACall()) {
730 return ERR_OK;
731 }
732
733 // check if system app
734 if (!CheckCallerIsSystemApp()) {
735 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
736 }
737
738 auto isCallingPerm = FormUtil::VerifyCallingPermission(permission);
739 if (!isCallingPerm) {
740 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
741 }
742
743 // checks whether the current user is inactive
744 if (!CheckAcrossLocalAccountsPermission()) {
745 HILOG_ERROR("Across local accounts permission failed.");
746 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
747 }
748
749 HILOG_DEBUG("Permission verification ok!");
750 return ERR_OK;
751 }
752
753 /**
754 * @brief Delete the invalid forms.
755 * @param formIds Indicates the ID of the valid forms.
756 * @param callerToken Caller ability token.
757 * @param numFormsDeleted Returns the number of the deleted forms.
758 * @return Returns ERR_OK on success, others on failure.
759 */
DeleteInvalidForms(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken,int32_t & numFormsDeleted)760 int FormMgrService::DeleteInvalidForms(const std::vector<int64_t> &formIds,
761 const sptr<IRemoteObject> &callerToken, int32_t &numFormsDeleted)
762 {
763 HILOG_INFO("called.");
764 ErrCode ret = CheckFormPermission();
765 if (ret != ERR_OK) {
766 HILOG_ERROR("fail, delete form permission denied");
767 return ret;
768 }
769 FormEventInfo eventInfo;
770 FormEventReport::SendFormEvent(FormEventName::DELETE_INVALID_FORM, HiSysEventType::BEHAVIOR, eventInfo);
771 return FormMgrAdapter::GetInstance().DeleteInvalidForms(formIds, callerToken, numFormsDeleted);
772 }
773
774 /**
775 * @brief Acquire form state info by passing a set of parameters (using Want) to the form provider.
776 * @param want Indicates a set of parameters to be transparently passed to the form provider.
777 * @param callerToken Caller ability token.
778 * @param stateInfo Returns the form's state info of the specify.
779 * @return Returns ERR_OK on success, others on failure.
780 */
AcquireFormState(const Want & want,const sptr<IRemoteObject> & callerToken,FormStateInfo & stateInfo)781 int FormMgrService::AcquireFormState(const Want &want,
782 const sptr<IRemoteObject> &callerToken, FormStateInfo &stateInfo)
783 {
784 HILOG_INFO("called.");
785 ErrCode ret = CheckFormPermission();
786 if (ret != ERR_OK) {
787 HILOG_ERROR("fail, acquire form state permission denied");
788 return ret;
789 }
790 FormEventInfo eventInfo;
791 eventInfo.bundleName = want.GetElement().GetBundleName();
792 eventInfo.moduleName = want.GetStringParam(AppExecFwk::Constants::PARAM_MODULE_NAME_KEY);
793 eventInfo.abilityName = want.GetElement().GetAbilityName();
794 FormEventReport::SendFormEvent(FormEventName::ACQUIREFORMSTATE_FORM, HiSysEventType::BEHAVIOR, eventInfo);
795 return FormMgrAdapter::GetInstance().AcquireFormState(want, callerToken, stateInfo);
796 }
797
798 /**
799 * @brief Register form router event proxy.
800 * @param formIds Indicates the ID of the forms.
801 * @param callerToken Host client.
802 * @return Returns ERR_OK on success, others on failure.
803 */
RegisterFormRouterProxy(const std::vector<int64_t> & formIds,const sptr<IRemoteObject> & callerToken)804 int FormMgrService::RegisterFormRouterProxy(const std::vector<int64_t> &formIds,
805 const sptr<IRemoteObject> &callerToken)
806 {
807 HILOG_DEBUG("Called.");
808 ErrCode ret = CheckFormPermission();
809 if (ret != ERR_OK) {
810 HILOG_ERROR("Fail, register form router proxy permission denied");
811 return ret;
812 }
813 return FormMgrAdapter::GetInstance().RegisterFormRouterProxy(formIds, callerToken);
814 }
815
816 /**
817 * @brief Unregister form router event proxy.
818 * @param formIds Indicates the ID of the forms.
819 * @return Returns ERR_OK on success, others on failure.
820 */
UnregisterFormRouterProxy(const std::vector<int64_t> & formIds)821 int FormMgrService::UnregisterFormRouterProxy(const std::vector<int64_t> &formIds)
822 {
823 HILOG_DEBUG("Called.");
824 ErrCode ret = CheckFormPermission();
825 if (ret != ERR_OK) {
826 HILOG_ERROR("Fail, unregister form router proxy permission denied");
827 return ret;
828 }
829 return FormMgrAdapter::GetInstance().UnregisterFormRouterProxy(formIds);
830 }
831
832 /**
833 * @brief Notify the form is visible or not.
834 * @param formIds Indicates the ID of the forms.
835 * @param isVisible Visible or not.
836 * @param callerToken Host client.
837 * @return Returns ERR_OK on success, others on failure.
838 */
NotifyFormsVisible(const std::vector<int64_t> & formIds,bool isVisible,const sptr<IRemoteObject> & callerToken)839 int FormMgrService::NotifyFormsVisible(const std::vector<int64_t> &formIds,
840 bool isVisible, const sptr<IRemoteObject> &callerToken)
841 {
842 HILOG_INFO("FMS NotifyFormsVisible called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
843 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
844 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
845 ErrCode ret = CheckFormPermission();
846 if (ret != ERR_OK) {
847 HILOG_ERROR("fail, notify form visible permission denied");
848 return ret;
849 }
850 return FormMgrAdapter::GetInstance().NotifyFormsVisible(formIds, isVisible, callerToken);
851 }
852
NotifyFormsPrivacyProtected(const std::vector<int64_t> & formIds,bool isProtected,const sptr<IRemoteObject> & callerToken)853 int FormMgrService::NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
854 const sptr<IRemoteObject> &callerToken)
855 {
856 HILOG_INFO("called.");
857 ErrCode ret = CheckFormPermission();
858 if (ret != ERR_OK) {
859 HILOG_ERROR("fail, notify form is privacy protected permission denied");
860 return ret;
861 }
862 return ERR_APPEXECFWK_FORM_COMMON_CODE;
863 }
864
865 /**
866 * @brief Notify the form is enable to be updated or not.
867 * @param formIds Indicates the ID of the forms.
868 * @param isEnableUpdate enable update or not.
869 * @param callerToken Host client.
870 * @return Returns ERR_OK on success, others on failure.
871 */
NotifyFormsEnableUpdate(const std::vector<int64_t> & formIds,bool isEnableUpdate,const sptr<IRemoteObject> & callerToken)872 int FormMgrService::NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds,
873 bool isEnableUpdate, const sptr<IRemoteObject> &callerToken)
874 {
875 HILOG_INFO("called.");
876 ErrCode ret = CheckFormPermission();
877 if (ret != ERR_OK) {
878 HILOG_ERROR("fail, notify form enable update permission denied");
879 return ret;
880 }
881 return FormMgrAdapter::GetInstance().NotifyFormsEnableUpdate(formIds, isEnableUpdate, callerToken);
882 }
883
884 /**
885 * @brief Get All FormsInfo.
886 * @param formInfos Return the form information of all forms provided.
887 * @return Returns ERR_OK on success, others on failure.
888 */
GetAllFormsInfo(std::vector<FormInfo> & formInfos)889 int FormMgrService::GetAllFormsInfo(std::vector<FormInfo> &formInfos)
890 {
891 HILOG_INFO("called.");
892 if (!CheckCallerIsSystemApp()) {
893 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
894 }
895 if (!CheckAcrossLocalAccountsPermission()) {
896 HILOG_ERROR("Across local accounts permission failed.");
897 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
898 }
899 return FormMgrAdapter::GetInstance().GetAllFormsInfo(formInfos);
900 }
901
902 /**
903 * @brief Get forms info by bundle name.
904 * @param bundleName Application name.
905 * @param formInfos Return the form information of the specify application name.
906 * @return Returns ERR_OK on success, others on failure.
907 */
GetFormsInfoByApp(std::string & bundleName,std::vector<FormInfo> & formInfos)908 int FormMgrService::GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos)
909 {
910 HILOG_DEBUG("called.");
911 if (!CheckCallerIsSystemApp()) {
912 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
913 }
914 if (!CheckAcrossLocalAccountsPermission()) {
915 HILOG_ERROR("Across local accounts permission failed.");
916 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
917 }
918 return FormMgrAdapter::GetInstance().GetFormsInfoByApp(bundleName, formInfos);
919 }
920
921 /**
922 * @brief Get forms info by bundle name and module name.
923 * @param bundleName bundle name.
924 * @param moduleName Module name of hap.
925 * @param formInfos Return the forms information of the specify bundle name and module name.
926 * @return Returns ERR_OK on success, others on failure.
927 */
GetFormsInfoByModule(std::string & bundleName,std::string & moduleName,std::vector<FormInfo> & formInfos)928 int FormMgrService::GetFormsInfoByModule(std::string &bundleName, std::string &moduleName,
929 std::vector<FormInfo> &formInfos)
930 {
931 HILOG_DEBUG("called.");
932 if (!CheckCallerIsSystemApp()) {
933 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
934 }
935 if (!CheckAcrossLocalAccountsPermission()) {
936 HILOG_ERROR("Across local accounts permission failed.");
937 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
938 }
939 return FormMgrAdapter::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos);
940 }
941
GetFormsInfo(const FormInfoFilter & filter,std::vector<FormInfo> & formInfos)942 int32_t FormMgrService::GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos)
943 {
944 HILOG_INFO("called.");
945 std::string callerBundleName;
946 auto ret = FormBmsHelper::GetInstance().GetCallerBundleName(callerBundleName);
947 if (ret != ERR_OK) {
948 HILOG_ERROR("fail, get host bundle name failed");
949 return ret;
950 }
951 // retrieve moduleName from filter.
952 std::string moduleName = filter.moduleName;
953 if (moduleName.empty()) {
954 // fulfill formInfos, the process should be the same as GetFormsInfoByApp.
955 HILOG_INFO("GetFormsInfo flows to GetFormsInfoByAPP");
956 return FormMgrAdapter::GetInstance().GetFormsInfoByApp(callerBundleName, formInfos);
957 }
958 HILOG_INFO("GetFormsInfo flows to GetFormsInfoByModule");
959 return FormMgrAdapter::GetInstance().GetFormsInfoByModule(callerBundleName, moduleName, formInfos);
960 }
961
AcquireFormData(int64_t formId,int64_t requestCode,const sptr<IRemoteObject> & callerToken,AAFwk::WantParams & formData)962 int32_t FormMgrService::AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
963 AAFwk::WantParams &formData)
964 {
965 HILOG_INFO("called.");
966 if (formId <= 0) {
967 HILOG_ERROR("form formId is invalid.");
968 return ERR_APPEXECFWK_FORM_COMMON_CODE;
969 }
970
971 if (callerToken == nullptr) {
972 HILOG_ERROR("callerToken is nullptr");
973 return ERR_APPEXECFWK_FORM_COMMON_CODE;
974 }
975
976 if (requestCode <= 0) {
977 HILOG_ERROR("form requestCode is invalid");
978 return ERR_APPEXECFWK_FORM_COMMON_CODE;
979 }
980
981 ErrCode ret = CheckFormPermission();
982 if (ret != ERR_OK) {
983 HILOG_ERROR("fail, request form permission denied");
984 return ret;
985 }
986 return FormMgrAdapter::GetInstance().AcquireFormData(formId, requestCode, callerToken, formData);
987 }
988
IsRequestPublishFormSupported()989 bool FormMgrService::IsRequestPublishFormSupported()
990 {
991 HILOG_INFO("%{public}s called.", __func__);
992 if (!CheckCallerIsSystemApp()) {
993 return false;
994 }
995 return FormMgrAdapter::GetInstance().IsRequestPublishFormSupported();
996 }
997
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken)998 int32_t FormMgrService::StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken)
999 {
1000 HILOG_INFO("FMS StartAbility called, startTime: begin: %{public}s, publish: %{public}s, end: %{public}s, "
1001 "onKvDataServiceAddTime: %{public}s", onStartBeginTime_.c_str(), onStartPublishTime_.c_str(),
1002 onStartEndTime_.c_str(), onKvDataServiceAddTime_.c_str());
1003 sptr<IBundleMgr> bundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
1004 if (bundleMgr == nullptr) {
1005 HILOG_ERROR("%{public}s error, failed to get bundleMgr.", __func__);
1006 return ERR_APPEXECFWK_FORM_GET_BMS_FAILED;
1007 }
1008 if (!CheckCallerIsSystemApp()) {
1009 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
1010 }
1011 // retrieve bundleName of the calling ability.
1012 std::string callerBundleName;
1013 auto callUid = IPCSkeleton::GetCallingUid();
1014 if (IN_PROCESS_CALL(bundleMgr->GetNameForUid(callUid, callerBundleName)) != ERR_OK) {
1015 HILOG_ERROR("StartAbility, failed to get form config info.");
1016 return ERR_APPEXECFWK_FORM_GET_INFO_FAILED;
1017 }
1018 // caller and callee should be in the same bundle.
1019 if (want.GetElement().GetBundleName() != callerBundleName) {
1020 return ERR_APPEXECFWK_FORM_INVALID_BUNDLENAME;
1021 }
1022 // check abilityName to void implicit want.
1023 if (want.GetElement().GetAbilityName() == "") {
1024 HILOG_ERROR("%{public}s error, AbilityName is empty", __func__);
1025 return ERR_APPEXECFWK_FORM_NO_SUCH_ABILITY;
1026 }
1027 sptr<AAFwk::IAbilityManager> ams = FormAmsHelper::GetInstance().GetAbilityManager();
1028 if (ams == nullptr) {
1029 HILOG_ERROR("%{public}s error, failed to get ams.", __func__);
1030 return ERR_APPEXECFWK_FORM_COMMON_CODE;
1031 }
1032 return ams->StartAbility(want, callerToken, -1, -1);
1033 }
1034
InitFormShareMgrSerialQueue()1035 void FormMgrService::InitFormShareMgrSerialQueue()
1036 {
1037 DelayedSingleton<FormShareMgr>::GetInstance()->SetSerialQueue(serialQueue_);
1038 DelayedSingleton<FormShareMgr>::GetInstance()->SetEventHandler(handler_);
1039 }
1040
ShareForm(int64_t formId,const std::string & deviceId,const sptr<IRemoteObject> & callerToken,int64_t requestCode)1041 int32_t FormMgrService::ShareForm(int64_t formId, const std::string &deviceId, const sptr<IRemoteObject> &callerToken,
1042 int64_t requestCode)
1043 {
1044 HILOG_DEBUG("FormMgrService ShareForm called deviceId : %{public}s, formId: %{public}" PRId64 "",
1045 deviceId.c_str(), formId);
1046 if (formId <= 0) {
1047 HILOG_ERROR("form formId is invalid.");
1048 return ERR_APPEXECFWK_FORM_COMMON_CODE;
1049 }
1050
1051 if (deviceId.empty()) {
1052 HILOG_ERROR("form deviceId is empty.");
1053 return ERR_APPEXECFWK_FORM_COMMON_CODE;
1054 }
1055
1056 if (callerToken == nullptr) {
1057 HILOG_ERROR("callerToken is nullptr.");
1058 return ERR_APPEXECFWK_FORM_COMMON_CODE;
1059 }
1060
1061 if (requestCode <= 0) {
1062 HILOG_ERROR("form requestCode is invalid.");
1063 return ERR_APPEXECFWK_FORM_COMMON_CODE;
1064 }
1065
1066 auto ret = CheckFormPermission();
1067 if (ret != ERR_OK) {
1068 HILOG_ERROR("share form permission denied.");
1069 return ret;
1070 }
1071
1072 ret = FormDataMgr::GetInstance().CheckInvalidForm(formId);
1073 if (ret != ERR_OK) {
1074 HILOG_ERROR("fail, the form id is invalid or not under the current active user.");
1075 return ret;
1076 }
1077
1078 InitFormShareMgrSerialQueue();
1079
1080 return DelayedSingleton<FormShareMgr>::GetInstance()->ShareForm(formId, deviceId, callerToken, requestCode);
1081 }
1082
RecvFormShareInfoFromRemote(const FormShareInfo & info)1083 int32_t FormMgrService::RecvFormShareInfoFromRemote(const FormShareInfo &info)
1084 {
1085 HILOG_DEBUG("%{public}s called.", __func__);
1086 InitFormShareMgrSerialQueue();
1087
1088 return DelayedSingleton<FormShareMgr>::GetInstance()->RecvFormShareInfoFromRemote(info);
1089 }
1090
DumpInit()1091 void FormMgrService::DumpInit()
1092 {
1093 dumpFuncMap_[DumpKey::KEY_DUMP_HELP] = &FormMgrService::HiDumpHelp;
1094 dumpFuncMap_[DumpKey::KEY_DUMP_STATIC] = &FormMgrService::HiDumpStaticBundleFormInfos;
1095 dumpFuncMap_[DumpKey::KEY_DUMP_STORAGE] = &FormMgrService::HiDumpStorageFormInfos;
1096 dumpFuncMap_[DumpKey::KEY_DUMP_TEMPORARY] = &FormMgrService::HiDumpTemporaryFormInfos;
1097 dumpFuncMap_[DumpKey::KEY_DUMP_BY_BUNDLE_NAME] = &FormMgrService::HiDumpFormInfoByBundleName;
1098 dumpFuncMap_[DumpKey::KEY_DUMP_BY_FORM_ID] = &FormMgrService::HiDumpFormInfoByFormId;
1099 }
1100
Dump(int fd,const std::vector<std::u16string> & args)1101 int FormMgrService::Dump(int fd, const std::vector<std::u16string> &args)
1102 {
1103 if (!IsReady()) {
1104 HILOG_ERROR("%{public}s, fms is not ready.", __func__);
1105 return ERR_APPEXECFWK_FORM_COMMON_CODE;
1106 }
1107
1108 std::string result;
1109 Dump(args, result);
1110 int ret = dprintf(fd, "%s\n", result.c_str());
1111 if (ret < 0) {
1112 HILOG_ERROR("%{public}s, dprintf error.", __func__);
1113 return ERR_APPEXECFWK_FORM_COMMON_CODE;
1114 }
1115 return ERR_OK;
1116 }
1117
Dump(const std::vector<std::u16string> & args,std::string & result)1118 void FormMgrService::Dump(const std::vector<std::u16string> &args, std::string &result)
1119 {
1120 DumpKey key;
1121 std::string value;
1122 if (!ParseOption(args, key, value, result)) {
1123 result.append('\n' + FORM_DUMP_HELP);
1124 return;
1125 }
1126
1127 auto iter = dumpFuncMap_.find(key);
1128 if (iter == dumpFuncMap_.end() || iter->second == nullptr) {
1129 result = "error: unknow function.";
1130 return;
1131 }
1132
1133 auto dumpFunc = iter->second;
1134 (this->*dumpFunc)(value, result);
1135 }
1136
RegisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)1137 int32_t FormMgrService::RegisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
1138 {
1139 HILOG_DEBUG("called.");
1140 sptr<IBundleMgr> bundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
1141 if (bundleMgr == nullptr) {
1142 HILOG_ERROR("error to get bundleMgr.");
1143 return ERR_APPEXECFWK_FORM_GET_BMS_FAILED;
1144 }
1145 // check if system app
1146 auto callingUid = IPCSkeleton::GetCallingUid();
1147 auto isSystemApp = bundleMgr->CheckIsSystemAppByUid(callingUid);
1148 if (!isSystemApp) {
1149 HILOG_ERROR("no permission.");
1150 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
1151 }
1152 return FormMgrAdapter::GetInstance().RegisterPublishFormInterceptor(interceptorCallback);
1153 }
1154
UnregisterPublishFormInterceptor(const sptr<IRemoteObject> & interceptorCallback)1155 int32_t FormMgrService::UnregisterPublishFormInterceptor(const sptr<IRemoteObject> &interceptorCallback)
1156 {
1157 HILOG_DEBUG("called.");
1158 sptr<IBundleMgr> bundleMgr = FormBmsHelper::GetInstance().GetBundleMgr();
1159 if (bundleMgr == nullptr) {
1160 HILOG_ERROR("failed to get bundleMgr.");
1161 return ERR_APPEXECFWK_FORM_GET_BMS_FAILED;
1162 }
1163 // check if system app
1164 auto callingUid = IPCSkeleton::GetCallingUid();
1165 auto isSystemApp = bundleMgr->CheckIsSystemAppByUid(callingUid);
1166 if (!isSystemApp) {
1167 HILOG_ERROR("permission denied.");
1168 return ERR_APPEXECFWK_FORM_PERMISSION_DENY;
1169 }
1170 return FormMgrAdapter::GetInstance().UnregisterPublishFormInterceptor(interceptorCallback);
1171 }
1172
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1173 void FormMgrService::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
1174 {
1175 if (systemAbilityId == MEMORY_MANAGER_SA_ID) {
1176 HILOG_INFO("MEMORY_MANAGER_SA start, SubscribeAppState");
1177 Memory::MemMgrClient::GetInstance().SubscribeAppState(*memStatusListener_);
1178 return;
1179 }
1180 if (systemAbilityId != DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID) {
1181 return;
1182 }
1183 onKvDataServiceAddTime_ = GetCurrentDateTime();
1184 FormDataProxyMgr::GetInstance().RetryFailureSubscribes();
1185 HILOG_INFO("FMS KV data service add time: %{public}s", onKvDataServiceAddTime_.c_str());
1186 }
1187
ParseOption(const std::vector<std::u16string> & args,DumpKey & key,std::string & value,std::string & result)1188 bool FormMgrService::ParseOption(const std::vector<std::u16string> &args, DumpKey &key, std::string &value,
1189 std::string &result)
1190 {
1191 auto size = args.size();
1192 if (size == 0) {
1193 result = "error: must contain arguments.";
1194 return false;
1195 }
1196
1197 if (size > FORM_DUMP_ARGC_MAX) {
1198 result = "error: arguments numer out of limit.";
1199 return false;
1200 }
1201
1202 std::string optionKey = Str16ToStr8(args[0]);
1203 auto iter = dumpKeyMap_.find(optionKey);
1204 if (iter == dumpKeyMap_.end()) {
1205 result = "error: unkown option.";
1206 return false;
1207 }
1208
1209 key = iter->second;
1210
1211 if (args.size() == FORM_DUMP_ARGC_MAX) {
1212 value = Str16ToStr8(args[1]);
1213 }
1214
1215 return true;
1216 }
1217
HiDumpHelp(const std::string & args,std::string & result)1218 void FormMgrService::HiDumpHelp([[maybe_unused]] const std::string &args, std::string &result)
1219 {
1220 result = FORM_DUMP_HELP;
1221 }
1222
HiDumpStorageFormInfos(const std::string & args,std::string & result)1223 void FormMgrService::HiDumpStorageFormInfos([[maybe_unused]] const std::string &args, std::string &result)
1224 {
1225 DumpStorageFormInfos(result);
1226 }
1227
HiDumpTemporaryFormInfos(const std::string & args,std::string & result)1228 void FormMgrService::HiDumpTemporaryFormInfos([[maybe_unused]] const std::string &args, std::string &result)
1229 {
1230 if (!CheckCallerIsSystemApp()) {
1231 return;
1232 }
1233 FormMgrAdapter::GetInstance().DumpTemporaryFormInfos(result);
1234 }
1235
HiDumpStaticBundleFormInfos(const std::string & args,std::string & result)1236 void FormMgrService::HiDumpStaticBundleFormInfos([[maybe_unused]] const std::string &args, std::string &result)
1237 {
1238 if (!CheckCallerIsSystemApp()) {
1239 return;
1240 }
1241 FormMgrAdapter::GetInstance().DumpStaticBundleFormInfos(result);
1242 }
1243
HiDumpFormInfoByBundleName(const std::string & args,std::string & result)1244 void FormMgrService::HiDumpFormInfoByBundleName(const std::string &args, std::string &result)
1245 {
1246 if (args.empty()) {
1247 result = "error: request a bundle name.";
1248 return;
1249 }
1250 DumpFormInfoByBundleName(args, result);
1251 }
1252
HiDumpFormInfoByFormId(const std::string & args,std::string & result)1253 void FormMgrService::HiDumpFormInfoByFormId(const std::string &args, std::string &result)
1254 {
1255 if (args.empty()) {
1256 result = "error: request a form ID.";
1257 return;
1258 }
1259 int64_t formId = atoll(args.c_str());
1260 if (formId == 0) {
1261 result = "error: form ID is invalid.";
1262 return;
1263 }
1264 DumpFormInfoByFormId(formId, result);
1265 }
1266
CheckCallerIsSystemApp() const1267 bool FormMgrService::CheckCallerIsSystemApp() const
1268 {
1269 auto callerTokenID = IPCSkeleton::GetCallingFullTokenID();
1270 if (!FormUtil::IsSACall() && !Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callerTokenID)) {
1271 HILOG_ERROR("The caller is not system-app, can not use system-api");
1272 return false;
1273 }
1274 return true;
1275 }
1276
GetCurrentDateTime()1277 std::string FormMgrService::GetCurrentDateTime()
1278 {
1279 auto cTimeNow = std::chrono::system_clock::now();
1280 auto microPart = std::chrono::duration_cast<std::chrono::milliseconds>(
1281 cTimeNow.time_since_epoch()).count() % 1000;
1282 std::time_t t1 = std::chrono::system_clock::to_time_t(cTimeNow);
1283 char buf[32];
1284 std::tm t2;
1285 localtime_r(&t1, &t2);
1286 (void)strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S.", &t2);
1287 std::stringstream ss;
1288 ss << buf << std::setw(MILLISECOND_WIDTH) << std::setfill(MILLISECOND_FILLCHAR) << microPart;
1289 return ss.str();
1290 }
1291
CheckAcrossLocalAccountsPermission() const1292 bool FormMgrService::CheckAcrossLocalAccountsPermission() const
1293 {
1294 // checks whether the current user is inactive
1295 int callingUid = IPCSkeleton::GetCallingUid();
1296 int32_t userId = callingUid / GET_CALLING_UID_TRANSFORM_DIVISOR;
1297 int32_t currentActiveUserId = FormUtil::GetCurrentAccountId();
1298 if (userId != currentActiveUserId) {
1299 HILOG_DEBUG("currentActiveUserId: %{public}d, userId: %{public}d", currentActiveUserId, userId);
1300 bool isCallingPermAccount =
1301 FormUtil::VerifyCallingPermission(AppExecFwk::Constants::PERMISSION_INTERACT_ACROSS_LOCAL_ACCOUNTS);
1302 if (!isCallingPermAccount) {
1303 HILOG_ERROR("Across local accounts permission failed.");
1304 return false;
1305 }
1306 }
1307 return true;
1308 }
1309
RegisterFormAddObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1310 ErrCode FormMgrService::RegisterFormAddObserverByBundle(const std::string bundleName,
1311 const sptr<IRemoteObject> &callerToken)
1312 {
1313 HILOG_DEBUG("called.");
1314 ErrCode ret = CheckFormObserverPermission();
1315 if (ret != ERR_OK) {
1316 HILOG_ERROR("fail, register form add observer permission denied");
1317 return ret;
1318 }
1319 return FormMgrAdapter::GetInstance().RegisterFormAddObserverByBundle(bundleName, callerToken);
1320 }
1321
RegisterFormRemoveObserverByBundle(const std::string bundleName,const sptr<IRemoteObject> & callerToken)1322 ErrCode FormMgrService::RegisterFormRemoveObserverByBundle(const std::string bundleName,
1323 const sptr<IRemoteObject> &callerToken)
1324 {
1325 HILOG_DEBUG("called.");
1326 ErrCode ret = CheckFormObserverPermission();
1327 if (ret != ERR_OK) {
1328 HILOG_ERROR("fail, register form remove observer permission denied");
1329 return ret;
1330 }
1331 return FormMgrAdapter::GetInstance().RegisterFormRemoveObserverByBundle(bundleName, callerToken);
1332 }
1333
GetFormsCount(bool isTempFormFlag,int32_t & formCount)1334 int32_t FormMgrService::GetFormsCount(bool isTempFormFlag, int32_t &formCount)
1335 {
1336 HILOG_INFO("%{public}s called.", __func__);
1337 return FormMgrAdapter::GetInstance().GetFormsCount(isTempFormFlag, formCount);
1338 }
1339
GetHostFormsCount(std::string & bundleName,int32_t & formCount)1340 int32_t FormMgrService::GetHostFormsCount(std::string &bundleName, int32_t &formCount)
1341 {
1342 HILOG_INFO("%{public}s called.", __func__);
1343 return FormMgrAdapter::GetInstance().GetHostFormsCount(bundleName, formCount);
1344 }
1345
GetRunningFormInfos(bool isUnusedIncluded,std::vector<RunningFormInfo> & runningFormInfos)1346 ErrCode FormMgrService::GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos)
1347 {
1348 HILOG_DEBUG("called.");
1349 ErrCode ret = CheckFormObserverPermission();
1350 if (ret != ERR_OK) {
1351 HILOG_ERROR("fail, get running form infos permission denied");
1352 return ret;
1353 }
1354 return FormMgrAdapter::GetInstance().GetRunningFormInfos(isUnusedIncluded, runningFormInfos);
1355 }
1356
GetRunningFormInfosByBundleName(const std::string & bundleName,bool isUnusedIncluded,std::vector<RunningFormInfo> & runningFormInfos)1357 ErrCode FormMgrService::GetRunningFormInfosByBundleName(
1358 const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos)
1359 {
1360 HILOG_DEBUG("called.");
1361 ErrCode ret = CheckFormObserverPermission();
1362 if (ret != ERR_OK) {
1363 HILOG_ERROR("fail, get running form infos by bundle name permission denied");
1364 return ret;
1365 }
1366 return FormMgrAdapter::GetInstance().GetRunningFormInfosByBundleName(
1367 bundleName, isUnusedIncluded, runningFormInfos);
1368 }
1369
GetFormInstancesByFilter(const FormInstancesFilter & formInstancesFilter,std::vector<FormInstance> & formInstances)1370 ErrCode FormMgrService::GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
1371 std::vector<FormInstance> &formInstances)
1372 {
1373 HILOG_DEBUG("called.");
1374 ErrCode ret = CheckFormObserverPermission();
1375 if (ret != ERR_OK) {
1376 HILOG_ERROR("fail, get form instances by filter permission denied");
1377 return ret;
1378 }
1379 return FormMgrAdapter::GetInstance().GetFormInstancesByFilter(formInstancesFilter, formInstances);
1380 }
1381
GetFormInstanceById(const int64_t formId,FormInstance & formInstance)1382 ErrCode FormMgrService::GetFormInstanceById(const int64_t formId, FormInstance &formInstance)
1383 {
1384 HILOG_DEBUG("called.");
1385 ErrCode ret = CheckFormObserverPermission();
1386 if (ret != ERR_OK) {
1387 HILOG_ERROR("fail, get form instance by id permission denied");
1388 return ret;
1389 }
1390 return FormMgrAdapter::GetInstance().GetFormInstanceById(formId, formInstance);
1391 }
1392
GetFormInstanceById(const int64_t formId,bool isUnusedIncluded,FormInstance & formInstance)1393 ErrCode FormMgrService::GetFormInstanceById(const int64_t formId, bool isUnusedIncluded, FormInstance &formInstance)
1394 {
1395 HILOG_DEBUG("called.");
1396 ErrCode ret = CheckFormObserverPermission();
1397 if (ret != ERR_OK) {
1398 HILOG_ERROR("fail, get form instance by id permission denied");
1399 return ret;
1400 }
1401 return FormMgrAdapter::GetInstance().GetFormInstanceById(formId, isUnusedIncluded, formInstance);
1402 }
1403
RegisterAddObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1404 ErrCode FormMgrService::RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1405 {
1406 HILOG_DEBUG("called.");
1407 ErrCode ret = CheckFormObserverPermission();
1408 if (ret != ERR_OK) {
1409 HILOG_ERROR("fail, register notifyVisible or notifyInVisible observer permission denied");
1410 return ret;
1411 }
1412 return FormMgrAdapter::GetInstance().RegisterAddObserver(bundleName, callerToken);
1413 }
1414
RegisterRemoveObserver(const std::string & bundleName,const sptr<IRemoteObject> & callerToken)1415 ErrCode FormMgrService::RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken)
1416 {
1417 HILOG_DEBUG("called.");
1418 ErrCode ret = CheckFormObserverPermission();
1419 if (ret != ERR_OK) {
1420 HILOG_ERROR("fail, unregister notifyVisible or notifyInVisible observer permission denied");
1421 return ret;
1422 }
1423 return FormMgrAdapter::GetInstance().RegisterRemoveObserver(bundleName, callerToken);
1424 }
1425
UpdateProxyForm(int64_t formId,const FormProviderData & formBindingData,const std::vector<FormDataProxy> & formDataProxies)1426 ErrCode FormMgrService::UpdateProxyForm(int64_t formId, const FormProviderData &formBindingData,
1427 const std::vector<FormDataProxy> &formDataProxies)
1428 {
1429 HILOG_DEBUG("called.");
1430 auto callingUid = IPCSkeleton::GetCallingUid();
1431 return FormMgrAdapter::GetInstance().UpdateForm(formId, callingUid, formBindingData, formDataProxies);
1432 }
1433
RequestPublishProxyForm(Want & want,bool withFormBindingData,std::unique_ptr<FormProviderData> & formBindingData,int64_t & formId,const std::vector<FormDataProxy> & formDataProxies)1434 ErrCode FormMgrService::RequestPublishProxyForm(Want &want, bool withFormBindingData,
1435 std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId,
1436 const std::vector<FormDataProxy> &formDataProxies)
1437 {
1438 HILOG_DEBUG("called.");
1439 if (!CheckCallerIsSystemApp()) {
1440 return ERR_APPEXECFWK_FORM_PERMISSION_DENY_SYS;
1441 }
1442 return FormMgrAdapter::GetInstance().RequestPublishForm(want, withFormBindingData, formBindingData, formId,
1443 formDataProxies);
1444 }
1445
RegisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)1446 ErrCode FormMgrService::RegisterClickEventObserver(
1447 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
1448 {
1449 HILOG_INFO("Called.");
1450 if (observer == nullptr) {
1451 HILOG_ERROR("Caller token parameter is empty.");
1452 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
1453 }
1454 ErrCode ret = CheckFormObserverPermission();
1455 if (ret != ERR_OK) {
1456 HILOG_ERROR("Fail, register form add observer permission denied");
1457 return ret;
1458 }
1459 return FormMgrAdapter::GetInstance().RegisterClickEventObserver(bundleName, formEventType, observer);
1460 }
1461
UnregisterClickEventObserver(const std::string & bundleName,const std::string & formEventType,const sptr<IRemoteObject> & observer)1462 ErrCode FormMgrService::UnregisterClickEventObserver(
1463 const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer)
1464 {
1465 HILOG_INFO("Called.");
1466 if (observer == nullptr) {
1467 HILOG_ERROR("Caller token parameter is empty.");
1468 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
1469 }
1470 ErrCode ret = CheckFormObserverPermission();
1471 if (ret != ERR_OK) {
1472 HILOG_ERROR("Fail, register form add observer permission denied");
1473 return ret;
1474 }
1475 return FormMgrAdapter::GetInstance().UnregisterClickEventObserver(bundleName, formEventType, observer);
1476 }
1477
SetFormsRecyclable(const std::vector<int64_t> & formIds)1478 int32_t FormMgrService::SetFormsRecyclable(const std::vector<int64_t> &formIds)
1479 {
1480 HILOG_DEBUG("called.");
1481 ErrCode ret = CheckFormPermission();
1482 if (ret != ERR_OK) {
1483 HILOG_ERROR("set forms recyclable permission denied");
1484 return ret;
1485 }
1486 return FormMgrAdapter::GetInstance().SetFormsRecyclable(formIds);
1487 }
1488
RecycleForms(const std::vector<int64_t> & formIds,const Want & want)1489 int32_t FormMgrService::RecycleForms(const std::vector<int64_t> &formIds, const Want &want)
1490 {
1491 HILOG_DEBUG("called.");
1492 ErrCode ret = CheckFormPermission();
1493 if (ret != ERR_OK) {
1494 HILOG_ERROR("recycle forms permission denied");
1495 return ret;
1496 }
1497 return FormMgrAdapter::GetInstance().RecycleForms(formIds, want);
1498 }
1499
RecoverForms(const std::vector<int64_t> & formIds,const Want & want)1500 int32_t FormMgrService::RecoverForms(const std::vector<int64_t> &formIds, const Want &want)
1501 {
1502 HILOG_DEBUG("called.");
1503 ErrCode ret = CheckFormPermission();
1504 if (ret != ERR_OK) {
1505 HILOG_ERROR("recover forms permission denied");
1506 return ret;
1507 }
1508 return FormMgrAdapter::GetInstance().RecoverForms(formIds, want);
1509 }
1510 } // namespace AppExecFwk
1511 } // namespace OHOS
1512