• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 #ifndef RESSCHED_PLUGINS_SOCPERF_PLUGIN_INCLUDE_SOCPERF_PLUGIN_H
17 #define RESSCHED_PLUGINS_SOCPERF_PLUGIN_INCLUDE_SOCPERF_PLUGIN_H
18 #ifdef RESSCHED_RESOURCESCHEDULE_SOC_PERF_ENABLE
19 #include <set>
20 #include <unordered_map>
21 #include <mutex>
22 #include "ffrt.h"
23 #include "plugin.h"
24 #include "single_instance.h"
25 #include "socperf_client.h"
26 #include <string>
27 #include <sstream>
28 
29 namespace OHOS {
30 namespace ResourceSchedule {
31 class AppKeyMessage {
32 private:
33     int32_t appType;
34     std::string bundleName;
35 
36 public:
37     AppKeyMessage(int32_t appType = 0,
appType(appType)38         const std::string& bundleName = "") : appType(appType), bundleName(bundleName) {}
39 
GetAppType()40     int32_t GetAppType() const
41     {
42         return appType;
43     }
44 
setAppType(int32_t newAppType)45     void setAppType(int32_t newAppType)
46     {
47         appType = newAppType;
48     }
49 
GetBundleName()50     std::string GetBundleName() const
51     {
52         return bundleName;
53     }
54 
setBundleName(const std::string & newBundleName)55     void setBundleName(const std::string& newBundleName)
56     {
57         bundleName = newBundleName;
58     }
59 };
60 
61 class SocPerfPlugin : public Plugin {
62     DECLARE_SINGLE_INSTANCE(SocPerfPlugin)
63 
64 public:
65     void Init() override;
66 
67     void Disable() override;
68 
69     void DispatchResource(const std::shared_ptr<ResData>& resData) override;
70 
71 private:
72     using ReqAppTypeFunc = int32_t (*)(const std::string &bundleName);
73     std::set<uint32_t> resTypes;
74     std::set<int32_t> focusAppUids_;
75     bool weakActionStatus_ = true;
76     std::set<std::string> keyAppName_;
77     std::set<int32_t> keyAppType_;
78     // app names set which use camera
79     std::set<std::string> appNameUseCamera_;
80     std::unordered_map<uint32_t, std::function<void(const std::shared_ptr<ResData>& data)>> functionMap;
81     // app's uid match app
82     std::map<int32_t, AppKeyMessage> uidToAppMsgMap_;
83     // app's pid match app type
84     std::map<int32_t, int32_t> pidToAppTypeMap_;
85     std::string perfReqAppTypeSoPath_;
86     std::string perfReqAppTypeSoFunc_;
87     bool isFocusAppsGameType_ = false;
88     int64_t screenStatus_;
89     std::string deviceMode_;
90     ffrt::mutex screenMutex_;
91     void* handle_ = nullptr;
92     ReqAppTypeFunc reqAppTypeFunc_ = nullptr;
93     int32_t RES_TYPE_SCENE_BOARD_ID = 0;
94     int32_t RES_TYPE_RGM_BOOTING_STATUS = 0;
95     bool socperfGameBoostSwitch_ = false;
96     void InitEventId();
97     void InitFunctionMap();
98     void AddEventToFunctionMap();
99     void AddOtherEventToFunctionMap();
100     void InitResTypes();
101     void InitOtherResTypes();
102     void InitPerfCrucialSo();
103     void InitWeakInterAction();
104     void AddKeyAppName(const std::string& subValue);
105     void AddKeyAppType(const std::string& subValue);
106     void UpdateWeakActionStatus();
107     void InitPerfCrucialFunc(const char* perfSoPath, const char* perfSoFunc);
108     void HandleWindowFocus(const std::shared_ptr<ResData>& data);
109     void HandleEventClick(const std::shared_ptr<ResData>& data);
110     void HandleEventKey(const std::shared_ptr<ResData>& data);
111 #ifdef RESSCHED_RESOURCESCHEDULE_CROWN_POWER_KEY_ENABLE
112     void HandlePowerEventKey(const std::shared_ptr<ResData>& data);
113     void HandleCrownRotation(const std::shared_ptr<ResData>& data);
114 #endif // RESSCHED_RESOURCESCHEDULE_CROWN_POWER_KEY_ENABLE
115     void HandleLoadPage(const std::shared_ptr<ResData>& data);
116     void HandlePopPage(const std::shared_ptr<ResData>& data);
117     void HandleEventSlide(const std::shared_ptr<ResData>& data);
118     void HandleEventWebGesture(const std::shared_ptr<ResData>& data);
119     void HandleAppAbilityStart(const std::shared_ptr<ResData>& data);
120     void HandleResizeWindow(const std::shared_ptr<ResData>& data);
121     void HandleMoveWindow(const std::shared_ptr<ResData>& data);
122     void HandleRemoteAnimation(const std::shared_ptr<ResData>& data);
123     bool InitFeatureSwitch(std::string featureName);
124     void HandleDragStatusBar(const std::shared_ptr<ResData>& data);
125     void HandleWebGestureMove(const std::shared_ptr<ResData>& data);
126     void HandleWebSlideNormal(const std::shared_ptr<ResData>& data);
127     void HandleLoadUrl(const std::shared_ptr<ResData>& data);
128     void HandleMousewheel(const std::shared_ptr<ResData>& data);
129     bool HandleAppStateChange(const std::shared_ptr<ResData>& data);
130     bool HandleSocperfSceneBoard(const std::shared_ptr<ResData>& data);
131     void HandleDeviceModeStatusChange(const std::shared_ptr<ResData>& data);
132     bool HandleSocperfAccountActivating(const std::shared_ptr<ResData> &data);
133 #ifdef RESSCHED_RESOURCESCHEDULE_CUST_SOC_PERF_ENABLE
134     bool HandleCustEvent(const std::shared_ptr<ResData>& data);
135     bool HandleCustEventBegin(const std::shared_ptr<ResData>& data);
136     bool HandleCustEventEnd(const std::shared_ptr<ResData>& data);
137 #endif // RESSCHED_RESOURCESCHEDULE_CUST_SOC_PERF_ENABLE
138     bool HandleRgmBootingStatus(const std::shared_ptr<ResData>& data);
139     bool HandleAppColdStartEx(const std::shared_ptr<ResData>& data);
140     bool HandleSceneRotation(const std::shared_ptr<ResData>& data);
141     bool HandleBmmMoniterStatus(const std::shared_ptr<ResData>& data);
142     bool HandlePowerModeChanged(const std::shared_ptr<ResData>& data);
143     bool HandleScreenStatusAnalysis(const std::shared_ptr<ResData>& data);
144     bool HandleGameBoost(const std::shared_ptr<ResData>& data);
145     bool UpdateFocusAppType(const std::shared_ptr<ResData>& data, bool focusStatus);
146     bool HandleUninstallEvent(const std::shared_ptr<ResData>& data);
147     bool UpdateUidToAppMsgMap(const std::shared_ptr<ResData>& data);
148     bool UpdateUidToAppMsgMap(const std::shared_ptr<ResData>& data, const int32_t appType,
149         const std::string& bundleName);
150     bool IsFocusAppsAllGame();
151     bool UpdatesFocusAppsType(int32_t appType);
152     bool HandleDeadProcess(const std::shared_ptr<ResData>& data);
153     bool IsGameEvent(const std::shared_ptr<ResData>& data);
154     bool HandleProcessStateChange(const std::shared_ptr<ResData> &data);
155     bool HandleCameraStateChange(const std::shared_ptr<ResData> &data);
156     bool InitBundleNameBoostList();
157     bool HandleSubValue(const std::string& subValue);
158     bool IsAllowBoostScene();
159     bool HandleRecentBuild(const std::shared_ptr<ResData>& data);
160     int32_t GetPidByData(const std::shared_ptr<ResData>& data, const std::string& key);
161     int32_t GetUidByData(const std::shared_ptr<ResData>& data);
162     void HandleScreenOn();
163     void HandleScreenOff();
164     std::string GetBundleNameByUid(const int32_t uid);
165     void HandleWebDragResize(const std::shared_ptr<ResData>& data);
166 #ifdef RESSCHED_RESOURCESCHEDULE_FILE_COPY_SOC_PERF_ENABLE
167     bool HandleFileCopyStatus(const std::shared_ptr<ResData>& data);
168 #endif
169 };
170 } // namespace ResourceSchedule
171 } // namespace OHOS
172 
173 #endif //RESSCHED_RESOURCESCHEDULE_SOC_PERF_ENABLE
174 #endif // RESSCHED_PLUGINS_SOCPERF_PLUGIN_INCLUDE_SOCPERF_PLUGIN_H
175