• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     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 };
93 
94 IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats");
95 
96 // ----------------------------------------------------------------------
97 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)98 status_t BnBatteryStats::onTransact(
99     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
100 {
101     switch(code) {
102         case NOTE_START_SENSOR_TRANSACTION: {
103             CHECK_INTERFACE(IBatteryStats, data, reply);
104             int uid = data.readInt32();
105             int sensor = data.readInt32();
106             noteStartSensor(uid, sensor);
107             reply->writeNoException();
108             return NO_ERROR;
109         } break;
110         case NOTE_STOP_SENSOR_TRANSACTION: {
111             CHECK_INTERFACE(IBatteryStats, data, reply);
112             int uid = data.readInt32();
113             int sensor = data.readInt32();
114             noteStopSensor(uid, sensor);
115             reply->writeNoException();
116             return NO_ERROR;
117         } break;
118         case NOTE_START_VIDEO_TRANSACTION: {
119             CHECK_INTERFACE(IBatteryStats, data, reply);
120             int uid = data.readInt32();
121             noteStartVideo(uid);
122             reply->writeNoException();
123             return NO_ERROR;
124         } break;
125         case NOTE_STOP_VIDEO_TRANSACTION: {
126             CHECK_INTERFACE(IBatteryStats, data, reply);
127             int uid = data.readInt32();
128             noteStopVideo(uid);
129             reply->writeNoException();
130             return NO_ERROR;
131         } break;
132         case NOTE_START_AUDIO_TRANSACTION: {
133             CHECK_INTERFACE(IBatteryStats, data, reply);
134             int uid = data.readInt32();
135             noteStartAudio(uid);
136             reply->writeNoException();
137             return NO_ERROR;
138         } break;
139         case NOTE_STOP_AUDIO_TRANSACTION: {
140             CHECK_INTERFACE(IBatteryStats, data, reply);
141             int uid = data.readInt32();
142             noteStopAudio(uid);
143             reply->writeNoException();
144             return NO_ERROR;
145         } break;
146         case NOTE_RESET_VIDEO_TRANSACTION: {
147             CHECK_INTERFACE(IBatteryStats, data, reply);
148             noteResetVideo();
149             reply->writeNoException();
150             return NO_ERROR;
151         } break;
152         case NOTE_RESET_AUDIO_TRANSACTION: {
153             CHECK_INTERFACE(IBatteryStats, data, reply);
154             noteResetAudio();
155             reply->writeNoException();
156             return NO_ERROR;
157         } break;
158         default:
159             return BBinder::onTransact(code, data, reply, flags);
160     }
161 }
162 
163 }; // namespace android
164