• 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 #define LOG_TAG "IBatteryPropertiesRegistrar"
18 //#define LOG_NDEBUG 0
19 #include <utils/Log.h>
20 
21 #include <batteryservice/IBatteryPropertiesListener.h>
22 #include <batteryservice/IBatteryPropertiesRegistrar.h>
23 #include <stdint.h>
24 #include <sys/types.h>
25 #include <binder/Parcel.h>
26 
27 namespace android {
28 
29 class BpBatteryPropertiesRegistrar : public BpInterface<IBatteryPropertiesRegistrar> {
30 public:
BpBatteryPropertiesRegistrar(const sp<IBinder> & impl)31     BpBatteryPropertiesRegistrar(const sp<IBinder>& impl)
32         : BpInterface<IBatteryPropertiesRegistrar>(impl) {}
33 
registerListener(const sp<IBatteryPropertiesListener> & listener)34         void registerListener(const sp<IBatteryPropertiesListener>& listener) {
35             Parcel data;
36             data.writeInterfaceToken(IBatteryPropertiesRegistrar::getInterfaceDescriptor());
37             data.writeStrongBinder(listener->asBinder());
38             remote()->transact(REGISTER_LISTENER, data, NULL);
39         }
40 
unregisterListener(const sp<IBatteryPropertiesListener> & listener)41         void unregisterListener(const sp<IBatteryPropertiesListener>& listener) {
42             Parcel data;
43             data.writeInterfaceToken(IBatteryPropertiesRegistrar::getInterfaceDescriptor());
44             data.writeStrongBinder(listener->asBinder());
45             remote()->transact(UNREGISTER_LISTENER, data, NULL);
46         }
47 };
48 
49 IMPLEMENT_META_INTERFACE(BatteryPropertiesRegistrar, "android.os.IBatteryPropertiesRegistrar");
50 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)51 status_t BnBatteryPropertiesRegistrar::onTransact(uint32_t code,
52                                                   const Parcel& data,
53                                                   Parcel* reply,
54                                                   uint32_t flags)
55 {
56     switch(code) {
57         case REGISTER_LISTENER: {
58             CHECK_INTERFACE(IBatteryPropertiesRegistrar, data, reply);
59             sp<IBatteryPropertiesListener> listener =
60                 interface_cast<IBatteryPropertiesListener>(data.readStrongBinder());
61             registerListener(listener);
62             return OK;
63         }
64 
65         case UNREGISTER_LISTENER: {
66             CHECK_INTERFACE(IBatteryPropertiesRegistrar, data, reply);
67             sp<IBatteryPropertiesListener> listener =
68                 interface_cast<IBatteryPropertiesListener>(data.readStrongBinder());
69             unregisterListener(listener);
70             return OK;
71         }
72     }
73     return BBinder::onTransact(code, data, reply, flags);
74 };
75 
76 // ----------------------------------------------------------------------------
77 
78 }; // namespace android
79