1 /*
2 * Copyright (c) 2025 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_refresh/form_refresh_mgr.h"
17
18 #include "fms_log_wrapper.h"
19 #include "form_mgr_errors.h"
20 #include "common/event/form_event_report.h"
21 #include "form_refresh/refresh_impl/form_host_refresh_impl.h"
22 #include "form_refresh/refresh_impl/form_net_conn_refresh_impl.h"
23 #include "form_refresh/refresh_impl/form_next_time_refresh_impl.h"
24 #include "form_refresh/refresh_impl/form_timer_refresh_impl.h"
25 #include "form_refresh/refresh_impl/form_data_refresh_impl.h"
26 #include "form_refresh/refresh_impl/form_force_refresh_impl.h"
27 #include "form_refresh/refresh_impl/form_refresh_after_uncontrol_impl.h"
28 #include "form_refresh/refresh_impl/form_app_upgrade_refresh_impl.h"
29
30 namespace OHOS {
31 namespace AppExecFwk {
32 namespace {
33 const static std::set<int> ERROR_CODE_WHITE_LIST = {
34 ERR_OK,
35 ERR_APPEXECFWK_FORM_INVALID_PARAM,
36 ERR_APPEXECFWK_FORM_NOT_EXIST_ID,
37 ERR_APPEXECFWK_FORM_DISABLE_REFRESH
38 };
39 }
40
FormRefreshMgr()41 FormRefreshMgr::FormRefreshMgr() {}
~FormRefreshMgr()42 FormRefreshMgr::~FormRefreshMgr() {}
43
44 const static std::map<int32_t, IFormRefresh *> refreshMap = {
45 { TYPE_HOST, &FormHostRefreshImpl::GetInstance() },
46 { TYPE_NETWORK, &FormNetConnRefreshImpl::GetInstance() },
47 { TYPE_NEXT_TIME, &FormNextTimeRefreshImpl::GetInstance() },
48 { TYPE_TIMER, &FormTimerRefreshImpl::GetInstance() },
49 { TYPE_DATA, &FormDataRefreshImpl::GetInstance() },
50 { TYPE_FORCE, &FormForceRefreshImpl::GetInstance() },
51 { TYPE_UNCONTROL, &FormRefreshAfterUncontrolImpl::GetInstance() },
52 { TYPE_APP_UPGRADE, &FormAppUpgradeRefreshImpl::GetInstance() },
53 };
54
RequestRefresh(RefreshData & data,const int32_t refreshType)55 int FormRefreshMgr::RequestRefresh(RefreshData &data, const int32_t refreshType)
56 {
57 HILOG_INFO("refreshInputType:%{public}d, formId:%{public}" PRId64, refreshType, data.formId);
58 auto it = refreshMap.find(refreshType);
59 if (it != refreshMap.end()) {
60 int ret = it->second->RefreshFormRequest(data);
61 if (ERROR_CODE_WHITE_LIST.find(ret) == ERROR_CODE_WHITE_LIST.end()) {
62 FormEventReport::SendFormFailedEvent(FormEventName::UPDATE_FORM_FAILED,
63 data.formId,
64 data.record.bundleName,
65 data.record.formName,
66 refreshType,
67 ret);
68 }
69 return ret;
70 }
71
72 HILOG_ERROR("invalid refreshType");
73 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
74 }
75
76 } // namespace AppExecFwk
77 } // namespace OHOS