ProcessInfoService.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef ANDROID_PROCESS_INFO_SERVICE_H
  17. #define ANDROID_PROCESS_INFO_SERVICE_H
  18. #include <binder/IProcessInfoService.h>
  19. #include <utils/Errors.h>
  20. #include <utils/Singleton.h>
  21. #include <sys/types.h>
  22. namespace android {
  23. // ----------------------------------------------------------------------
  24. class ProcessInfoService : public Singleton<ProcessInfoService> {
  25. friend class Singleton<ProcessInfoService>;
  26. sp<IProcessInfoService> mProcessInfoService;
  27. Mutex mProcessInfoLock;
  28. ProcessInfoService();
  29. status_t getProcessStatesImpl(size_t length, /*in*/ int32_t* pids, /*out*/ int32_t* states);
  30. void updateBinderLocked();
  31. static const int BINDER_ATTEMPT_LIMIT = 5;
  32. public:
  33. /**
  34. * For each PID in the given "pids" input array, write the current process state
  35. * for that process into the "states" output array, or
  36. * ActivityManager.PROCESS_STATE_NONEXISTENT * to indicate that no process with the given PID
  37. * exists.
  38. *
  39. * Returns NO_ERROR if this operation was successful, or a negative error code otherwise.
  40. */
  41. static status_t getProcessStatesFromPids(size_t length, /*in*/ int32_t* pids,
  42. /*out*/ int32_t* states) {
  43. return ProcessInfoService::getInstance().getProcessStatesImpl(length, /*in*/ pids,
  44. /*out*/ states);
  45. }
  46. };
  47. // ----------------------------------------------------------------------
  48. }; // namespace android
  49. #endif // ANDROID_PROCESS_INFO_SERVICE_H