BatteryService.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2012 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. #include <stdint.h>
  17. #include <sys/types.h>
  18. #include <binder/IBatteryStats.h>
  19. #include <utils/Singleton.h>
  20. namespace android {
  21. // ---------------------------------------------------------------------------
  22. class BatteryService : public Singleton<BatteryService> {
  23. friend class Singleton<BatteryService>;
  24. sp<IBatteryStats> mBatteryStatService;
  25. BatteryService();
  26. void enableSensorImpl(uid_t uid, int handle);
  27. void disableSensorImpl(uid_t uid, int handle);
  28. void cleanupImpl(uid_t uid);
  29. struct Info {
  30. uid_t uid;
  31. int handle;
  32. int32_t count;
  33. Info() : uid(0), handle(0), count(0) { }
  34. Info(uid_t uid, int handle) : uid(uid), handle(handle), count(0) { }
  35. bool operator < (const Info& rhs) const {
  36. return (uid == rhs.uid) ? (handle < rhs.handle) : (uid < rhs.uid);
  37. }
  38. };
  39. Mutex mActivationsLock;
  40. SortedVector<Info> mActivations;
  41. bool addSensor(uid_t uid, int handle);
  42. bool removeSensor(uid_t uid, int handle);
  43. public:
  44. static void enableSensor(uid_t uid, int handle) {
  45. BatteryService::getInstance().enableSensorImpl(uid, handle);
  46. }
  47. static void disableSensor(uid_t uid, int handle) {
  48. BatteryService::getInstance().disableSensorImpl(uid, handle);
  49. }
  50. static void cleanup(uid_t uid) {
  51. BatteryService::getInstance().cleanupImpl(uid);
  52. }
  53. };
  54. // ---------------------------------------------------------------------------
  55. }; // namespace android