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 <aidl/android/system/suspend/BnSystemSuspend.h> 20 #include <aidl/android/system/suspend/BnWakeLock.h> 21 22 #include <string> 23 24 #include "SystemSuspend.h" 25 26 namespace aidl { 27 namespace android { 28 namespace system { 29 namespace suspend { 30 31 using ::android::system::suspend::V1_0::SystemSuspend; 32 33 class WakeLock : public BnWakeLock { 34 public: 35 WakeLock(SystemSuspend* systemSuspend, const std::string& name, int pid); 36 ~WakeLock(); 37 38 ndk::ScopedAStatus release() override; 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 SystemSuspendAidl : public BnSystemSuspend { 50 public: 51 SystemSuspendAidl(SystemSuspend* systemSuspend); 52 ndk::ScopedAStatus acquireWakeLock(WakeLockType type, const std::string& name, 53 std::shared_ptr<IWakeLock>* _aidl_return) override; 54 55 private: 56 SystemSuspend* mSystemSuspend; 57 }; 58 59 } // namespace suspend 60 } // namespace system 61 } // namespace android 62 } // namespace aidl 63