blob: bff871916fcfd35876bf50de7f401667076c3c25 [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
Colin Crossb731ae02012-03-28 13:55:43 -070030class BpPowerManager : public BpInterface<IPowerManager>
31{
32public:
33 BpPowerManager(const sp<IBinder>& impl)
34 : BpInterface<IPowerManager>(impl)
35 {
36 }
37
Dianne Hackborn80d7fd82013-05-20 11:24:31 -070038 virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag,
Glenn Kastena6020862014-09-05 16:46:46 -070039 const String16& packageName, bool isOneWay)
Colin Crossb731ae02012-03-28 13:55:43 -070040 {
41 Parcel data, reply;
42 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
43
Colin Crossb731ae02012-03-28 13:55:43 -070044 data.writeStrongBinder(lock);
Jeff Brownac1f70b2012-07-27 18:07:41 -070045 data.writeInt32(flags);
Colin Crossb731ae02012-03-28 13:55:43 -070046 data.writeString16(tag);
Dianne Hackborn80d7fd82013-05-20 11:24:31 -070047 data.writeString16(packageName);
Jeff Brownac1f70b2012-07-27 18:07:41 -070048 data.writeInt32(0); // no WorkSource
Dianne Hackbornf74865e2014-04-03 12:06:48 -070049 data.writeString16(NULL, 0); // no history tag
Glenn Kastena6020862014-09-05 16:46:46 -070050 return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply,
51 isOneWay ? IBinder::FLAG_ONEWAY : 0);
Colin Crossb731ae02012-03-28 13:55:43 -070052 }
53
Marco Nelissen9a7706b2013-10-02 12:42:20 -070054 virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag,
Glenn Kastena6020862014-09-05 16:46:46 -070055 const String16& packageName, int uid, bool isOneWay)
Marco Nelissen9a7706b2013-10-02 12:42:20 -070056 {
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 Kastena6020862014-09-05 16:46:46 -070065 return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply,
66 isOneWay ? IBinder::FLAG_ONEWAY : 0);
Marco Nelissen9a7706b2013-10-02 12:42:20 -070067 }
68
Glenn Kastena6020862014-09-05 16:46:46 -070069 virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags, bool isOneWay)
Colin Crossb731ae02012-03-28 13:55:43 -070070 {
71 Parcel data, reply;
72 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
73 data.writeStrongBinder(lock);
74 data.writeInt32(flags);
Glenn Kastena6020862014-09-05 16:46:46 -070075 return remote()->transact(RELEASE_WAKE_LOCK, data, &reply,
76 isOneWay ? IBinder::FLAG_ONEWAY : 0);
Colin Crossb731ae02012-03-28 13:55:43 -070077 }
Marco Nelissen5c0106e2013-10-16 10:57:51 -070078
Glenn Kastena6020862014-09-05 16:46:46 -070079 virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids,
80 bool isOneWay) {
Marco Nelissen5c0106e2013-10-16 10:57:51 -070081 Parcel data, reply;
82 data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
83 data.writeStrongBinder(lock);
84 data.writeInt32Array(len, uids);
Glenn Kastena6020862014-09-05 16:46:46 -070085 return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply,
86 isOneWay ? IBinder::FLAG_ONEWAY : 0);
Marco Nelissen5c0106e2013-10-16 10:57:51 -070087 }
Ruchi Kandoica13fa72014-04-02 12:54:45 -070088
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 Kastena6020862014-09-05 16:46:46 -070095 // This FLAG_ONEWAY is in the .aidl, so there is no way to disable it
Ruchi Kandoica13fa72014-04-02 12:54:45 -070096 return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY);
97 }
Daniel Erat3f50a392015-09-30 14:49:15 -060098
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 Crossb731ae02012-03-28 13:55:43 -0700136};
137
138IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager");
139
140// ----------------------------------------------------------------------------
141
142}; // namespace android