OSDN Git Service

System suspend HAL implementation.
[android-x86/system-hardware-interfaces.git] / suspend / 1.0 / default / SystemSuspend.h
1 /*
2  * Copyright 2018 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 ANDROID_SYSTEM_SYSTEM_SUSPEND_V1_0_H
18 #define ANDROID_SYSTEM_SYSTEM_SUSPEND_V1_0_H
19
20 #include <android-base/unique_fd.h>
21 #include <android/system/suspend/1.0/ISystemSuspend.h>
22
23 #include <condition_variable>
24 #include <mutex>
25 #include <string>
26
27 namespace android {
28 namespace system {
29 namespace suspend {
30 namespace V1_0 {
31
32 using ::android::base::unique_fd;
33 using ::android::hardware::hidl_handle;
34 using ::android::hardware::hidl_string;
35 using ::android::hardware::hidl_vec;
36 using ::android::hardware::Return;
37
38 class SystemSuspend;
39
40 std::string readFd(int fd);
41
42 class WakeLock : public IWakeLock {
43    public:
44     WakeLock(SystemSuspend* systemSuspend);
45     ~WakeLock();
46
47    private:
48     SystemSuspend* mSystemSuspend;
49 };
50
51 class SystemSuspend : public ISystemSuspend {
52    public:
53     SystemSuspend(unique_fd wakeupCountFd, unique_fd stateFd);
54     Return<bool> enableAutosuspend() override;
55     Return<sp<IWakeLock>> acquireWakeLock() override;
56     Return<void> debug(const hidl_handle& handle, const hidl_vec<hidl_string>& options) override;
57     void incSuspendCounter();
58     void decSuspendCounter();
59
60    private:
61     void initAutosuspend();
62
63     std::mutex mCounterLock;
64     std::condition_variable mCounterCondVar;
65     uint32_t mSuspendCounter;
66     unique_fd mWakeupCountFd;
67     unique_fd mStateFd;
68 };
69
70 }  // namespace V1_0
71 }  // namespace suspend
72 }  // namespace system
73 }  // namespace android
74
75 #endif  // ANDROID_SYSTEM_SYSTEM_SUSPEND_V1_0_H