1 /*
2  * Copyright 2021 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 #pragma once
18 
19 #include <android/system/suspend/1.0/ISystemSuspend.h>
20 
21 #include <string>
22 
23 #include "SystemSuspend.h"
24 
25 namespace android {
26 namespace system {
27 namespace suspend {
28 namespace V1_0 {
29 
30 using ::android::hardware::hidl_string;
31 using ::android::hardware::Return;
32 
33 class WakeLock : public IWakeLock {
34    public:
35     WakeLock(SystemSuspend* systemSuspend, const std::string& name, int pid);
36     ~WakeLock();
37 
38     Return<void> release();
39 
40    private:
41     inline void releaseOnce();
42     std::once_flag mReleased;
43 
44     SystemSuspend* mSystemSuspend;
45     std::string mName;
46     int mPid;
47 };
48 
49 class SystemSuspendHidl : public ISystemSuspend {
50    public:
51     SystemSuspendHidl(SystemSuspend* systemSuspend);
52     Return<sp<IWakeLock>> acquireWakeLock(WakeLockType type, const hidl_string& name) override;
53 
54    private:
55     SystemSuspend* mSystemSuspend;
56 };
57 
58 }  // namespace V1_0
59 }  // namespace suspend
60 }  // namespace system
61 }  // namespace android
62