1 /*
2  * Copyright (c) 2022 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 INTELLI_SENSE_SERVER_H
17 #define INTELLI_SENSE_SERVER_H
18 
19 #include <map>
20 #include <list>
21 #include <string>
22 #include <vector>
23 #include <set>
24 #include <cstdint>
25 #include <iosfwd>
26 #include "rme_constants.h"
27 #include "single_instance.h"
28 #include "app_info.h"
29 
30 namespace OHOS {
31 namespace RME {
32 using namespace std;
33 
34 class IntelliSenseServer {
35     DECLARE_SINGLE_INSTANCE(IntelliSenseServer);
36 public:
37     void Init();
38     void ReportAppInfo(const int pid, const int uid, const std::string bundleName, ThreadState state);
39     void ReportProcessInfo(const int pid, const int uid, const std::string bundleName, ThreadState state);
40     void ReportCgroupChange(const int pid, const int uid, const int oldGroup, const int newGroup);
41     void ReportWindowFocus(const int pid, const int uid, int isFocus);
42     void ReportRenderThread(const int pid, const int uid, int renderTid);
43     void ReportContinuousTask(const int pid, const int uid, const int status);
44     bool ReadXml();
45     void SetPara(const int32_t currentFps, const int32_t currentRenderType);
46 
47 private:
48     void NewForeground(int pid, int uid);
49     void NewBackground(int pid);
50     void NewDiedProcess(int pid);
51     void NewAppRecord(int pid, int uid);
52     void AuthAppKilled(int pid);
53     void AuthForeground(int pid);
54     void AuthBackground(int pid);
55     int TryCreateRtgForApp(AppInfo *app);
56     int CreateNewRtgGrp(int prioType = 0, int rtNum = 0);
57     inline CgroupPolicy CheckCgroupState(const CgroupPolicy cgroup);
58     std::list<AppInfo>::iterator GetRecordOfPid(int pid);
59     std::list<AppInfo> m_historyApp = {};
60     std::set<std::string> m_unsupportApp = {};
61     std::map<std::string, std::string> m_generalPara {};
62     std::map<std::string, std::map<std::string, int>> m_subEventPara {};
63     std::vector<int> m_fpsList {};
64     std::vector<int> m_renderTypeList {};
65     bool m_readXmlSuc = false;
66     bool m_needReadXml = true;
67     bool m_switch = false;
68 };
69 } // namespace RME
70 } // namesapce OHOS
71 #endif
72