1 /*
2  * Copyright 2020 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.camera.camera2.pipe
18 
19 import androidx.annotation.RestrictTo
20 import kotlin.reflect.KClass
21 
22 /**
23  * An interface for wrapper objects that should not normally be accessed directly.
24  *
25  * This interface indicates that an object or interface wraps a specific Android object or type and
26  * provides a way to retrieve the underlying object directly. Accessing the underlying objects can
27  * be useful for compatibility and testing, but is extremely risky if the state or lifetime of the
28  * of the object is managed by CameraPipe.
29  */
30 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
31 public interface UnsafeWrapper {
32     /**
33      * Attempt to unwrap this object into an underlying type.
34      *
35      * This operation is not safe and should be used with caution as it makes no guarantees about
36      * the state of the underlying objects. In particular, implementations should assume that fakes,
37      * test wrappers will always return null. Finally this method should return null when unwrapping
38      * into the provided type is not supported.
39      *
40      * @return unwrapped object matching T or null
41      */
unwrapAsnull42     public fun <T : Any> unwrapAs(type: KClass<T>): T?
43 }
44