1 /* 2 * Copyright (c) 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 OHOS_ABILITY_RUNTIME_RES_SCHED_UTIL_H 17 #define OHOS_ABILITY_RUNTIME_RES_SCHED_UTIL_H 18 19 #include <unordered_set> 20 21 #include "nocopyable.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 struct AbilityInfo; 26 } 27 namespace AAFwk { 28 using AbilityInfo = AppExecFwk::AbilityInfo; 29 constexpr int64_t RES_TYPE_SCB_START_ABILITY = 0; 30 constexpr int64_t RES_TYPE_EXTENSION_START_ABILITY = 1; 31 constexpr int64_t RES_TYPE_MISSION_LIST_START_ABILITY = 2; 32 33 enum class LoadingStage : int32_t { 34 LOAD_BEGIN = 1, 35 LOAD_END, 36 FOREGROUND_BEGIN, 37 FOREGROUND_END, 38 }; 39 40 class ResSchedUtil final { 41 public: 42 static ResSchedUtil &GetInstance(); 43 void ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart); 44 void ReportAbilityAssociatedStartInfoToRSS( 45 const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid); 46 void ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason, 47 const int32_t callerPid = -1); 48 void GetAllFrozenPidsFromRSS(std::unordered_set<int32_t> &frozenPids); 49 bool CheckShouldForceKillProcess(int32_t pid); 50 void ReportLoadingEventToRss(LoadingStage stage, int32_t pid, int32_t uid, 51 int64_t timeDuration = 0, int64_t abilityRecordId = -1); 52 std::unordered_set<std::string> GetNWebPreloadSet() const; 53 private: 54 ResSchedUtil() = default; 55 ~ResSchedUtil() = default; 56 DISALLOW_COPY_AND_MOVE(ResSchedUtil); 57 58 int64_t convertType(int64_t resSchedType); 59 }; 60 } // namespace AAFwk 61 } // namespace OHOS 62 63 #endif // OHOS_ABILITY_RUNTIME_RES_SCHED_UTIL_H