• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/refresh_impl/form_host_refresh_impl.h"
17 
18 #include "form_refresh/strategy/refresh_check_mgr.h"
19 #include "form_refresh/strategy/refresh_control_mgr.h"
20 #include "form_refresh/strategy/refresh_exec_mgr.h"
21 #include "form_refresh/strategy/refresh_cache_mgr.h"
22 #include "data_center/form_data_mgr.h"
23 #include "common/util/form_util.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 
FormHostRefreshImpl()28 FormHostRefreshImpl::FormHostRefreshImpl() {}
~FormHostRefreshImpl()29 FormHostRefreshImpl::~FormHostRefreshImpl() {}
30 
RefreshFormRequest(RefreshData & data)31 int FormHostRefreshImpl::RefreshFormRequest(RefreshData &data)
32 {
33     const std::vector<int32_t> checkTypes = { TYPE_UNTRUST_APP, TYPE_SELF_FORM, TYPE_ACTIVE_USER, TYPE_ADD_FINISH };
34     CheckValidFactor factor;
35     factor.formId = data.formId;
36     factor.record = data.record;
37     factor.callerToken = data.callerToken;
38     Want reqWant(data.want);
39     reqWant.SetParam(Constants::PARAM_FORM_USER_ID, FormUtil::GetCurrentAccountId());
40     factor.want = reqWant;
41     int ret = RefreshCheckMgr::GetInstance().IsBaseValidPass(checkTypes, factor);
42     if (ret != ERR_OK) {
43         return ret;
44     }
45 
46     FormDataMgr::GetInstance().UpdateFormWant(data.formId, data.want, data.record);
47     FormDataMgr::GetInstance().UpdateFormRecord(data.formId, data.record);
48     if (RefreshControlMgr::GetInstance().IsHealthyControl(data.record)) {
49         RefreshCacheMgr::GetInstance().AddFlagByHealthyControl(data.formId, true);
50         return ERR_OK;
51     }
52 
53     if (data.record.isSystemApp) {
54         reqWant.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_HOST);
55     }
56 
57     if (RefreshControlMgr::GetInstance().IsScreenOff(data.record)) {
58         RefreshCacheMgr::GetInstance().AddFlagByScreenOff(data.formId, data.want, data.record);
59         return ERR_OK;
60     }
61 
62     if (!RefreshControlMgr::GetInstance().IsNeedToFresh(data.record, true)) {
63         FormDataMgr::GetInstance().SetNeedRefresh(data.formId, true);
64         return ERR_OK;
65     }
66 
67     FormRecord refreshRecord = FormDataMgr::GetInstance().GetFormAbilityInfo(data.record);
68     ret = RefreshExecMgr::AskForProviderData(data.formId, refreshRecord, reqWant);
69     if (ret != ERR_OK) {
70         HILOG_ERROR("ask for provider data failed, ret:%{public}d, formId:%{public}" PRId64, ret, data.formId);
71         return ret;
72     }
73 
74     return ERR_OK;
75 }
76 } // namespace AppExecFwk
77 } // namespace OHOS