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 CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H 17 #define CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H 18 19 #include <unordered_set> 20 #include <list> 21 #include <mutex> 22 #include <unordered_map> 23 #include <vector> 24 #include "json/json.h" 25 #include "concurrent_task_type.h" 26 #include "qos_manager.h" 27 28 namespace OHOS { 29 namespace ConcurrentTask { 30 class ForegroundAppRecord; 31 32 class TaskController { 33 public: 34 static TaskController& GetInstance(); 35 TaskController() = default; 36 virtual ~TaskController() = default; 37 void ReportData(uint32_t resType, int64_t value, const Json::Value& payload); 38 void QueryInterval(int queryItem, IntervalReply& queryRs); 39 void Init(); 40 void Release(); 41 42 private: 43 bool CheckUid(pid_t uid); 44 void TypeMapInit(); 45 void QosApplyInit(); 46 void SetHwcAuth(bool status); 47 void TryCreateRsGroup(); 48 void QueryUi(pid_t uid, IntervalReply& queryRs); 49 void QueryRender(pid_t uid, IntervalReply& queryRs); 50 void QueryRenderService(pid_t uid, IntervalReply& queryRs); 51 void QueryHwc(pid_t uid, IntervalReply& queryRs); 52 int GetRequestType(std::string strRequstType); 53 void DealSystemRequest(int requestType, const Json::Value& payload); 54 void DealAppRequest(int requestType, const Json::Value& payload, pid_t uid); 55 void NewForeground(int uid); 56 void NewBackground(int uid); 57 void NewAppStart(int uid); 58 void AppKilled(int uid); 59 std::list<ForegroundAppRecord>::iterator GetRecordOfUid(int uid); 60 void PrintInfo(); 61 62 std::mutex appInfoLock_; 63 std::list<ForegroundAppRecord> foregroundApp_ = {}; 64 std::unordered_map<std::string, int> msgType_ = {}; 65 QosManager qosManager_; 66 std::vector<int> authApps_; 67 int renderServiceGrpId_ = -1; 68 bool rtgEnabled_ = false; 69 }; 70 71 class ForegroundAppRecord { 72 public: 73 explicit ForegroundAppRecord(int uid); 74 ~ForegroundAppRecord(); 75 76 void AddKeyThread(int tid, int prio = PRIO_NORMAL); 77 bool BeginScene(); 78 bool EndScene(); 79 int GetUid(); 80 int GetGrpId(); 81 bool IsValid(); 82 void PrintKeyThreads(); 83 84 private: 85 int uid_ = 0; 86 int grpId_ = 0; 87 std::unordered_set<int> keyThreads_; 88 }; 89 } // namespace ConcurrentTask 90 } // namespace OHOS 91 92 #endif // CONCURRENT_TASK_SERVICES_CONCURRENTSEVICE_INCLUDE_CONCURRENT_TASK_CONTROLLER_H