Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 "IPowerManager" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | |
| 24 | #include <binder/Parcel.h> |
| 25 | |
| 26 | #include <powermanager/IPowerManager.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | // must be kept in sync with IPowerManager.aidl |
| 31 | enum { |
| 32 | ACQUIRE_WAKE_LOCK = IBinder::FIRST_CALL_TRANSACTION, |
Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 33 | ACQUIRE_WAKE_LOCK_UID = IBinder::FIRST_CALL_TRANSACTION + 1, |
| 34 | RELEASE_WAKE_LOCK = IBinder::FIRST_CALL_TRANSACTION + 2, |
Marco Nelissen | 708cc79 | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 35 | UPDATE_WAKE_LOCK_UIDS = IBinder::FIRST_CALL_TRANSACTION + 3, |
Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | class BpPowerManager : public BpInterface<IPowerManager> |
| 39 | { |
| 40 | public: |
| 41 | BpPowerManager(const sp<IBinder>& impl) |
| 42 | : BpInterface<IPowerManager>(impl) |
| 43 | { |
| 44 | } |
| 45 | |
Dianne Hackborn | 80d7fd8 | 2013-05-20 11:24:31 -0700 | [diff] [blame] | 46 | virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag, |
| 47 | const String16& packageName) |
Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 48 | { |
| 49 | Parcel data, reply; |
| 50 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); |
| 51 | |
Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 52 | data.writeStrongBinder(lock); |
Jeff Brown | ac1f70b | 2012-07-27 18:07:41 -0700 | [diff] [blame] | 53 | data.writeInt32(flags); |
Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 54 | data.writeString16(tag); |
Dianne Hackborn | 80d7fd8 | 2013-05-20 11:24:31 -0700 | [diff] [blame] | 55 | data.writeString16(packageName); |
Jeff Brown | ac1f70b | 2012-07-27 18:07:41 -0700 | [diff] [blame] | 56 | data.writeInt32(0); // no WorkSource |
Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 57 | return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply); |
| 58 | } |
| 59 | |
Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 60 | virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag, |
| 61 | const String16& packageName, int uid) |
| 62 | { |
| 63 | Parcel data, reply; |
| 64 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); |
| 65 | |
| 66 | data.writeStrongBinder(lock); |
| 67 | data.writeInt32(flags); |
| 68 | data.writeString16(tag); |
| 69 | data.writeString16(packageName); |
| 70 | data.writeInt32(uid); // uid to blame for the work |
| 71 | return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply); |
| 72 | } |
| 73 | |
Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 74 | virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags) |
| 75 | { |
| 76 | Parcel data, reply; |
| 77 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); |
| 78 | data.writeStrongBinder(lock); |
| 79 | data.writeInt32(flags); |
| 80 | return remote()->transact(RELEASE_WAKE_LOCK, data, &reply); |
| 81 | } |
Marco Nelissen | 708cc79 | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 82 | |
| 83 | virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids) { |
| 84 | Parcel data, reply; |
| 85 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); |
| 86 | data.writeStrongBinder(lock); |
| 87 | data.writeInt32Array(len, uids); |
| 88 | // We don't really care too much if this succeeds (there's nothing we can do if it doesn't) |
| 89 | // but it should return ASAP |
| 90 | return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply, IBinder::FLAG_ONEWAY); |
| 91 | } |
Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager"); |
| 95 | |
| 96 | // ---------------------------------------------------------------------------- |
| 97 | |
| 98 | }; // namespace android |