IBatteryStats.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * Copyright (C) 2013 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 <binder/IBatteryStats.h>
  17. #include <utils/Log.h>
  18. #include <binder/Parcel.h>
  19. #include <utils/String8.h>
  20. #include <private/binder/Static.h>
  21. namespace android {
  22. // ----------------------------------------------------------------------
  23. class BpBatteryStats : public BpInterface<IBatteryStats>
  24. {
  25. public:
  26. BpBatteryStats(const sp<IBinder>& impl)
  27. : BpInterface<IBatteryStats>(impl)
  28. {
  29. }
  30. virtual void noteStartSensor(int uid, int sensor) {
  31. Parcel data, reply;
  32. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  33. data.writeInt32(uid);
  34. data.writeInt32(sensor);
  35. remote()->transact(NOTE_START_SENSOR_TRANSACTION, data, &reply);
  36. }
  37. virtual void noteStopSensor(int uid, int sensor) {
  38. Parcel data, reply;
  39. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  40. data.writeInt32(uid);
  41. data.writeInt32(sensor);
  42. remote()->transact(NOTE_STOP_SENSOR_TRANSACTION, data, &reply);
  43. }
  44. virtual void noteStartVideo(int uid) {
  45. Parcel data, reply;
  46. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  47. data.writeInt32(uid);
  48. remote()->transact(NOTE_START_VIDEO_TRANSACTION, data, &reply);
  49. }
  50. virtual void noteStopVideo(int uid) {
  51. Parcel data, reply;
  52. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  53. data.writeInt32(uid);
  54. remote()->transact(NOTE_STOP_VIDEO_TRANSACTION, data, &reply);
  55. }
  56. virtual void noteStartAudio(int uid) {
  57. Parcel data, reply;
  58. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  59. data.writeInt32(uid);
  60. remote()->transact(NOTE_START_AUDIO_TRANSACTION, data, &reply);
  61. }
  62. virtual void noteStopAudio(int uid) {
  63. Parcel data, reply;
  64. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  65. data.writeInt32(uid);
  66. remote()->transact(NOTE_STOP_AUDIO_TRANSACTION, data, &reply);
  67. }
  68. virtual void noteResetVideo() {
  69. Parcel data, reply;
  70. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  71. remote()->transact(NOTE_RESET_VIDEO_TRANSACTION, data, &reply);
  72. }
  73. virtual void noteResetAudio() {
  74. Parcel data, reply;
  75. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  76. remote()->transact(NOTE_RESET_AUDIO_TRANSACTION, data, &reply);
  77. }
  78. virtual void noteFlashlightOn(int uid) {
  79. Parcel data, reply;
  80. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  81. data.writeInt32(uid);
  82. remote()->transact(NOTE_FLASHLIGHT_ON_TRANSACTION, data, &reply);
  83. }
  84. virtual void noteFlashlightOff(int uid) {
  85. Parcel data, reply;
  86. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  87. data.writeInt32(uid);
  88. remote()->transact(NOTE_FLASHLIGHT_OFF_TRANSACTION, data, &reply);
  89. }
  90. virtual void noteStartCamera(int uid) {
  91. Parcel data, reply;
  92. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  93. data.writeInt32(uid);
  94. remote()->transact(NOTE_START_CAMERA_TRANSACTION, data, &reply);
  95. }
  96. virtual void noteStopCamera(int uid) {
  97. Parcel data, reply;
  98. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  99. data.writeInt32(uid);
  100. remote()->transact(NOTE_STOP_CAMERA_TRANSACTION, data, &reply);
  101. }
  102. virtual void noteResetCamera() {
  103. Parcel data, reply;
  104. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  105. remote()->transact(NOTE_RESET_CAMERA_TRANSACTION, data, &reply);
  106. }
  107. virtual void noteResetFlashlight() {
  108. Parcel data, reply;
  109. data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
  110. remote()->transact(NOTE_RESET_FLASHLIGHT_TRANSACTION, data, &reply);
  111. }
  112. };
  113. IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats");
  114. // ----------------------------------------------------------------------
  115. status_t BnBatteryStats::onTransact(
  116. uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
  117. {
  118. switch(code) {
  119. case NOTE_START_SENSOR_TRANSACTION: {
  120. CHECK_INTERFACE(IBatteryStats, data, reply);
  121. int uid = data.readInt32();
  122. int sensor = data.readInt32();
  123. noteStartSensor(uid, sensor);
  124. reply->writeNoException();
  125. return NO_ERROR;
  126. } break;
  127. case NOTE_STOP_SENSOR_TRANSACTION: {
  128. CHECK_INTERFACE(IBatteryStats, data, reply);
  129. int uid = data.readInt32();
  130. int sensor = data.readInt32();
  131. noteStopSensor(uid, sensor);
  132. reply->writeNoException();
  133. return NO_ERROR;
  134. } break;
  135. case NOTE_START_VIDEO_TRANSACTION: {
  136. CHECK_INTERFACE(IBatteryStats, data, reply);
  137. int uid = data.readInt32();
  138. noteStartVideo(uid);
  139. reply->writeNoException();
  140. return NO_ERROR;
  141. } break;
  142. case NOTE_STOP_VIDEO_TRANSACTION: {
  143. CHECK_INTERFACE(IBatteryStats, data, reply);
  144. int uid = data.readInt32();
  145. noteStopVideo(uid);
  146. reply->writeNoException();
  147. return NO_ERROR;
  148. } break;
  149. case NOTE_START_AUDIO_TRANSACTION: {
  150. CHECK_INTERFACE(IBatteryStats, data, reply);
  151. int uid = data.readInt32();
  152. noteStartAudio(uid);
  153. reply->writeNoException();
  154. return NO_ERROR;
  155. } break;
  156. case NOTE_STOP_AUDIO_TRANSACTION: {
  157. CHECK_INTERFACE(IBatteryStats, data, reply);
  158. int uid = data.readInt32();
  159. noteStopAudio(uid);
  160. reply->writeNoException();
  161. return NO_ERROR;
  162. } break;
  163. case NOTE_RESET_VIDEO_TRANSACTION: {
  164. CHECK_INTERFACE(IBatteryStats, data, reply);
  165. noteResetVideo();
  166. reply->writeNoException();
  167. return NO_ERROR;
  168. } break;
  169. case NOTE_RESET_AUDIO_TRANSACTION: {
  170. CHECK_INTERFACE(IBatteryStats, data, reply);
  171. noteResetAudio();
  172. reply->writeNoException();
  173. return NO_ERROR;
  174. } break;
  175. case NOTE_FLASHLIGHT_ON_TRANSACTION: {
  176. CHECK_INTERFACE(IBatteryStats, data, reply);
  177. int uid = data.readInt32();
  178. noteFlashlightOn(uid);
  179. reply->writeNoException();
  180. return NO_ERROR;
  181. } break;
  182. case NOTE_FLASHLIGHT_OFF_TRANSACTION: {
  183. CHECK_INTERFACE(IBatteryStats, data, reply);
  184. int uid = data.readInt32();
  185. noteFlashlightOff(uid);
  186. reply->writeNoException();
  187. return NO_ERROR;
  188. } break;
  189. case NOTE_START_CAMERA_TRANSACTION: {
  190. CHECK_INTERFACE(IBatteryStats, data, reply);
  191. int uid = data.readInt32();
  192. noteStartCamera(uid);
  193. reply->writeNoException();
  194. return NO_ERROR;
  195. } break;
  196. case NOTE_STOP_CAMERA_TRANSACTION: {
  197. CHECK_INTERFACE(IBatteryStats, data, reply);
  198. int uid = data.readInt32();
  199. noteStopCamera(uid);
  200. reply->writeNoException();
  201. return NO_ERROR;
  202. } break;
  203. case NOTE_RESET_CAMERA_TRANSACTION: {
  204. CHECK_INTERFACE(IBatteryStats, data, reply);
  205. noteResetCamera();
  206. reply->writeNoException();
  207. return NO_ERROR;
  208. } break;
  209. case NOTE_RESET_FLASHLIGHT_TRANSACTION: {
  210. CHECK_INTERFACE(IBatteryStats, data, reply);
  211. noteResetFlashlight();
  212. reply->writeNoException();
  213. return NO_ERROR;
  214. } break;
  215. default:
  216. return BBinder::onTransact(code, data, reply, flags);
  217. }
  218. }
  219. }; // namespace android