1 /*
2  * Copyright 2022 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 package androidx.hardware
18 
19 import android.hardware.SyncFence
20 import android.os.Build
21 import androidx.annotation.RequiresApi
22 import java.time.Duration
23 
24 @RequiresApi(Build.VERSION_CODES.TIRAMISU)
25 internal class SyncFenceV33 internal constructor(syncFence: SyncFence) : SyncFenceImpl {
26     internal val mSyncFence: SyncFence = syncFence
27 
28     /** See [SyncFenceImpl.await] */
awaitnull29     override fun await(timeoutNanos: Long): Boolean {
30         return mSyncFence.await(Duration.ofNanos(timeoutNanos))
31     }
32 
33     /** See [SyncFenceImpl.awaitForever] */
awaitForevernull34     override fun awaitForever(): Boolean {
35         return mSyncFence.awaitForever()
36     }
37 
38     /** See [SyncFenceImpl.close] */
closenull39     override fun close() {
40         mSyncFence.close()
41     }
42 
43     /** See [SyncFenceImpl.getSignalTimeNanos] */
getSignalTimeNanosnull44     override fun getSignalTimeNanos(): Long {
45         return mSyncFence.signalTime
46     }
47 
48     /**
49      * Checks if the SyncFence object is valid.
50      *
51      * @return `true` if it is valid, `false` otherwise
52      */
isValidnull53     override fun isValid(): Boolean {
54         return mSyncFence.isValid
55     }
56 }
57