• 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 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     DESTROY_BEGIN = 8,
39     DESTROY_END = 9,
40     PRELOAD_BEGIN,
41     CONNECT_BEGIN,
42     CONNECT_END
43 };
44 
45 class ResSchedUtil final {
46 public:
47     static ResSchedUtil &GetInstance();
48     void ReportAbilityStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart);
49     void ReportAbilityAssociatedStartInfoToRSS(
50         const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid);
51     bool NeedReportByPidWhenConnect(const AbilityInfo &abilityInfo);
52     void ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason,
53         const int32_t pid = -1, const int32_t callerPid = -1);
54     std::string GetThawReasonByAbilityType(const AbilityInfo &abilityInfo);
55     void GetAllFrozenPidsFromRSS(std::unordered_set<int32_t> &frozenPids);
56     bool CheckShouldForceKillProcess(int32_t pid);
57     void ReportLoadingEventToRss(LoadingStage stage, int32_t pid, int32_t uid,
58         int64_t timeDuration = 0, int64_t abilityRecordId = -1);
59     std::unordered_set<std::string> GetNWebPreloadSet() const;
60 private:
61     ResSchedUtil() = default;
62     ~ResSchedUtil() = default;
63     DISALLOW_COPY_AND_MOVE(ResSchedUtil);
64 
65     int64_t convertType(int64_t resSchedType);
66 };
67 } // namespace AAFwk
68 } // namespace OHOS
69 
70 #endif // OHOS_ABILITY_RUNTIME_RES_SCHED_UTIL_H