1 /* 2 * Copyright (C) 2015 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 #ifndef SYSTEM_NATIVEPOWER_INCLUDE_NATIVEPOWER_WAKE_LOCK_H_ 18 #define SYSTEM_NATIVEPOWER_INCLUDE_NATIVEPOWER_WAKE_LOCK_H_ 19 20 #include <string> 21 22 #include <base/macros.h> 23 #include <utils/StrongPointer.h> 24 25 namespace android { 26 27 class IBinder; 28 class PowerManagerClient; 29 30 // RAII-style class that prevents the system from suspending. 31 // 32 // Instantiate by calling PowerManagerClient::CreateWakeLock(). 33 class WakeLock { 34 public: 35 ~WakeLock(); 36 37 private: 38 friend class PowerManagerClient; 39 40 // Ownership of |client| remains with the caller. 41 WakeLock(const std::string& tag, 42 const std::string& package, 43 PowerManagerClient* client); 44 45 // Initializes the object and acquires the lock, returning true on success. 46 bool Init(); 47 48 // Was a lock successfully acquired from the power manager? 49 bool acquired_lock_; 50 51 std::string tag_; 52 std::string package_; 53 54 // Weak pointer to the client that created this wake lock. 55 PowerManagerClient* client_; 56 57 // Locally-created binder passed to the power manager. 58 sp<IBinder> lock_binder_; 59 60 DISALLOW_COPY_AND_ASSIGN(WakeLock); 61 }; 62 63 } // namespace android 64 65 #endif // SYSTEM_NATIVEPOWER_INCLUDE_NATIVEPOWER_WAKE_LOCK_H_ 66