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_SERVICES_RESSCHEDSERVICE_INCLUDE_RES_SCHED_SERVICE_STUB_H 17 #define RESSCHED_SERVICES_RESSCHEDSERVICE_INCLUDE_RES_SCHED_SERVICE_STUB_H 18 19 #include <cstdint> 20 #include <map> 21 #include <unordered_set> 22 #include "iremote_stub.h" 23 #include "ires_sched_service.h" 24 #include "res_type.h" 25 #include <atomic> 26 #include <mutex> 27 28 namespace OHOS { 29 namespace ResourceSchedule { 30 class ResSchedServiceStub : public IRemoteStub<IResSchedService> { 31 public: 32 ResSchedServiceStub(); 33 ~ResSchedServiceStub(); 34 DISALLOW_COPY_AND_MOVE(ResSchedServiceStub); 35 int32_t OnRemoteRequest( 36 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 37 38 private: 39 int32_t ReportDataInner(MessageParcel& data, MessageParcel& reply); 40 int32_t ReportSyncEventInner(MessageParcel& data, MessageParcel& reply); 41 int32_t ParseAndCheckReportDataParcel(MessageParcel& data, uint32_t& type, int64_t& value, std::string& payload); 42 int32_t KillProcessInner(MessageParcel& data, MessageParcel& reply); 43 void RegisterSystemloadNotifierInner(MessageParcel& data, MessageParcel& reply); 44 void UnRegisterSystemloadNotifierInner(MessageParcel& data, MessageParcel& reply); 45 void RegisterEventListenerInner(MessageParcel& data, MessageParcel& reply); 46 void UnRegisterEventListenerInner(MessageParcel& data, MessageParcel& reply); 47 int32_t GetSystemloadLevelInner(MessageParcel& data, MessageParcel& reply); 48 bool IsAllowedAppPreloadInner(MessageParcel& data, MessageParcel& reply); 49 nlohmann::json StringToJsonObj(const std::string& str); 50 bool IsLimitRequest(int32_t uid); 51 void CheckAndUpdateLimitData(int64_t nowTime); 52 void PrintLimitLog(int32_t uid); 53 void ReportBigData(); 54 void InreaseBigDataCount(); 55 void Init(); 56 57 using RequestFuncType = std::function<int32_t (MessageParcel& data, MessageParcel& reply)>; 58 std::map<uint32_t, RequestFuncType> funcMap_; 59 std::map<int32_t, int32_t> appRequestCountMap_; 60 std::atomic<int32_t> allRequestCount_ {0}; 61 std::atomic<int32_t> bigDataReportCount_ {0}; 62 std::atomic<int64_t> nextCheckTime_ = {0}; 63 std::atomic<int64_t> nextReportBigDataTime_ = {0}; 64 std::atomic<bool> isReportBigData_ = {false}; 65 std::atomic<bool> isPrintLimitLog_ = {true}; 66 std::mutex mutex_; 67 }; 68 } // namespace ResourceSchedule 69 } // namespace OHOS 70 71 #endif // RESSCHED_SERVICES_RESSCHEDSERVICE_INCLUDE_RES_SCHED_SERVICE_STUB_H 72