blob: 82bde622e8c6bdc23325297aee4697122f27e905 [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 }
Chong Zhangbd42d382014-07-22 09:12:21 -070052
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 }
Mike Lockwood63ff1c62013-09-25 09:28:41 -070080};
81
82IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats");
83
84// ----------------------------------------------------------------------
85
86status_t BnBatteryStats::onTransact(
87 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
88{
89 switch(code) {
90 case NOTE_START_SENSOR_TRANSACTION: {
91 CHECK_INTERFACE(IBatteryStats, data, reply);
92 int uid = data.readInt32();
93 int sensor = data.readInt32();
94 noteStartSensor(uid, sensor);
95 reply->writeNoException();
96 return NO_ERROR;
97 } break;
98 case NOTE_STOP_SENSOR_TRANSACTION: {
99 CHECK_INTERFACE(IBatteryStats, data, reply);
100 int uid = data.readInt32();
101 int sensor = data.readInt32();
102 noteStopSensor(uid, sensor);
103 reply->writeNoException();
104 return NO_ERROR;
105 } break;
Chong Zhangbd42d382014-07-22 09:12:21 -0700106 case NOTE_START_VIDEO_TRANSACTION: {
107 CHECK_INTERFACE(IBatteryStats, data, reply);
108 int uid = data.readInt32();
109 noteStartVideo(uid);
110 reply->writeNoException();
111 return NO_ERROR;
112 } break;
113 case NOTE_STOP_VIDEO_TRANSACTION: {
114 CHECK_INTERFACE(IBatteryStats, data, reply);
115 int uid = data.readInt32();
116 noteStopVideo(uid);
117 reply->writeNoException();
118 return NO_ERROR;
119 } break;
120 case NOTE_START_AUDIO_TRANSACTION: {
121 CHECK_INTERFACE(IBatteryStats, data, reply);
122 int uid = data.readInt32();
123 noteStartAudio(uid);
124 reply->writeNoException();
125 return NO_ERROR;
126 } break;
127 case NOTE_STOP_AUDIO_TRANSACTION: {
128 CHECK_INTERFACE(IBatteryStats, data, reply);
129 int uid = data.readInt32();
130 noteStopAudio(uid);
131 reply->writeNoException();
132 return NO_ERROR;
133 } break;
Mike Lockwood63ff1c62013-09-25 09:28:41 -0700134 default:
135 return BBinder::onTransact(code, data, reply, flags);
136 }
137}
138
139}; // namespace android