IPowerManager.cpp revision f74865eb525b34af7983777a522a5bfc496fc1c5
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 28namespace android { 29 30// must be kept in sync with IPowerManager.aidl 31enum { 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 UPDATE_WAKE_LOCK_UIDS = IBinder::FIRST_CALL_TRANSACTION + 3, 36 POWER_HINT = IBinder::FIRST_CALL_TRANSACTION + 4, 37}; 38 39class BpPowerManager : public BpInterface<IPowerManager> 40{ 41public: 42 BpPowerManager(const sp<IBinder>& impl) 43 : BpInterface<IPowerManager>(impl) 44 { 45 } 46 47 virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag, 48 const String16& packageName) 49 { 50 Parcel data, reply; 51 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 52 53 data.writeStrongBinder(lock); 54 data.writeInt32(flags); 55 data.writeString16(tag); 56 data.writeString16(packageName); 57 data.writeInt32(0); // no WorkSource 58 data.writeString16(NULL, 0); // no history tag 59 return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply); 60 } 61 62 virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag, 63 const String16& packageName, int uid) 64 { 65 Parcel data, reply; 66 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 67 68 data.writeStrongBinder(lock); 69 data.writeInt32(flags); 70 data.writeString16(tag); 71 data.writeString16(packageName); 72 data.writeInt32(uid); // uid to blame for the work 73 return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply); 74 } 75 76 virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags) 77 { 78 Parcel data, reply; 79 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 80 data.writeStrongBinder(lock); 81 data.writeInt32(flags); 82 return remote()->transact(RELEASE_WAKE_LOCK, data, &reply); 83 } 84 85 virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids) { 86 Parcel data, reply; 87 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 88 data.writeStrongBinder(lock); 89 data.writeInt32Array(len, uids); 90 // We don't really care too much if this succeeds (there's nothing we can do if it doesn't) 91 // but it should return ASAP 92 return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply, IBinder::FLAG_ONEWAY); 93 } 94 95 virtual status_t powerHint(int hintId, int param) 96 { 97 Parcel data, reply; 98 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor()); 99 data.writeInt32(hintId); 100 data.writeInt32(param); 101 return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY); 102 } 103}; 104 105IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager"); 106 107// ---------------------------------------------------------------------------- 108 109}; // namespace android 110