Mike Lockwood | 63ff1c6 | 2013-09-25 09:28:41 -0700 | [diff] [blame^] | 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/Debug.h> |
| 20 | #include <utils/Log.h> |
| 21 | #include <binder/Parcel.h> |
| 22 | #include <utils/String8.h> |
| 23 | |
| 24 | #include <private/binder/Static.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | // ---------------------------------------------------------------------- |
| 29 | |
| 30 | class BpBatteryStats : public BpInterface<IBatteryStats> |
| 31 | { |
| 32 | public: |
| 33 | BpBatteryStats(const sp<IBinder>& impl) |
| 34 | : BpInterface<IBatteryStats>(impl) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | virtual void noteStartSensor(int uid, int sensor) { |
| 39 | Parcel data, reply; |
| 40 | data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor()); |
| 41 | data.writeInt32(uid); |
| 42 | data.writeInt32(sensor); |
| 43 | remote()->transact(NOTE_START_SENSOR_TRANSACTION, data, &reply); |
| 44 | } |
| 45 | |
| 46 | virtual void noteStopSensor(int uid, int sensor) { |
| 47 | Parcel data, reply; |
| 48 | data.writeInterfaceToken(IBatteryStats::getInterfaceDescriptor()); |
| 49 | data.writeInt32(uid); |
| 50 | data.writeInt32(sensor); |
| 51 | remote()->transact(NOTE_STOP_SENSOR_TRANSACTION, data, &reply); |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | IMPLEMENT_META_INTERFACE(BatteryStats, "com.android.internal.app.IBatteryStats"); |
| 56 | |
| 57 | // ---------------------------------------------------------------------- |
| 58 | |
| 59 | status_t BnBatteryStats::onTransact( |
| 60 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 61 | { |
| 62 | switch(code) { |
| 63 | case NOTE_START_SENSOR_TRANSACTION: { |
| 64 | CHECK_INTERFACE(IBatteryStats, data, reply); |
| 65 | int uid = data.readInt32(); |
| 66 | int sensor = data.readInt32(); |
| 67 | noteStartSensor(uid, sensor); |
| 68 | reply->writeNoException(); |
| 69 | return NO_ERROR; |
| 70 | } break; |
| 71 | case NOTE_STOP_SENSOR_TRANSACTION: { |
| 72 | CHECK_INTERFACE(IBatteryStats, data, reply); |
| 73 | int uid = data.readInt32(); |
| 74 | int sensor = data.readInt32(); |
| 75 | noteStopSensor(uid, sensor); |
| 76 | reply->writeNoException(); |
| 77 | return NO_ERROR; |
| 78 | } break; |
| 79 | default: |
| 80 | return BBinder::onTransact(code, data, reply, flags); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | }; // namespace android |