2 * Copyright 2018 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_SYSTEM_SYSTEM_SUSPEND_V1_0_H
18 #define ANDROID_SYSTEM_SYSTEM_SUSPEND_V1_0_H
20 #include <android-base/unique_fd.h>
21 #include <android/system/suspend/1.0/ISystemSuspend.h>
23 #include <condition_variable>
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;
40 std::string readFd(int fd);
42 class WakeLock : public IWakeLock {
44 WakeLock(SystemSuspend* systemSuspend);
48 SystemSuspend* mSystemSuspend;
51 class SystemSuspend : public ISystemSuspend {
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();
61 void initAutosuspend();
63 std::mutex mCounterLock;
64 std::condition_variable mCounterCondVar;
65 uint32_t mSuspendCounter;
66 unique_fd mWakeupCountFd;
71 } // namespace suspend
73 } // namespace android
75 #endif // ANDROID_SYSTEM_SYSTEM_SUSPEND_V1_0_H