• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace {
29 constexpr int32_t INTENT_EXEMPTION_DURATION = 10000;
30 }
31 using AbilityInfo = AppExecFwk::AbilityInfo;
32 constexpr int64_t RES_TYPE_SCB_START_ABILITY = 0;
33 constexpr int64_t RES_TYPE_EXTENSION_START_ABILITY = 1;
34 constexpr int64_t RES_TYPE_MISSION_LIST_START_ABILITY = 2;
35 
36 enum class LoadingStage : int32_t {
37     LOAD_BEGIN = 1,
38     LOAD_END,
39     FOREGROUND_BEGIN,
40     FOREGROUND_END,
41     CONNECT_BEGIN,
42     CONNECT_END,
43     DESTROY_BEGIN = 8,
44     DESTROY_END = 9,
45     PRELOAD_BEGIN,
46     PRELOAD_END,
47 };
48 
49 class ResSchedUtil final {
50 public:
51     static ResSchedUtil &GetInstance();
52     void ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart,
53         bool supportWarmSmartGC);
54     void ReportPreloadApplicationToRSS(const std::shared_ptr<AbilityInfo>& abilityInfo, int32_t preloadMode);
55     void ReportAbilityAssociatedStartInfoToRSS(
56         const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid);
57     void ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason,
58         const int32_t pid = -1, const int32_t callerPid = -1);
59     std::string GetThawReasonByAbilityType(const AbilityInfo &abilityInfo);
60     void GetAllFrozenPidsFromRSS(std::unordered_set<int32_t> &frozenPids);
61     bool CheckShouldForceKillProcess(int32_t pid, const std::string& bundleName);
62     void ReportLoadingEventToRss(LoadingStage stage, int32_t pid, int32_t uid,
63         int64_t timeDuration = 0, int64_t abilityRecordId = -1);
64     std::unordered_set<std::string> GetNWebPreloadSet() const;
65     void ReportAbilityIntentExemptionInfoToRSS(int32_t callerUid, int32_t callerPid);
66     void ReportSubHealtyPerfInfoToRSS();
67 private:
68     ResSchedUtil() = default;
69     ~ResSchedUtil() = default;
70     DISALLOW_COPY_AND_MOVE(ResSchedUtil);
71 
72     int64_t convertType(int64_t resSchedType);
73 };
74 } // namespace AAFwk
75 } // namespace OHOS
76 
77 #endif // OHOS_ABILITY_RUNTIME_RES_SCHED_UTIL_H
78