1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2013 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker *
4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker *
8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker *
10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker */
16*38e8c45fSAndroid Build Coastguard Worker
17*38e8c45fSAndroid Build Coastguard Worker #include <batterystats/IBatteryStats.h>
18*38e8c45fSAndroid Build Coastguard Worker
19*38e8c45fSAndroid Build Coastguard Worker #include <utils/Log.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <binder/Parcel.h>
21*38e8c45fSAndroid Build Coastguard Worker #include <utils/String8.h>
22*38e8c45fSAndroid Build Coastguard Worker
23*38e8c45fSAndroid Build Coastguard Worker namespace android {
24*38e8c45fSAndroid Build Coastguard Worker
25*38e8c45fSAndroid Build Coastguard Worker // ----------------------------------------------------------------------
26*38e8c45fSAndroid Build Coastguard Worker
27*38e8c45fSAndroid Build Coastguard Worker class BpBatteryStats : public BpInterface<IBatteryStats>
28*38e8c45fSAndroid Build Coastguard Worker {
29*38e8c45fSAndroid Build Coastguard Worker public:
BpBatteryStats(const sp<IBinder> & impl)30*38e8c45fSAndroid Build Coastguard Worker explicit BpBatteryStats(const sp<IBinder>& impl)
31*38e8c45fSAndroid Build Coastguard Worker : BpInterface<IBatteryStats>(impl)
32*38e8c45fSAndroid Build Coastguard Worker {
33*38e8c45fSAndroid Build Coastguard Worker }
34*38e8c45fSAndroid Build Coastguard Worker
noteStartSensor(int uid,int sensor)35*38e8c45fSAndroid Build Coastguard Worker virtual void noteStartSensor(int uid, int sensor) {
36*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
37*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
38*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
39*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(sensor);
40*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_START_SENSOR_TRANSACTION, data, &reply);
41*38e8c45fSAndroid Build Coastguard Worker }
42*38e8c45fSAndroid Build Coastguard Worker
noteStopSensor(int uid,int sensor)43*38e8c45fSAndroid Build Coastguard Worker virtual void noteStopSensor(int uid, int sensor) {
44*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
45*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
46*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
47*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(sensor);
48*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_STOP_SENSOR_TRANSACTION, data, &reply);
49*38e8c45fSAndroid Build Coastguard Worker }
50*38e8c45fSAndroid Build Coastguard Worker
noteStartVideo(int uid)51*38e8c45fSAndroid Build Coastguard Worker virtual void noteStartVideo(int uid) {
52*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
53*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
54*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
55*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_START_VIDEO_TRANSACTION, data, &reply);
56*38e8c45fSAndroid Build Coastguard Worker }
57*38e8c45fSAndroid Build Coastguard Worker
noteStopVideo(int uid)58*38e8c45fSAndroid Build Coastguard Worker virtual void noteStopVideo(int uid) {
59*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
60*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
61*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
62*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_STOP_VIDEO_TRANSACTION, data, &reply);
63*38e8c45fSAndroid Build Coastguard Worker }
64*38e8c45fSAndroid Build Coastguard Worker
noteStartAudio(int uid)65*38e8c45fSAndroid Build Coastguard Worker virtual void noteStartAudio(int uid) {
66*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
67*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
68*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
69*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_START_AUDIO_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
70*38e8c45fSAndroid Build Coastguard Worker }
71*38e8c45fSAndroid Build Coastguard Worker
noteStopAudio(int uid)72*38e8c45fSAndroid Build Coastguard Worker virtual void noteStopAudio(int uid) {
73*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
74*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
75*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
76*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_STOP_AUDIO_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
77*38e8c45fSAndroid Build Coastguard Worker }
78*38e8c45fSAndroid Build Coastguard Worker
noteResetVideo()79*38e8c45fSAndroid Build Coastguard Worker virtual void noteResetVideo() {
80*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
81*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
82*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_RESET_VIDEO_TRANSACTION, data, &reply);
83*38e8c45fSAndroid Build Coastguard Worker }
84*38e8c45fSAndroid Build Coastguard Worker
noteResetAudio()85*38e8c45fSAndroid Build Coastguard Worker virtual void noteResetAudio() {
86*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
87*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
88*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_RESET_AUDIO_TRANSACTION, data, &reply, IBinder::FLAG_ONEWAY);
89*38e8c45fSAndroid Build Coastguard Worker }
90*38e8c45fSAndroid Build Coastguard Worker
noteFlashlightOn(int uid)91*38e8c45fSAndroid Build Coastguard Worker virtual void noteFlashlightOn(int uid) {
92*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
93*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
94*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
95*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_FLASHLIGHT_ON_TRANSACTION, data, &reply);
96*38e8c45fSAndroid Build Coastguard Worker }
97*38e8c45fSAndroid Build Coastguard Worker
noteFlashlightOff(int uid)98*38e8c45fSAndroid Build Coastguard Worker virtual void noteFlashlightOff(int uid) {
99*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
100*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
101*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
102*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_FLASHLIGHT_OFF_TRANSACTION, data, &reply);
103*38e8c45fSAndroid Build Coastguard Worker }
104*38e8c45fSAndroid Build Coastguard Worker
noteStartCamera(int uid)105*38e8c45fSAndroid Build Coastguard Worker virtual void noteStartCamera(int uid) {
106*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
107*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
108*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
109*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_START_CAMERA_TRANSACTION, data, &reply);
110*38e8c45fSAndroid Build Coastguard Worker }
111*38e8c45fSAndroid Build Coastguard Worker
noteStopCamera(int uid)112*38e8c45fSAndroid Build Coastguard Worker virtual void noteStopCamera(int uid) {
113*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
114*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
115*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
116*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_STOP_CAMERA_TRANSACTION, data, &reply);
117*38e8c45fSAndroid Build Coastguard Worker }
118*38e8c45fSAndroid Build Coastguard Worker
noteResetCamera()119*38e8c45fSAndroid Build Coastguard Worker virtual void noteResetCamera() {
120*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
121*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
122*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_RESET_CAMERA_TRANSACTION, data, &reply);
123*38e8c45fSAndroid Build Coastguard Worker }
124*38e8c45fSAndroid Build Coastguard Worker
noteResetFlashlight()125*38e8c45fSAndroid Build Coastguard Worker virtual void noteResetFlashlight() {
126*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
127*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
128*38e8c45fSAndroid Build Coastguard Worker remote()->transact(NOTE_RESET_FLASHLIGHT_TRANSACTION, data, &reply);
129*38e8c45fSAndroid Build Coastguard Worker }
130*38e8c45fSAndroid Build Coastguard Worker
noteWakeupSensorEvent(int64_t elapsedNanos,int uid,int handle)131*38e8c45fSAndroid Build Coastguard Worker virtual binder::Status noteWakeupSensorEvent(int64_t elapsedNanos, int uid, int handle) {
132*38e8c45fSAndroid Build Coastguard Worker Parcel data, reply;
133*38e8c45fSAndroid Build Coastguard Worker data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
134*38e8c45fSAndroid Build Coastguard Worker data.writeInt64(elapsedNanos);
135*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(uid);
136*38e8c45fSAndroid Build Coastguard Worker data.writeInt32(handle);
137*38e8c45fSAndroid Build Coastguard Worker status_t ret = remote()->transact(NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION, data, &reply);
138*38e8c45fSAndroid Build Coastguard Worker return binder::Status::fromStatusT(ret);
139*38e8c45fSAndroid Build Coastguard Worker }
140*38e8c45fSAndroid Build Coastguard Worker };
141*38e8c45fSAndroid Build Coastguard Worker
142*38e8c45fSAndroid Build Coastguard Worker IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats")
143*38e8c45fSAndroid Build Coastguard Worker
144*38e8c45fSAndroid Build Coastguard Worker // ----------------------------------------------------------------------
145*38e8c45fSAndroid Build Coastguard Worker
146*38e8c45fSAndroid Build Coastguard Worker // NOLINTNEXTLINE(google-default-arguments)
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)147*38e8c45fSAndroid Build Coastguard Worker status_t BnBatteryStats::onTransact(
148*38e8c45fSAndroid Build Coastguard Worker uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
149*38e8c45fSAndroid Build Coastguard Worker {
150*38e8c45fSAndroid Build Coastguard Worker switch(code) {
151*38e8c45fSAndroid Build Coastguard Worker case NOTE_START_SENSOR_TRANSACTION: {
152*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
153*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
154*38e8c45fSAndroid Build Coastguard Worker int sensor = data.readInt32();
155*38e8c45fSAndroid Build Coastguard Worker noteStartSensor(uid, sensor);
156*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
157*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
158*38e8c45fSAndroid Build Coastguard Worker } break;
159*38e8c45fSAndroid Build Coastguard Worker case NOTE_STOP_SENSOR_TRANSACTION: {
160*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
161*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
162*38e8c45fSAndroid Build Coastguard Worker int sensor = data.readInt32();
163*38e8c45fSAndroid Build Coastguard Worker noteStopSensor(uid, sensor);
164*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
165*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
166*38e8c45fSAndroid Build Coastguard Worker } break;
167*38e8c45fSAndroid Build Coastguard Worker case NOTE_START_VIDEO_TRANSACTION: {
168*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
169*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
170*38e8c45fSAndroid Build Coastguard Worker noteStartVideo(uid);
171*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
172*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
173*38e8c45fSAndroid Build Coastguard Worker } break;
174*38e8c45fSAndroid Build Coastguard Worker case NOTE_STOP_VIDEO_TRANSACTION: {
175*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
176*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
177*38e8c45fSAndroid Build Coastguard Worker noteStopVideo(uid);
178*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
179*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
180*38e8c45fSAndroid Build Coastguard Worker } break;
181*38e8c45fSAndroid Build Coastguard Worker case NOTE_START_AUDIO_TRANSACTION: {
182*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
183*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
184*38e8c45fSAndroid Build Coastguard Worker noteStartAudio(uid);
185*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
186*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
187*38e8c45fSAndroid Build Coastguard Worker } break;
188*38e8c45fSAndroid Build Coastguard Worker case NOTE_STOP_AUDIO_TRANSACTION: {
189*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
190*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
191*38e8c45fSAndroid Build Coastguard Worker noteStopAudio(uid);
192*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
193*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
194*38e8c45fSAndroid Build Coastguard Worker } break;
195*38e8c45fSAndroid Build Coastguard Worker case NOTE_RESET_VIDEO_TRANSACTION: {
196*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
197*38e8c45fSAndroid Build Coastguard Worker noteResetVideo();
198*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
199*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
200*38e8c45fSAndroid Build Coastguard Worker } break;
201*38e8c45fSAndroid Build Coastguard Worker case NOTE_RESET_AUDIO_TRANSACTION: {
202*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
203*38e8c45fSAndroid Build Coastguard Worker noteResetAudio();
204*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
205*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
206*38e8c45fSAndroid Build Coastguard Worker } break;
207*38e8c45fSAndroid Build Coastguard Worker case NOTE_FLASHLIGHT_ON_TRANSACTION: {
208*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
209*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
210*38e8c45fSAndroid Build Coastguard Worker noteFlashlightOn(uid);
211*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
212*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
213*38e8c45fSAndroid Build Coastguard Worker } break;
214*38e8c45fSAndroid Build Coastguard Worker case NOTE_FLASHLIGHT_OFF_TRANSACTION: {
215*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
216*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
217*38e8c45fSAndroid Build Coastguard Worker noteFlashlightOff(uid);
218*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
219*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
220*38e8c45fSAndroid Build Coastguard Worker } break;
221*38e8c45fSAndroid Build Coastguard Worker case NOTE_START_CAMERA_TRANSACTION: {
222*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
223*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
224*38e8c45fSAndroid Build Coastguard Worker noteStartCamera(uid);
225*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
226*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
227*38e8c45fSAndroid Build Coastguard Worker } break;
228*38e8c45fSAndroid Build Coastguard Worker case NOTE_STOP_CAMERA_TRANSACTION: {
229*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
230*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
231*38e8c45fSAndroid Build Coastguard Worker noteStopCamera(uid);
232*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
233*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
234*38e8c45fSAndroid Build Coastguard Worker } break;
235*38e8c45fSAndroid Build Coastguard Worker case NOTE_RESET_CAMERA_TRANSACTION: {
236*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
237*38e8c45fSAndroid Build Coastguard Worker noteResetCamera();
238*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
239*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
240*38e8c45fSAndroid Build Coastguard Worker } break;
241*38e8c45fSAndroid Build Coastguard Worker case NOTE_RESET_FLASHLIGHT_TRANSACTION: {
242*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
243*38e8c45fSAndroid Build Coastguard Worker noteResetFlashlight();
244*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
245*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
246*38e8c45fSAndroid Build Coastguard Worker } break;
247*38e8c45fSAndroid Build Coastguard Worker case NOTE_WAKEUP_SENSOR_EVENT_TRANSACTION: {
248*38e8c45fSAndroid Build Coastguard Worker CHECK_INTERFACE(IBatteryStats, data, reply);
249*38e8c45fSAndroid Build Coastguard Worker int64_t elapsedNanos = data.readInt64();
250*38e8c45fSAndroid Build Coastguard Worker int uid = data.readInt32();
251*38e8c45fSAndroid Build Coastguard Worker int handle = data.readInt32();
252*38e8c45fSAndroid Build Coastguard Worker noteWakeupSensorEvent(elapsedNanos, uid, handle);
253*38e8c45fSAndroid Build Coastguard Worker reply->writeNoException();
254*38e8c45fSAndroid Build Coastguard Worker return NO_ERROR;
255*38e8c45fSAndroid Build Coastguard Worker } break;
256*38e8c45fSAndroid Build Coastguard Worker
257*38e8c45fSAndroid Build Coastguard Worker default:
258*38e8c45fSAndroid Build Coastguard Worker return BBinder::onTransact(code, data, reply, flags);
259*38e8c45fSAndroid Build Coastguard Worker }
260*38e8c45fSAndroid Build Coastguard Worker }
261*38e8c45fSAndroid Build Coastguard Worker
262*38e8c45fSAndroid Build Coastguard Worker } // namespace android
263