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, 33 ACQUIRE_WAKE_LOCK_UID = IBinder::FIRST_CALL_TRANSACTION + 1, 34 RELEASE_WAKE_LOCK = IBinder::FIRST_CALL_TRANSACTION + 2, 35 }; 36 37 class BpPowerManager : public BpInterface<IPowerManager> 38 { 39 public: 40 BpPowerManager(const sp<IBinder>& impl) 41 : BpInterface<IPowerManager>(impl) 42 { 43 } 44 45 virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag, 46 const String16& packageName) 47 { 48 Parcel data, reply; 49 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 50 51 data.writeStrongBinder(lock); 52 data.writeInt32(flags); 53 data.writeString16(tag); 54 data.writeString16(packageName); 55 data.writeInt32(0); // no WorkSource 56 return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply); 57 } 58 59 virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag, 60 const String16& packageName, int uid) 61 { 62 Parcel data, reply; 63 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 64 65 data.writeStrongBinder(lock); 66 data.writeInt32(flags); 67 data.writeString16(tag); 68 data.writeString16(packageName); 69 data.writeInt32(uid); // uid to blame for the work 70 return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply); 71 } 72 73 virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags) 74 { 75 Parcel data, reply; 76 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 77 data.writeStrongBinder(lock); 78 data.writeInt32(flags); 79 return remote()->transact(RELEASE_WAKE_LOCK, data, &reply); 80 } 81 }; 82 83 IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager"); 84 85 // ---------------------------------------------------------------------------- 86 87 }; // namespace android 88