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