blob: 5702151ca5d67a8deb0a976fac76944ea49a063e [file] [log] [blame]
Mike Lockwood63ff1c62013-09-25 09:28:41 -07001/*
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
Mike Lockwood63ff1c62013-09-25 09:28:41 -070019#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
54IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats");
55
56// ----------------------------------------------------------------------
57
58status_t BnBatteryStats::onTransact(
59 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
60{
61 switch(code) {
62 case NOTE_START_SENSOR_TRANSACTION: {
63 CHECK_INTERFACE(IBatteryStats, data, reply);
64 int uid = data.readInt32();
65 int sensor = data.readInt32();
66 noteStartSensor(uid, sensor);
67 reply->writeNoException();
68 return NO_ERROR;
69 } break;
70 case NOTE_STOP_SENSOR_TRANSACTION: {
71 CHECK_INTERFACE(IBatteryStats, data, reply);
72 int uid = data.readInt32();
73 int sensor = data.readInt32();
74 noteStopSensor(uid, sensor);
75 reply->writeNoException();
76 return NO_ERROR;
77 } break;
78 default:
79 return BBinder::onTransact(code, data, reply, flags);
80 }
81}
82
83}; // namespace android