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
25 namespace android {
26
27 // ----------------------------------------------------------------------
28
29 class BpBatteryStats : public BpInterface<IBatteryStats>
30 {
31 public:
BpBatteryStats(const sp<IBinder> & impl)32 explicit BpBatteryStats(const sp<IBinder>& impl)
33 : BpInterface<IBatteryStats>(impl)
34 {
35 }
36
noteStartSensor(int uid,int sensor)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
noteStopSensor(int uid,int sensor)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
noteStartVideo(int uid)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
noteStopVideo(int uid)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
noteStartAudio(int uid)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
noteStopAudio(int uid)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
noteResetVideo()81 virtual void noteResetVideo() {
82 Parcel data, reply;
83 data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
84 remote()->transact(NOTE_RESET_VIDEO_TRANSACTION, data, &reply);
85 }
86
noteResetAudio()87 virtual void noteResetAudio() {
88 Parcel data, reply;
89 data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
90 remote()->transact(NOTE_RESET_AUDIO_TRANSACTION, data, &reply);
91 }
92
noteFlashlightOn(int uid)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
noteFlashlightOff(int uid)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
noteStartCamera(int uid)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
noteStopCamera(int uid)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
noteResetCamera()121 virtual void noteResetCamera() {
122 Parcel data, reply;
123 data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor());
124 remote()->transact(NOTE_RESET_CAMERA_TRANSACTION, data, &reply);
125 }
126
noteResetFlashlight()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
135 IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats");
136
137 // ----------------------------------------------------------------------
138
139 // NOLINTNEXTLINE(google-default-arguments)
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)140 status_t BnBatteryStats::onTransact(
141 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
142 {
143 switch(code) {
144 case NOTE_START_SENSOR_TRANSACTION: {
145 CHECK_INTERFACE(IBatteryStats, data, reply);
146 int uid = data.readInt32();
147 int sensor = data.readInt32();
148 noteStartSensor(uid, sensor);
149 reply->writeNoException();
150 return NO_ERROR;
151 } break;
152 case NOTE_STOP_SENSOR_TRANSACTION: {
153 CHECK_INTERFACE(IBatteryStats, data, reply);
154 int uid = data.readInt32();
155 int sensor = data.readInt32();
156 noteStopSensor(uid, sensor);
157 reply->writeNoException();
158 return NO_ERROR;
159 } break;
160 case NOTE_START_VIDEO_TRANSACTION: {
161 CHECK_INTERFACE(IBatteryStats, data, reply);
162 int uid = data.readInt32();
163 noteStartVideo(uid);
164 reply->writeNoException();
165 return NO_ERROR;
166 } break;
167 case NOTE_STOP_VIDEO_TRANSACTION: {
168 CHECK_INTERFACE(IBatteryStats, data, reply);
169 int uid = data.readInt32();
170 noteStopVideo(uid);
171 reply->writeNoException();
172 return NO_ERROR;
173 } break;
174 case NOTE_START_AUDIO_TRANSACTION: {
175 CHECK_INTERFACE(IBatteryStats, data, reply);
176 int uid = data.readInt32();
177 noteStartAudio(uid);
178 reply->writeNoException();
179 return NO_ERROR;
180 } break;
181 case NOTE_STOP_AUDIO_TRANSACTION: {
182 CHECK_INTERFACE(IBatteryStats, data, reply);
183 int uid = data.readInt32();
184 noteStopAudio(uid);
185 reply->writeNoException();
186 return NO_ERROR;
187 } break;
188 case NOTE_RESET_VIDEO_TRANSACTION: {
189 CHECK_INTERFACE(IBatteryStats, data, reply);
190 noteResetVideo();
191 reply->writeNoException();
192 return NO_ERROR;
193 } break;
194 case NOTE_RESET_AUDIO_TRANSACTION: {
195 CHECK_INTERFACE(IBatteryStats, data, reply);
196 noteResetAudio();
197 reply->writeNoException();
198 return NO_ERROR;
199 } break;
200 case NOTE_FLASHLIGHT_ON_TRANSACTION: {
201 CHECK_INTERFACE(IBatteryStats, data, reply);
202 int uid = data.readInt32();
203 noteFlashlightOn(uid);
204 reply->writeNoException();
205 return NO_ERROR;
206 } break;
207 case NOTE_FLASHLIGHT_OFF_TRANSACTION: {
208 CHECK_INTERFACE(IBatteryStats, data, reply);
209 int uid = data.readInt32();
210 noteFlashlightOff(uid);
211 reply->writeNoException();
212 return NO_ERROR;
213 } break;
214 case NOTE_START_CAMERA_TRANSACTION: {
215 CHECK_INTERFACE(IBatteryStats, data, reply);
216 int uid = data.readInt32();
217 noteStartCamera(uid);
218 reply->writeNoException();
219 return NO_ERROR;
220 } break;
221 case NOTE_STOP_CAMERA_TRANSACTION: {
222 CHECK_INTERFACE(IBatteryStats, data, reply);
223 int uid = data.readInt32();
224 noteStopCamera(uid);
225 reply->writeNoException();
226 return NO_ERROR;
227 } break;
228 case NOTE_RESET_CAMERA_TRANSACTION: {
229 CHECK_INTERFACE(IBatteryStats, data, reply);
230 noteResetCamera();
231 reply->writeNoException();
232 return NO_ERROR;
233 } break;
234 case NOTE_RESET_FLASHLIGHT_TRANSACTION: {
235 CHECK_INTERFACE(IBatteryStats, data, reply);
236 noteResetFlashlight();
237 reply->writeNoException();
238 return NO_ERROR;
239 } break;
240 default:
241 return BBinder::onTransact(code, data, reply, flags);
242 }
243 }
244
245 }; // namespace android
246