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