blob: 0c43e909e49b987022b3a3532811d0c17f82f8e0 [file] [log] [blame]
Colin Crossb731ae02012-03-28 13:55:43 -07001/*
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,
Marco Nelissen9a7706b2013-10-02 12:42:20 -070033 ACQUIRE_WAKE_LOCK_UID = IBinder::FIRST_CALL_TRANSACTION + 1,
34 RELEASE_WAKE_LOCK = IBinder::FIRST_CALL_TRANSACTION + 2,
Marco Nelissen5c0106e2013-10-16 10:57:51 -070035 UPDATE_WAKE_LOCK_UIDS = IBinder::FIRST_CALL_TRANSACTION + 3,
Ruchi Kandoica13fa72014-04-02 12:54:45 -070036 POWER_HINT = IBinder::FIRST_CALL_TRANSACTION + 4,
Colin Crossb731ae02012-03-28 13:55:43 -070037};
38
39class BpPowerManager : public BpInterface<IPowerManager>
40{
41public:
42 BpPowerManager(const sp<IBinder>& impl)
43 : BpInterface<IPowerManager>(impl)
44 {
45 }
46
Dianne Hackborn80d7fd82013-05-20 11:24:31 -070047 virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag,
48 const String16& packageName)
Colin Crossb731ae02012-03-28 13:55:43 -070049 {
50 Parcel data, reply;
51 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
52
Colin Crossb731ae02012-03-28 13:55:43 -070053 data.writeStrongBinder(lock);
Jeff Brownac1f70b2012-07-27 18:07:41 -070054 data.writeInt32(flags);
Colin Crossb731ae02012-03-28 13:55:43 -070055 data.writeString16(tag);
Dianne Hackborn80d7fd82013-05-20 11:24:31 -070056 data.writeString16(packageName);
Jeff Brownac1f70b2012-07-27 18:07:41 -070057 data.writeInt32(0); // no WorkSource
Colin Crossb731ae02012-03-28 13:55:43 -070058 return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply);
59 }
60
Marco Nelissen9a7706b2013-10-02 12:42:20 -070061 virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag,
62 const String16& packageName, int uid)
63 {
64 Parcel data, reply;
65 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
66
67 data.writeStrongBinder(lock);
68 data.writeInt32(flags);
69 data.writeString16(tag);
70 data.writeString16(packageName);
71 data.writeInt32(uid); // uid to blame for the work
72 return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply);
73 }
74
Colin Crossb731ae02012-03-28 13:55:43 -070075 virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags)
76 {
77 Parcel data, reply;
78 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
79 data.writeStrongBinder(lock);
80 data.writeInt32(flags);
81 return remote()->transact(RELEASE_WAKE_LOCK, data, &reply);
82 }
Marco Nelissen5c0106e2013-10-16 10:57:51 -070083
84 virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids) {
85 Parcel data, reply;
86 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
87 data.writeStrongBinder(lock);
88 data.writeInt32Array(len, uids);
89 // We don't really care too much if this succeeds (there's nothing we can do if it doesn't)
90 // but it should return ASAP
91 return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply, IBinder::FLAG_ONEWAY);
92 }
Ruchi Kandoica13fa72014-04-02 12:54:45 -070093
94 virtual status_t powerHint(int hintId, int param)
95 {
96 Parcel data, reply;
97 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
98 data.writeInt32(hintId);
99 data.writeInt32(param);
100 return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY);
101 }
Colin Crossb731ae02012-03-28 13:55:43 -0700102};
103
104IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager");
105
106// ----------------------------------------------------------------------------
107
108}; // namespace android