IPowerManager.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2011 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. #define LOG_TAG "IPowerManager"
  17. //#define LOG_NDEBUG 0
  18. #include <utils/Log.h>
  19. #include <stdint.h>
  20. #include <sys/types.h>
  21. #include <binder/Parcel.h>
  22. #include <powermanager/IPowerManager.h>
  23. namespace android {
  24. // must be kept in sync with IPowerManager.aidl
  25. enum {
  26. ACQUIRE_WAKE_LOCK = IBinder::FIRST_CALL_TRANSACTION,
  27. ACQUIRE_WAKE_LOCK_UID = IBinder::FIRST_CALL_TRANSACTION + 1,
  28. RELEASE_WAKE_LOCK = IBinder::FIRST_CALL_TRANSACTION + 2,
  29. UPDATE_WAKE_LOCK_UIDS = IBinder::FIRST_CALL_TRANSACTION + 3,
  30. POWER_HINT = IBinder::FIRST_CALL_TRANSACTION + 4,
  31. };
  32. class BpPowerManager : public BpInterface<IPowerManager>
  33. {
  34. public:
  35. BpPowerManager(const sp<IBinder>& impl)
  36. : BpInterface<IPowerManager>(impl)
  37. {
  38. }
  39. virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag,
  40. const String16& packageName, bool isOneWay)
  41. {
  42. Parcel data, reply;
  43. data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
  44. data.writeStrongBinder(lock);
  45. data.writeInt32(flags);
  46. data.writeString16(tag);
  47. data.writeString16(packageName);
  48. data.writeInt32(0); // no WorkSource
  49. data.writeString16(NULL, 0); // no history tag
  50. return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply,
  51. isOneWay ? IBinder::FLAG_ONEWAY : 0);
  52. }
  53. virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag,
  54. const String16& packageName, int uid, bool isOneWay)
  55. {
  56. Parcel data, reply;
  57. data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
  58. data.writeStrongBinder(lock);
  59. data.writeInt32(flags);
  60. data.writeString16(tag);
  61. data.writeString16(packageName);
  62. data.writeInt32(uid); // uid to blame for the work
  63. return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply,
  64. isOneWay ? IBinder::FLAG_ONEWAY : 0);
  65. }
  66. virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags, bool isOneWay)
  67. {
  68. Parcel data, reply;
  69. data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
  70. data.writeStrongBinder(lock);
  71. data.writeInt32(flags);
  72. return remote()->transact(RELEASE_WAKE_LOCK, data, &reply,
  73. isOneWay ? IBinder::FLAG_ONEWAY : 0);
  74. }
  75. virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids,
  76. bool isOneWay) {
  77. Parcel data, reply;
  78. data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
  79. data.writeStrongBinder(lock);
  80. data.writeInt32Array(len, uids);
  81. return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply,
  82. isOneWay ? IBinder::FLAG_ONEWAY : 0);
  83. }
  84. virtual status_t powerHint(int hintId, int param)
  85. {
  86. Parcel data, reply;
  87. data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
  88. data.writeInt32(hintId);
  89. data.writeInt32(param);
  90. // This FLAG_ONEWAY is in the .aidl, so there is no way to disable it
  91. return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY);
  92. }
  93. };
  94. IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager");
  95. // ----------------------------------------------------------------------------
  96. }; // namespace android