1 /*
2  * Copyright (c) 2022-2023 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_MEMORY_MEMMGR_PROCESS_PRIORITY_INFO_H
17 #define OHOS_MEMORY_MEMMGR_PROCESS_PRIORITY_INFO_H
18 
19 #include <set>
20 #include <string>
21 #include <map>
22 
23 #include "reclaim_strategy_constants.h"
24 
25 namespace OHOS {
26 namespace Memory {
27 constexpr int EXTENSION_STATUS_BIND_UNKOWN = 0;
28 constexpr int EXTENSION_STATUS_FG_BIND = 1;
29 constexpr int EXTENSION_STATUS_BG_BIND = 2;
30 constexpr int EXTENSION_STATUS_NO_BIND = 3;
31 const std::string DEFAULT_PROCESS_NAME = "";
32 
33 class ProcessPriorityInfo {
34 public:
35     explicit ProcessPriorityInfo(pid_t pid, int bundleUid, int priority, bool isImportant = false);
36     ProcessPriorityInfo(const ProcessPriorityInfo &copyProcess);
37     ~ProcessPriorityInfo();
38 
39     int uid_;
40     pid_t pid_;
41     int priority_;
42     int priorityIfImportant_; // only enable when configured in xml, and should not be changed after read from xml
43     bool isImportant_; // true means important background, false means normal background
44     bool isVisible_;
45     bool isRender_;
46     bool isFreground; // true means freground, false means background
47     bool isBackgroundRunning;
48     bool isSuspendDelay;
49     bool isEventStart;
50     bool isDistDeviceConnected;
51     bool isExtension_;
52     int extensionBindStatus; // 0: unkown, 1:fg bind, 2:bg bind, 3:no bind
53     std::map<int32_t, int32_t> procsBindToMe_;
54     std::map<int32_t, int32_t> procsBindFromMe_;
55 
56     void SetPriority(int targetPriority);
57     int32_t ExtensionConnectorsCount();
58 
59     void ProcBindToMe(int32_t pid, int32_t uid);
60     void ProcUnBindToMe(int32_t pid);
61 
62     void ProcBindFromMe(int32_t pid, int32_t uid);
63     void ProcUnBindFromMe(int32_t pid);
64 
65     std::string ProcsBindToMe();
66     std::string ProcsBindFromMe();
67 
68     bool IsAbilityStarting() const;
69     void SetIsAbilityStarting(bool isAbilityStarting); // use to set value of isAbilityStarting_
70 
71     void SetStartingAbilityTime(int64_t time);
72     int64_t GetStartingAbilityTime() const;
73 
74 private:
75     bool isAbilityStarting_; // true means proc current is starting ability, false means not
76     int64_t startingAbilityTime_;
77 };
78 } // namespace Memory
79 } // namespace OHOS
80 #endif // OHOS_MEMORY_MEMMGR_PROCESS_PRIORITY_INFO_H
81