blob: 6bfd1bc17df110ecb1de6d51e336bd56c5d355a5 [file] [log] [blame]
Ruben Brunk52f04072015-01-28 18:13:33 -08001/*
2 * Copyright 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 ANDROID_PROCESS_INFO_SERVICE_H
18#define ANDROID_PROCESS_INFO_SERVICE_H
19
Jiyong Park47f876b2018-04-17 13:56:46 +090020#ifndef __ANDROID_VNDK__
21
Ruben Brunk52f04072015-01-28 18:13:33 -080022#include <binder/IProcessInfoService.h>
23#include <utils/Errors.h>
24#include <utils/Singleton.h>
25#include <sys/types.h>
26
27namespace android {
28
29// ----------------------------------------------------------------------
30
31class ProcessInfoService : public Singleton<ProcessInfoService> {
32
33 friend class Singleton<ProcessInfoService>;
34 sp<IProcessInfoService> mProcessInfoService;
35 Mutex mProcessInfoLock;
36
37 ProcessInfoService();
38
39 status_t getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states);
Emilian Peevb4f33df2017-02-02 09:57:18 +000040 status_t getProcessStatesScoresImpl(size_t length, /*in*/ int32_t* pids,
41 /*out*/ int32_t* states, /*out*/ int32_t *scores);
Ruben Brunk52f04072015-01-28 18:13:33 -080042 void updateBinderLocked();
43
44 static const int BINDER_ATTEMPT_LIMIT = 5;
45
46public:
47
48 /**
49 * For each PID in the given "pids" input array, write the current process state
50 * for that process into the "states" output array, or
51 * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID
52 * exists.
53 *
54 * Returns NO_ERROR if this operation was successful, or a negative error code otherwise.
55 */
56 static status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids,
57 /*out*/ int32_t* states) {
58 return ProcessInfoService::getInstance().getProcessStatesImpl(length, /*in*/ pids,
59 /*out*/ states);
60 }
61
Emilian Peevb4f33df2017-02-02 09:57:18 +000062 /**
63 * For each PID in the given "pids" input array, write the current process state
64 * for that process into the "states" output array, or
65 * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID
66 * exists. OoM scores will also be written in the "scores" output array.
67 * Please also note that clients calling this method need to have
68 * "GET_PROCESS_STATE_AND_OOM_SCORE" permission.
69 *
70 * Returns NO_ERROR if this operation was successful, or a negative error code otherwise.
71 */
72 static status_t getProcessStatesScoresFromPids(size_t length, /*in*/ int32_t* pids,
73 /*out*/ int32_t* states, /*out*/ int32_t *scores) {
74 return ProcessInfoService::getInstance().getProcessStatesScoresImpl(
75 length, /*in*/ pids, /*out*/ states, /*out*/ scores);
76 }
Ruben Brunk52f04072015-01-28 18:13:33 -080077};
78
79// ----------------------------------------------------------------------
80
Steven Moreland6511af52019-09-26 16:05:45 -070081} // namespace android
Ruben Brunk52f04072015-01-28 18:13:33 -080082
Jiyong Park47f876b2018-04-17 13:56:46 +090083#else // __ANDROID_VNDK__
84#error "This header is not visible to vendors"
85#endif // __ANDROID_VNDK__
86
Ruben Brunk52f04072015-01-28 18:13:33 -080087#endif // ANDROID_PROCESS_INFO_SERVICE_H
88