1 /* 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 20 #include <binder/IProcessInfoService.h> 21 #include <utils/Errors.h> 22 #include <utils/Singleton.h> 23 #include <sys/types.h> 24 25 namespace android { 26 27 // ---------------------------------------------------------------------- 28 29 class ProcessInfoService : public Singleton<ProcessInfoService> { 30 31 friend class Singleton<ProcessInfoService>; 32 sp<IProcessInfoService> mProcessInfoService; 33 Mutex mProcessInfoLock; 34 35 ProcessInfoService(); 36 37 status_t getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states); 38 status_t getProcessStatesScoresImpl(size_t length, /*in*/ int32_t* pids, 39 /*out*/ int32_t* states, /*out*/ int32_t *scores); 40 void updateBinderLocked(); 41 42 static const int BINDER_ATTEMPT_LIMIT = 5; 43 44 public: 45 46 /** 47 * For each PID in the given "pids" input array, write the current process state 48 * for that process into the "states" output array, or 49 * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID 50 * exists. 51 * 52 * Returns NO_ERROR if this operation was successful, or a negative error code otherwise. 53 */ getProcessStatesFromPids(size_t length,int32_t * pids,int32_t * states)54 static status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids, 55 /*out*/ int32_t* states) { 56 return ProcessInfoService::getInstance().getProcessStatesImpl(length, /*in*/ pids, 57 /*out*/ states); 58 } 59 60 /** 61 * For each PID in the given "pids" input array, write the current process state 62 * for that process into the "states" output array, or 63 * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID 64 * exists. OoM scores will also be written in the "scores" output array. 65 * Please also note that clients calling this method need to have 66 * "GET_PROCESS_STATE_AND_OOM_SCORE" permission. 67 * 68 * Returns NO_ERROR if this operation was successful, or a negative error code otherwise. 69 */ getProcessStatesScoresFromPids(size_t length,int32_t * pids,int32_t * states,int32_t * scores)70 static status_t getProcessStatesScoresFromPids(size_t length, /*in*/ int32_t* pids, 71 /*out*/ int32_t* states, /*out*/ int32_t *scores) { 72 return ProcessInfoService::getInstance().getProcessStatesScoresImpl( 73 length, /*in*/ pids, /*out*/ states, /*out*/ scores); 74 } 75 }; 76 77 // ---------------------------------------------------------------------- 78 79 }; // namespace android 80 81 #endif // ANDROID_PROCESS_INFO_SERVICE_H 82 83