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