• 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_app_upgrade_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 #include "data_center/form_cache_mgr.h"
25 #include "form_mgr/form_mgr_adapter.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 
FormAppUpgradeRefreshImpl()30 FormAppUpgradeRefreshImpl::FormAppUpgradeRefreshImpl() {}
~FormAppUpgradeRefreshImpl()31 FormAppUpgradeRefreshImpl::~FormAppUpgradeRefreshImpl() {}
32 
RefreshFormRequest(RefreshData & data)33 int FormAppUpgradeRefreshImpl::RefreshFormRequest(RefreshData &data)
34 {
35     const std::vector<int32_t> checkTypes = { TYPE_UNTRUST_APP, TYPE_ACTIVE_USER, TYPE_ADD_FINISH };
36     CheckValidFactor factor;
37     factor.formId = data.formId;
38     factor.record = data.record;
39     factor.callerToken = data.callerToken;
40     Want reqWant(data.want);
41     factor.want = reqWant;
42     int ret = RefreshCheckMgr::GetInstance().IsBaseValidPass(checkTypes, factor);
43     if (ret != ERR_OK) {
44         return ret;
45     }
46 
47     if (RefreshControlMgr::GetInstance().IsHealthyControl(data.record)) {
48         RefreshCacheMgr::GetInstance().AddFlagByHealthyControl(data.formId, true);
49         return ERR_OK;
50     }
51 
52     if (!RefreshControlMgr::GetInstance().IsNeedToFresh(data.record, true)) {
53         FormDataMgr::GetInstance().SetNeedRefresh(data.formId, true);
54         return ERR_OK;
55     }
56 
57     if (data.record.isDataProxy) {
58         FormProviderData formProviderData;
59         std::string cacheData;
60         std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> imageDataMap;
61         if (FormCacheMgr::GetInstance().GetData(data.formId, cacheData, imageDataMap)) {
62             formProviderData.SetDataString(cacheData);
63             formProviderData.SetImageDataMap(imageDataMap);
64             FormMgrAdapter::GetInstance().UpdateForm(data.formId, data.record.uid, formProviderData);
65         }
66         HILOG_INFO("Upgrade APP data agent card update, cacheData: %{public}zu, formId:%{public}" PRId64,
67             cacheData.size(), data.formId);
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