• 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_next_time_refresh_impl.h"
17 
18 #include "form_refresh/strategy/refresh_check_mgr.h"
19 #include "common/timer_mgr/form_timer_mgr.h"
20 #include "data_center/form_record/form_record_report.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
24 
FormNextTimeRefreshImpl()25 FormNextTimeRefreshImpl::FormNextTimeRefreshImpl() {}
~FormNextTimeRefreshImpl()26 FormNextTimeRefreshImpl::~FormNextTimeRefreshImpl() {}
27 
RefreshFormRequest(RefreshData & data)28 int FormNextTimeRefreshImpl::RefreshFormRequest(RefreshData &data)
29 {
30     const std::vector<int32_t> checkTypes = {
31         TYPE_UNTRUST_APP, TYPE_ACTIVE_USER, TYPE_CALLING_BUNDLE, TYPE_ADD_FINISH
32     };
33     CheckValidFactor factor;
34     factor.formId = data.formId;
35     factor.record = data.record;
36     int32_t userId = FormUtil::GetCurrentAccountId();
37     Want reqWant;
38     reqWant.SetParam(Constants::PARAM_FORM_USER_ID, userId);
39     factor.want = reqWant;
40     int ret = RefreshCheckMgr::GetInstance().IsBaseValidPass(checkTypes, factor);
41     if (ret != ERR_OK) {
42         return ret;
43     }
44 
45     if (data.nextTime < 0) {
46         HILOG_ERROR("nextTime is negative, formId:%{public}" PRId64, data.formId);
47         return ERR_APPEXECFWK_FORM_COMMON_CODE;
48     }
49 
50     const int32_t MAX_NEXT_TIME = INT32_MAX / Constants::SEC_PER_MIN;
51     if (data.nextTime > MAX_NEXT_TIME) {
52         HILOG_ERROR("nextTime exceeds safety range, formId:%{public}" PRId64, data.formId);
53         return ERR_APPEXECFWK_FORM_COMMON_CODE;
54     }
55 
56     if (data.record.isDataProxy) {
57         HILOG_INFO("data proxy form set next refresh time formId:%{public}" PRId64, data.formId);
58     }
59 
60     int32_t timerRefreshedCount = FormTimerMgr::GetInstance().GetRefreshCount(data.formId);
61     if (timerRefreshedCount >= Constants::LIMIT_COUNT) {
62         HILOG_WARN("already reach max times:%{public}d, formId:%{public}" PRId64, timerRefreshedCount, data.formId);
63         FormRecordReport::GetInstance().IncreaseUpdateTimes(data.formId, HiSysEventPointType::TYPE_HIGH_FREQUENCY);
64         FormTimerMgr::GetInstance().MarkRemind(data.formId);
65         return ERR_APPEXECFWK_FORM_MAX_REFRESH;
66     }
67 
68     int64_t safeNextTime = static_cast<int64_t>(data.nextTime) * Constants::SEC_PER_MIN;
69     if (!FormTimerMgr::GetInstance().SetNextRefreshTime(data.formId, safeNextTime, userId)) {
70         HILOG_ERROR("set next time refresh failed, formId:%{public}" PRId64, data.formId);
71         return ERR_APPEXECFWK_FORM_COMMON_CODE;
72     }
73 
74     return ERR_OK;
75 }
76 } // namespace AppExecFwk
77 } // namespace OHOS