• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 class BpPowerManager : public BpInterface<IPowerManager>
31 {
32 public:
BpPowerManager(const sp<IBinder> & impl)33     BpPowerManager(const sp<IBinder>& impl)
34         : BpInterface<IPowerManager>(impl)
35     {
36     }
37 
acquireWakeLock(int flags,const sp<IBinder> & lock,const String16 & tag,const String16 & packageName,bool isOneWay)38     virtual status_t acquireWakeLock(int flags, const sp<IBinder>& lock, const String16& tag,
39             const String16& packageName, bool isOneWay)
40     {
41         Parcel data, reply;
42         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
43 
44         data.writeStrongBinder(lock);
45         data.writeInt32(flags);
46         data.writeString16(tag);
47         data.writeString16(packageName);
48         data.writeInt32(0); // no WorkSource
49         data.writeString16(NULL, 0); // no history tag
50         return remote()->transact(ACQUIRE_WAKE_LOCK, data, &reply,
51                 isOneWay ? IBinder::FLAG_ONEWAY : 0);
52     }
53 
acquireWakeLockWithUid(int flags,const sp<IBinder> & lock,const String16 & tag,const String16 & packageName,int uid,bool isOneWay)54     virtual status_t acquireWakeLockWithUid(int flags, const sp<IBinder>& lock, const String16& tag,
55             const String16& packageName, int uid, bool isOneWay)
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
65         return remote()->transact(ACQUIRE_WAKE_LOCK_UID, data, &reply,
66                 isOneWay ? IBinder::FLAG_ONEWAY : 0);
67     }
68 
releaseWakeLock(const sp<IBinder> & lock,int flags,bool isOneWay)69     virtual status_t releaseWakeLock(const sp<IBinder>& lock, int flags, bool isOneWay)
70     {
71         Parcel data, reply;
72         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
73         data.writeStrongBinder(lock);
74         data.writeInt32(flags);
75         return remote()->transact(RELEASE_WAKE_LOCK, data, &reply,
76                 isOneWay ? IBinder::FLAG_ONEWAY : 0);
77     }
78 
updateWakeLockUids(const sp<IBinder> & lock,int len,const int * uids,bool isOneWay)79     virtual status_t updateWakeLockUids(const sp<IBinder>& lock, int len, const int *uids,
80             bool isOneWay) {
81         Parcel data, reply;
82         data.writeInterfaceToken(IPowerManager::getInterfaceDescriptor());
83         data.writeStrongBinder(lock);
84         data.writeInt32Array(len, uids);
85         return remote()->transact(UPDATE_WAKE_LOCK_UIDS, data, &reply,
86                 isOneWay ? IBinder::FLAG_ONEWAY : 0);
87     }
88 
powerHint(int hintId,int param)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);
95         // This FLAG_ONEWAY is in the .aidl, so there is no way to disable it
96         return remote()->transact(POWER_HINT, data, &reply, IBinder::FLAG_ONEWAY);
97     }
98 
goToSleep(int64_t event_time_ms,int reason,int flags)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 
reboot(bool confirm,const String16 & reason,bool wait)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 
shutdown(bool confirm,const String16 & reason,bool wait)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 
crash(const String16 & message)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     }
136 };
137 
138 IMPLEMENT_META_INTERFACE(PowerManager, "android.os.IPowerManager");
139 
140 // ----------------------------------------------------------------------------
141 
142 }; // namespace android
143