1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PROCESS_INFO_INTERFACE_H_
18 #define PROCESS_INFO_INTERFACE_H_
19 
20 #include <vector>
21 #include <utils/RefBase.h>
22 
23 namespace android {
24 
25 struct ProcessInfoInterface : public RefBase {
26     /*
27      * Gets the priority of the process (with given pid) as oom score.
28      *
29      * @param[in] pid pid of the process.
30      * @param[out] priority of the process.
31      *
32      * @return true for successful return and false otherwise.
33      */
34     virtual bool getPriority(int pid, int* priority) = 0;
35     /*
36      * Check whether the given pid is trusted or not.
37      *
38      * @param[in] pid pid of the process.
39      *
40      * @return true for trusted process and false otherwise.
41      */
42     virtual bool isPidTrusted(int pid) = 0;
43     /*
44      * Check whether the given pid and uid is trusted or not.
45      *
46      * @param[in] pid pid of the process.
47      * @param[in] uid uid of the process.
48      *
49      * @return true for trusted process and false otherwise.
50      */
51     virtual bool isPidUidTrusted(int pid, int uid) = 0;
52     /*
53      * Override process state and oom score of the pid.
54      *
55      * @param[in] pid pid of the process.
56      * @param[in] procState new state of the process to override with.
57      * @param[in] oomScore new oom score of the process to override with.
58      *
59      * @return true upon success and false otherwise.
60      */
61     virtual bool overrideProcessInfo(int pid, int procState, int oomScore) = 0;
62     /*
63      * Remove the override info of the given process.
64      *
65      * @param[in] pid pid of the process.
66      */
67     virtual void removeProcessInfoOverride(int pid) = 0;
68     /*
69      * Checks whether the list of processes with given pids exist or not.
70      *
71      * @param[in] pids List of pids for which to check whether they are Existent or not.
72      * @param[out] existent boolean vector corresponds to Existent state of each pids.
73      *
74      * @return true for successful return and false otherwise.
75      * On successful return:
76      *     - existent[i] true corresponds to pids[i] still active and
77      *     - existent[i] false corresponds to pids[i] already terminated (Nonexistent)
78      * On unsuccessful return, the output argument existent is invalid.
79      */
checkProcessExistentProcessInfoInterface80     virtual bool checkProcessExistent(const std::vector<int32_t>& pids,
81                                       std::vector<bool>* existent) {
82         // A default implementation.
83         (void)pids;
84         (void)existent;
85         return false;
86     }
87 
88 protected:
~ProcessInfoInterfaceProcessInfoInterface89     virtual ~ProcessInfoInterface() {}
90 };
91 
92 }  // namespace android
93 
94 #endif  // PROCESS_INFO_INTERFACE_H_
95