| 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 |  | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 30 | class BpPowerManager : public BpInterface<IPowerManager> | 
 | 31 | { | 
 | 32 | public: | 
| Chih-Hung Hsieh | 6ca70ef | 2016-04-29 16:23:55 -0700 | [diff] [blame] | 33 |     explicit BpPowerManager(const sp<IBinder>& impl) | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 34 |         : BpInterface<IPowerManager>(impl) | 
 | 35 |     { | 
 | 36 |     } | 
 | 37 |  | 
| Dianne Hackborn | 80d7fd8 | 2013-05-20 11:24:31 -0700 | [diff] [blame] | 38 |     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] | 39 |             const String16& packageName, bool isOneWay) | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 40 |     { | 
 | 41 |         Parcel data, reply; | 
 | 42 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 43 |  | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 44 |         data.writeStrongBinder(lock); | 
| Jeff Brown | ac1f70b | 2012-07-27 18:07:41 -0700 | [diff] [blame] | 45 |         data.writeInt32(flags); | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 46 |         data.writeString16(tag); | 
| Dianne Hackborn | 80d7fd8 | 2013-05-20 11:24:31 -0700 | [diff] [blame] | 47 |         data.writeString16(packageName); | 
| Jeff Brown | ac1f70b | 2012-07-27 18:07:41 -0700 | [diff] [blame] | 48 |         data.writeInt32(0); // no WorkSource | 
| Dianne Hackborn | f74865e | 2014-04-03 12:06:48 -0700 | [diff] [blame] | 49 |         data.writeString16(NULL, 0); // no history tag | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 50 |         return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply, | 
 | 51 |                 isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 52 |     } | 
 | 53 |  | 
| Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 54 |     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] | 55 |             const String16& packageName, int uid, bool isOneWay) | 
| Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 56 |     { | 
 | 57 |         Parcel data, reply; | 
 | 58 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 59 |  | 
 | 60 |         data.writeStrongBinder(lock); | 
 | 61 |         data.writeInt32(flags); | 
 | 62 |         data.writeString16(tag); | 
 | 63 |         data.writeString16(packageName); | 
 | 64 |         data.writeInt32(uid); // uid to blame for the work | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 65 |         return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply, | 
 | 66 |                 isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Marco Nelissen | 9a7706b | 2013-10-02 12:42:20 -0700 | [diff] [blame] | 67 |     } | 
 | 68 |  | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 69 |     virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags, bool isOneWay) | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 70 |     { | 
 | 71 |         Parcel data, reply; | 
 | 72 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 73 |         data.writeStrongBinder(lock); | 
 | 74 |         data.writeInt32(flags); | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 75 |         return remote()->transact(RELEASE_WAKE_LOCK, data, &reply, | 
 | 76 |                 isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 77 |     } | 
| Marco Nelissen | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 78 |  | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 79 |     virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids, | 
 | 80 |             bool isOneWay) { | 
| Marco Nelissen | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 81 |         Parcel data, reply; | 
 | 82 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 83 |         data.writeStrongBinder(lock); | 
 | 84 |         data.writeInt32Array(len, uids); | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 85 |         return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply, | 
 | 86 |                 isOneWay ? IBinder::FLAG_ONEWAY : 0); | 
| Marco Nelissen | 5c0106e | 2013-10-16 10:57:51 -0700 | [diff] [blame] | 87 |     } | 
| Ruchi Kandoi | ca13fa7 | 2014-04-02 12:54:45 -0700 | [diff] [blame] | 88 |  | 
 | 89 |     virtual status_t powerHint(int hintId, int param) | 
 | 90 |     { | 
 | 91 |         Parcel data, reply; | 
 | 92 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 93 |         data.writeInt32(hintId); | 
 | 94 |         data.writeInt32(param); | 
| Glenn Kasten | a602086 | 2014-09-05 16:46:46 -0700 | [diff] [blame] | 95 |         // 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] | 96 |         return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY); | 
 | 97 |     } | 
| Daniel Erat | 3f50a39 | 2015-09-30 14:49:15 -0600 | [diff] [blame] | 98 |  | 
 | 99 |     virtual status_t goToSleep(int64_t event_time_ms, int reason, int flags) | 
 | 100 |     { | 
 | 101 |         Parcel data, reply; | 
 | 102 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 103 |         data.writeInt64(event_time_ms); | 
 | 104 |         data.writeInt32(reason); | 
 | 105 |         data.writeInt32(flags); | 
 | 106 |         return remote()->transact(GO_TO_SLEEP, data, &reply, 0); | 
 | 107 |     } | 
 | 108 |  | 
 | 109 |     virtual status_t reboot(bool confirm, const String16& reason, bool wait) | 
 | 110 |     { | 
 | 111 |         Parcel data, reply; | 
 | 112 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 113 |         data.writeInt32(confirm); | 
 | 114 |         data.writeString16(reason); | 
 | 115 |         data.writeInt32(wait); | 
 | 116 |         return remote()->transact(REBOOT, data, &reply, 0); | 
 | 117 |     } | 
 | 118 |  | 
 | 119 |     virtual status_t shutdown(bool confirm, const String16& reason, bool wait) | 
 | 120 |     { | 
 | 121 |         Parcel data, reply; | 
 | 122 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 123 |         data.writeInt32(confirm); | 
 | 124 |         data.writeString16(reason); | 
 | 125 |         data.writeInt32(wait); | 
 | 126 |         return remote()->transact(SHUTDOWN, data, &reply, 0); | 
 | 127 |     } | 
 | 128 |  | 
 | 129 |     virtual status_t crash(const String16& message) | 
 | 130 |     { | 
 | 131 |         Parcel data, reply; | 
 | 132 |         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); | 
 | 133 |         data.writeString16(message); | 
 | 134 |         return remote()->transact(CRASH, data, &reply, 0); | 
 | 135 |     } | 
| Colin Cross | b731ae0 | 2012-03-28 13:55:43 -0700 | [diff] [blame] | 136 | }; | 
 | 137 |  | 
 | 138 | IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager"); | 
 | 139 |  | 
 | 140 | // ---------------------------------------------------------------------------- | 
 | 141 |  | 
 | 142 | }; // namespace android |