• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RECLAIM_STRATEGY_RECLAIM_PARAM_H
17 #define OHOS_MEMORY_MEMMGR_RECLAIM_STRATEGY_RECLAIM_PARAM_H
18 
19 #include <sys/types.h>
20 
21 #include <string>
22 
23 namespace OHOS {
24 namespace Memory {
25 enum class AppAction {
26     CREATE_PROCESS_AND_APP = 0,
27     CREATE_PROCESS_ONLY = 1,
28     APP_DIED = 2,
29     APP_FOREGROUND = 3,
30     APP_BACKGROUND = 4,
31     OTHERS = 5,
32 };
33 
34 const std::map<int, std::string> appActionStrMap_ = {
35     { static_cast<int32_t>(AppAction::CREATE_PROCESS_AND_APP), "CREATE_PROCESS_AND_APP" },
36     { static_cast<int32_t>(AppAction::CREATE_PROCESS_ONLY), "CREATE_PROCESS_ONLY" },
37     { static_cast<int32_t>(AppAction::APP_DIED), "APP_DIED" },
38     { static_cast<int32_t>(AppAction::APP_FOREGROUND), "APP_FOREGROUND" },
39     { static_cast<int32_t>(AppAction::APP_BACKGROUND), "APP_BACKGROUND" },
40     { static_cast<int32_t>(AppAction::OTHERS), "OTHERS" },
41 };
42 
43 class ReclaimParam {
44 public:
45     pid_t pid_;
46     int bundleUid_;
47     std::string bundleName_;
48     int accountId_;
49     int score_;
50     AppAction action_;
51 
ReclaimParam(pid_t pid,int bundleUid,std::string bundleName,int accountId,int score,AppAction action)52     ReclaimParam(pid_t pid, int bundleUid, std::string bundleName, int accountId, int score, AppAction action)
53         : pid_(pid),
54           bundleUid_(bundleUid),
55           bundleName_(bundleName),
56           accountId_(accountId),
57           score_(score),
58           action_(action) {}
59 
GetAppActionStr(const AppAction action)60     static std::string GetAppActionStr(const AppAction action)
61     {
62         auto pair = appActionStrMap_.find(static_cast<int32_t>(action));
63         if (pair == appActionStrMap_.end()) {
64             return "none"; // none means no such action
65         }
66         return pair->second;
67     }
68 
ToString()69     inline std::string ToString() const
70     {
71         std::string ret = "pid:" + std::to_string(pid_)
72                         + " bundle:" + std::to_string(bundleUid_)
73                         + " " + bundleName_
74                         + " userId:" + std::to_string(accountId_)
75                         + " score:" + std::to_string(score_)
76                         + " action:" + GetAppActionStr(action_);
77         return ret;
78     }
79 
80     ReclaimParam() = delete;
81     ReclaimParam(const ReclaimParam&) = delete;
82     ReclaimParam& operator=(const ReclaimParam&) = delete;
83     ReclaimParam(ReclaimParam&&) = delete;
84     ReclaimParam& operator=(ReclaimParam&&) = delete;
85 }; // end class ReclaimParam
86 } // namespace Memory
87 } // namespace OHOS
88 #endif // OHOS_MEMORY_MEMMGR_RECLAIM_STRATEGY_RECLAIM_PARAM_H
89