1 /* 2 * Copyright (C) 2019 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 #include "V2_0/ScopedWakelock.h" 18 19 namespace android { 20 namespace hardware { 21 namespace sensors { 22 namespace V2_0 { 23 namespace implementation { 24 getTimeNow()25int64_t getTimeNow() { 26 return std::chrono::duration_cast<std::chrono::nanoseconds>( 27 std::chrono::system_clock::now().time_since_epoch()) 28 .count(); 29 } 30 ScopedWakelock(ScopedWakelock && other)31ScopedWakelock::ScopedWakelock(ScopedWakelock&& other) { 32 *this = std::move(other); 33 } 34 operator =(ScopedWakelock && other)35ScopedWakelock& ScopedWakelock::operator=(ScopedWakelock&& other) { 36 mRefCounter = other.mRefCounter; 37 mCreatedAtTimeNs = other.mCreatedAtTimeNs; 38 mLocked = other.mLocked; 39 40 other.mRefCounter = nullptr; 41 other.mCreatedAtTimeNs = 0; 42 other.mLocked = false; 43 return *this; 44 } 45 ScopedWakelock(IScopedWakelockRefCounter * refCounter,bool locked)46ScopedWakelock::ScopedWakelock(IScopedWakelockRefCounter* refCounter, bool locked) 47 : mRefCounter(refCounter), mLocked(locked) { 48 if (mLocked) { 49 mLocked = mRefCounter->incrementRefCountAndMaybeAcquireWakelock(1, &mCreatedAtTimeNs); 50 } 51 } 52 ~ScopedWakelock()53ScopedWakelock::~ScopedWakelock() { 54 if (mLocked) { 55 mRefCounter->decrementRefCountAndMaybeReleaseWakelock(1, mCreatedAtTimeNs); 56 } 57 } 58 59 } // namespace implementation 60 } // namespace V2_0 61 } // namespace sensors 62 } // namespace hardware 63 } // namespace android