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/strategy/refresh_control_mgr.h"
17
18 #include "fms_log_wrapper.h"
19 #include "common/util/form_trust_mgr.h"
20 #include "data_center/form_data_mgr.h"
21 #include "data_center/form_record/form_record_report.h"
22 #include "form_refresh/strategy/refresh_cache_mgr.h"
23 #ifdef SUPPORT_POWER
24 #include "power_mgr_client.h"
25 #endif
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 namespace {
30 constexpr char HICAR_FORM [] = "phone_hicar";
31 }
32
RefreshControlMgr()33 RefreshControlMgr::RefreshControlMgr() {}
~RefreshControlMgr()34 RefreshControlMgr::~RefreshControlMgr() {}
35
36 #ifdef RES_SCHEDULE_ENABLE
SetSystemOverloadFlag(bool flag)37 void RefreshControlMgr::SetSystemOverloadFlag(bool flag)
38 {
39 if (isSystemOverload_ && !flag) {
40 RefreshCacheMgr::GetInstance().ConsumeOverloadTaskQueue();
41 }
42
43 HILOG_INFO("isSystemOverload_:%{public}d, new flag:%{public}d", isSystemOverload_, flag);
44 isSystemOverload_ = flag;
45 }
46 #endif
47
IsSystemOverload()48 bool RefreshControlMgr::IsSystemOverload()
49 {
50 #ifdef RES_SCHEDULE_ENABLE
51 if (isSystemOverload_) {
52 HILOG_WARN("system overload");
53 }
54 return isSystemOverload_;
55 #endif
56 return false;
57 }
58
IsFormInvisible(const FormRecord & record)59 bool RefreshControlMgr::IsFormInvisible(const FormRecord &record)
60 {
61 if (record.formVisibleNotifyState != Constants::FORM_VISIBLE) {
62 HILOG_WARN("invisible formId:%{public}" PRId64, record.formId);
63 return true;
64 }
65 return false;
66 }
67
IsScreenOff(const FormRecord & record)68 bool RefreshControlMgr::IsScreenOff(const FormRecord &record)
69 {
70 #ifdef SUPPORT_POWER
71 bool screenOnFlag = PowerMgr::PowerMgrClient::GetInstance().IsScreenOn();
72 bool collaborationScreenOnFlag = PowerMgr::PowerMgrClient::GetInstance().IsCollaborationScreenOn();
73 bool isHicar = (record.moduleName == HICAR_FORM);
74 if (!screenOnFlag && !collaborationScreenOnFlag && !isHicar) {
75 HILOG_WARN("screen off contorl, formId:%{public}" PRId64, record.formId);
76 return true;
77 }
78 #endif
79 return false;
80 }
81
IsHealthyControl(const FormRecord & record)82 bool RefreshControlMgr::IsHealthyControl(const FormRecord &record)
83 {
84 if (!record.enableForm) {
85 HILOG_WARN("be healthy usage controlling, formId:%{public}" PRId64, record.formId);
86 return true;
87 }
88
89 return false;
90 }
91
IsNeedToFresh(FormRecord & record,bool isVisibleToFresh)92 bool RefreshControlMgr::IsNeedToFresh(FormRecord &record, bool isVisibleToFresh)
93 {
94 bool isEnableRefresh = FormDataMgr::GetInstance().IsEnableRefresh(record.formId);
95 HILOG_INFO("isEnableRefresh is %{public}d", isEnableRefresh);
96 if (isEnableRefresh) {
97 return true;
98 }
99 HILOG_INFO("isVisibleToFresh is %{public}d, record.isVisible is %{public}d", isVisibleToFresh, record.isVisible);
100 if (isVisibleToFresh) {
101 if (!record.isVisible) {
102 FormRecordReport::GetInstance().IncreaseUpdateTimes(record.formId,
103 HiSysEventPointType::TYPE_INVISIBLE_INTERCEPT);
104 }
105 return record.isVisible;
106 }
107 bool isEnableUpdate = FormDataMgr::GetInstance().IsEnableUpdate(record.formId);
108 HILOG_INFO("isEnableUpdate is %{public}d", isEnableUpdate);
109 return isEnableUpdate;
110 }
111
112 } // namespace AppExecFwk
113 } // namespace OHOS