1 /*
2  * Copyright (c) 2022 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_RECALIM_PRIORITY_CONSTANTS_H
17 #define OHOS_MEMORY_MEMMGR_RECALIM_PRIORITY_CONSTANTS_H
18 
19 namespace OHOS {
20 namespace Memory {
21 // system app
22 constexpr int RECLAIM_PRIORITY_SYSTEM = -1000;
23 // killable system app
24 constexpr int RECLAIM_PRIORITY_KILLABLE_SYSTEM = -800;
25 // foreground process priority
26 constexpr int RECLAIM_PRIORITY_FOREGROUND = 0;
27 // visible process priority
28 constexpr int RECLAIM_PRIORITY_VISIBLE = 50;
29 // perceived suspend delay case
30 constexpr int RECLAIM_PRIORITY_BG_SUSPEND_DELAY = 100;
31 // extension and a bg process bind to it
32 constexpr int RECLAIM_PRIORITY_FG_BIND_EXTENSION = 100;
33 // perceived background process priority
34 constexpr int RECLAIM_PRIORITY_BG_PERCEIVED = 200;
35 // extension and a bg process bind to it (reserved, now unsed)
36 constexpr int RECLAIM_PRIORITY_BG_BIND_EXTENSION = 240;
37 // background and connected by distribute device
38 constexpr int RECLAIM_PRIORITY_BG_DIST_DEVICE = 260;
39 // background priority
40 constexpr int RECLAIM_PRIORITY_BACKGROUND = 400;
41 // extension and no process bind to it
42 constexpr int RECLAIM_PRIORITY_NO_BIND_EXTENSION = 500;
43 // frozen process priority
44 constexpr int RECLAIM_PRIORITY_FROZEN = 600;
45 // suspend process priority
46 constexpr int RECLAIM_PRIORITY_SUSPEND = 800;
47 // empty process priority
48 constexpr int RECLAIM_PRIORITY_EMPTY = 900;
49 // unknown process priority
50 constexpr int RECLAIM_PRIORITY_UNKNOWN = 1000;
51 
52 constexpr int RECLAIM_PRIORITY_MIN = -1000;
53 constexpr int RECLAIM_PRIORITY_MAX = 1000;
54 
55 const int USER_ID_SHIFT = 200000;
GetOsAccountIdByUid(int bundleUid)56 inline int GetOsAccountIdByUid(int bundleUid)
57 {
58     return (bundleUid / USER_ID_SHIFT);
59 }
60 
61 constexpr int IGNORE_PID = -1;
62 constexpr int INVALID_TIME = -1;
63 
64 enum class AppStateUpdateReason {
65     CREATE_PROCESS = 0,
66     PROCESS_READY,
67     FOREGROUND,
68     BACKGROUND,
69     SUSPEND_DELAY_START,
70     SUSPEND_DELAY_END,
71     BACKGROUND_RUNNING_START,
72     BACKGROUND_RUNNING_END,
73     EVENT_START,
74     EVENT_END,
75     APPLICATION_SUSPEND,
76     PROCESS_TERMINATED,
77     OS_ACCOUNT_CHANGED,
78     DIST_DEVICE_CONNECTED,
79     DIST_DEVICE_DISCONNECTED,
80     BIND_EXTENSION,
81     UNBIND_EXTENSION,
82     VISIBLE,
83     UN_VISIBLE,
84     RENDER_CREATE_PROCESS,
85     ABILITY_START,
86 };
87 
88 enum class BundleState {
89     STATE_DEFAULT = 0,
90     STATE_WAITING_FOR_KILL,
91 };
92 
93 enum class MemMgrErrorCode {
94     MEMMGR_SERVICE_ERR = 190900,
95 };
96 } // namespace Memory
97 } // namespace OHOS
98 #endif // OHOS_MEMORY_MEMMGR_RECALIM_PRIORITY_CONSTANTS_H
99