Loading include/binder/ProcessInfoService.h +17 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ class ProcessInfoService : public Singleton<ProcessInfoService> { ProcessInfoService(); status_t getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states); status_t getProcessStatesScoresImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t *scores); void updateBinderLocked(); static const int BINDER_ATTEMPT_LIMIT = 5; Loading @@ -55,6 +57,21 @@ public: /*out*/ states); } /** * For each PID in the given "pids" input array, write the current process state * for that process into the "states" output array, or * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID * exists. OoM scores will also be written in the "scores" output array. * Please also note that clients calling this method need to have * "GET_PROCESS_STATE_AND_OOM_SCORE" permission. * * Returns NO_ERROR if this operation was successful, or a negative error code otherwise. */ static status_t getProcessStatesScoresFromPids(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t *scores) { return ProcessInfoService::getInstance().getProcessStatesScoresImpl( length, /*in*/ pids, /*out*/ states, /*out*/ scores); } }; // ---------------------------------------------------------------------- Loading libs/binder/ProcessInfoService.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,40 @@ status_t ProcessInfoService::getProcessStatesImpl(size_t length, /*in*/ int32_t* return TIMED_OUT; } status_t ProcessInfoService::getProcessStatesScoresImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t *scores) { status_t err = NO_ERROR; sp<IProcessInfoService> pis; mProcessInfoLock.lock(); pis = mProcessInfoService; mProcessInfoLock.unlock(); for (int i = 0; i < BINDER_ATTEMPT_LIMIT; i++) { if (pis != NULL) { err = pis->getProcessStatesAndOomScoresFromPids(length, /*in*/ pids, /*out*/ states, /*out*/ scores); if (err == NO_ERROR) return NO_ERROR; // success if (IInterface::asBinder(pis)->isBinderAlive()) return err; } sleep(1); mProcessInfoLock.lock(); if (pis == mProcessInfoService) { updateBinderLocked(); } pis = mProcessInfoService; mProcessInfoLock.unlock(); } ALOGW("%s: Could not retrieve process states and scores " "from ProcessInfoService after %d retries.", __FUNCTION__, BINDER_ATTEMPT_LIMIT); return TIMED_OUT; } void ProcessInfoService::updateBinderLocked() { const sp<IServiceManager> sm(defaultServiceManager()); if (sm != NULL) { Loading Loading
include/binder/ProcessInfoService.h +17 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,8 @@ class ProcessInfoService : public Singleton<ProcessInfoService> { ProcessInfoService(); status_t getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states); status_t getProcessStatesScoresImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t *scores); void updateBinderLocked(); static const int BINDER_ATTEMPT_LIMIT = 5; Loading @@ -55,6 +57,21 @@ public: /*out*/ states); } /** * For each PID in the given "pids" input array, write the current process state * for that process into the "states" output array, or * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID * exists. OoM scores will also be written in the "scores" output array. * Please also note that clients calling this method need to have * "GET_PROCESS_STATE_AND_OOM_SCORE" permission. * * Returns NO_ERROR if this operation was successful, or a negative error code otherwise. */ static status_t getProcessStatesScoresFromPids(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t *scores) { return ProcessInfoService::getInstance().getProcessStatesScoresImpl( length, /*in*/ pids, /*out*/ states, /*out*/ scores); } }; // ---------------------------------------------------------------------- Loading
libs/binder/ProcessInfoService.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,40 @@ status_t ProcessInfoService::getProcessStatesImpl(size_t length, /*in*/ int32_t* return TIMED_OUT; } status_t ProcessInfoService::getProcessStatesScoresImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states, /*out*/ int32_t *scores) { status_t err = NO_ERROR; sp<IProcessInfoService> pis; mProcessInfoLock.lock(); pis = mProcessInfoService; mProcessInfoLock.unlock(); for (int i = 0; i < BINDER_ATTEMPT_LIMIT; i++) { if (pis != NULL) { err = pis->getProcessStatesAndOomScoresFromPids(length, /*in*/ pids, /*out*/ states, /*out*/ scores); if (err == NO_ERROR) return NO_ERROR; // success if (IInterface::asBinder(pis)->isBinderAlive()) return err; } sleep(1); mProcessInfoLock.lock(); if (pis == mProcessInfoService) { updateBinderLocked(); } pis = mProcessInfoService; mProcessInfoLock.unlock(); } ALOGW("%s: Could not retrieve process states and scores " "from ProcessInfoService after %d retries.", __FUNCTION__, BINDER_ATTEMPT_LIMIT); return TIMED_OUT; } void ProcessInfoService::updateBinderLocked() { const sp<IServiceManager> sm(defaultServiceManager()); if (sm != NULL) { Loading