| 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 | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 35 | UPDATE_WAKE_LOCK_UIDS = IBinder::FIRST_CALL_TRANSACTION + 3, | 
| Ruchi Kandoi | ca13fa7 | 2014-04-02 12:54:45 -0700 | [diff] [blame] | 36 | POWER_HINT = IBinder::FIRST_CALL_TRANSACTION + 4, | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 37 | }; | 
|  | 38 |  | 
|  | 39 | class BpPowerManager : public BpInterface<IPowerManager> | 
|  | 40 | { | 
|  | 41 | public: | 
|  | 42 | BpPowerManager(const sp<IBinder>& impl) | 
|  | 43 | : BpInterface<IPowerManager>(impl) | 
|  | 44 | { | 
|  | 45 | } | 
|  | 46 |  | 
| Dianne Hackborn | 80d7fd8 | 2013-05-20 11:24:31 -0700 | [diff] [blame] | 47 | virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag, | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 48 | const String16& packageName, bool isOneWay) | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 49 | { | 
|  | 50 | Parcel data, reply; | 
|  | 51 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
|  | 52 |  | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 53 | data.writeStrongBinder(lock); | 
| Jeff Brown | ac1f70b | 2012-07-27 18:07:41 -0700 | [diff] [blame] | 54 | data.writeInt32(flags); | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 55 | data.writeString16(tag); | 
| Dianne Hackborn | 80d7fd8 | 2013-05-20 11:24:31 -0700 | [diff] [blame] | 56 | data.writeString16(packageName); | 
| Jeff Brown | ac1f70b | 2012-07-27 18:07:41 -0700 | [diff] [blame] | 57 | data.writeInt32(0); // no WorkSource | 
| Dianne Hackborn | f74865e | 2014-04-03 12:06:48 -0700 | [diff] [blame] | 58 | data.writeString16(NULL, 0); // no history tag | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 59 | return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply, | 
|  | 60 | isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 61 | } | 
|  | 62 |  | 
| Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 63 | virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag, | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 64 | const String16& packageName, int uid, bool isOneWay) | 
| Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 65 | { | 
|  | 66 | Parcel data, reply; | 
|  | 67 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
|  | 68 |  | 
|  | 69 | data.writeStrongBinder(lock); | 
|  | 70 | data.writeInt32(flags); | 
|  | 71 | data.writeString16(tag); | 
|  | 72 | data.writeString16(packageName); | 
|  | 73 | data.writeInt32(uid); // uid to blame for the work | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 74 | return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply, | 
|  | 75 | isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 76 | } | 
|  | 77 |  | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 78 | virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags, bool isOneWay) | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 79 | { | 
|  | 80 | Parcel data, reply; | 
|  | 81 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
|  | 82 | data.writeStrongBinder(lock); | 
|  | 83 | data.writeInt32(flags); | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 84 | return remote()->transact(RELEASE_WAKE_LOCK, data, &reply, | 
|  | 85 | isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 86 | } | 
| Marco Nelissen | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 87 |  | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 88 | virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids, | 
|  | 89 | bool isOneWay) { | 
| Marco Nelissen | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 90 | Parcel data, reply; | 
|  | 91 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
|  | 92 | data.writeStrongBinder(lock); | 
|  | 93 | data.writeInt32Array(len, uids); | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 94 | return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply, | 
|  | 95 | isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Marco Nelissen | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 96 | } | 
| Ruchi Kandoi | ca13fa7 | 2014-04-02 12:54:45 -0700 | [diff] [blame] | 97 |  | 
|  | 98 | virtual status_t powerHint(int hintId, int param) | 
|  | 99 | { | 
|  | 100 | Parcel data, reply; | 
|  | 101 | data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
|  | 102 | data.writeInt32(hintId); | 
|  | 103 | data.writeInt32(param); | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 104 | // This FLAG_ONEWAY is in the .aidl, so there is no way to disable it | 
| Ruchi Kandoi | ca13fa7 | 2014-04-02 12:54:45 -0700 | [diff] [blame] | 105 | return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY); | 
|  | 106 | } | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 107 | }; | 
|  | 108 |  | 
|  | 109 | IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager"); | 
|  | 110 |  | 
|  | 111 | // ---------------------------------------------------------------------------- | 
|  | 112 |  | 
|  | 113 | }; // namespace android |