• 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_net_conn_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 
FormNetConnRefreshImpl()28 FormNetConnRefreshImpl::FormNetConnRefreshImpl() {}
~FormNetConnRefreshImpl()29 FormNetConnRefreshImpl::~FormNetConnRefreshImpl() {}
30 
RefreshFormRequest(RefreshData & data)31 int FormNetConnRefreshImpl::RefreshFormRequest(RefreshData &data)
32 {
33     const std::vector<int32_t> checkTypes = { TYPE_UNTRUST_APP, TYPE_SYSTEM_APP, TYPE_ACTIVE_USER, TYPE_ADD_FINISH };
34     CheckValidFactor factor;
35     factor.formId = data.formId;
36     factor.record = data.record;
37     Want reqWant;
38     reqWant.SetParam(Constants::PARAM_FORM_USER_ID, FormUtil::GetCurrentAccountId());
39     factor.want = reqWant;
40     int ret = RefreshCheckMgr::GetInstance().IsBaseValidPass(checkTypes, factor);
41     if (ret != ERR_OK) {
42         return ret;
43     }
44 
45     if (RefreshControlMgr::GetInstance().IsHealthyControl(data.record)) {
46         RefreshCacheMgr::GetInstance().AddFlagByHealthyControl(data.formId, true);
47         return ERR_OK;
48     }
49 
50     FormDataMgr::GetInstance().SetTimerRefresh(data.formId, true);
51     if (RefreshControlMgr::GetInstance().IsFormInvisible(data.record)) {
52         RefreshCacheMgr::GetInstance().AddFlagByInvisible(data.formId, Constants::REFRESHTYPE_NETWORKCHANGED);
53         return ERR_OK;
54     }
55 
56     if (data.record.isSystemApp) {
57         reqWant.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_NETWORKCHANGED);
58     }
59 
60     if (RefreshControlMgr::GetInstance().IsScreenOff(data.record)) {
61         RefreshCacheMgr::GetInstance().AddFlagByScreenOff(data.formId, data.want, data.record);
62         return ERR_OK;
63     }
64 
65     if (!RefreshControlMgr::GetInstance().IsNeedToFresh(data.record, true)) {
66         FormDataMgr::GetInstance().SetNeedRefresh(data.formId, true);
67         return ERR_OK;
68     }
69 
70     FormRecord refreshRecord = FormDataMgr::GetInstance().GetFormAbilityInfo(data.record);
71     ret = RefreshExecMgr::AskForProviderData(data.formId, refreshRecord, reqWant);
72     if (ret != ERR_OK) {
73         HILOG_ERROR("ask for provider data failed, ret:%{public}d, formId:%{public}" PRId64, ret, data.formId);
74         return ret;
75     }
76 
77     return ERR_OK;
78 }
79 } // namespace AppExecFwk
80 } // namespace OHOS