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 package androidx.window.extensions;
18 
19 import androidx.window.extensions.area.WindowAreaComponent;
20 import androidx.window.extensions.embedding.ActivityEmbeddingComponent;
21 import androidx.window.extensions.layout.WindowLayoutComponent;
22 
23 import org.jspecify.annotations.Nullable;
24 
25 /**
26  * A class to provide instances of different WindowManager Jetpack extension components. An OEM must
27  * implement all the availability methods to state which WindowManager Jetpack extension
28  * can be used. If a component is not available then the check must return {@code false}. Trying to
29  * get a component that is not available will throw an {@link UnsupportedOperationException}.
30  * All components must support the API level returned in
31  * {@link WindowExtensions#getVendorApiLevel()}.
32  */
33 public interface WindowExtensions {
34 
35     /**
36      * Returns the API level of the vendor library on the device. If the returned version is not
37      * supported by the WindowManager library, then some functions may not be available or replaced
38      * with stub implementations.
39      *
40      * The expected use case is for the WindowManager library to determine which APIs are
41      * available and wrap the API so that app developers do not need to deal with the complexity.
42      * @return the API level supported by the library.
43      */
getVendorApiLevel()44     default int getVendorApiLevel() {
45         throw new RuntimeException("Not implemented. Must override in a subclass.");
46     }
47 
48     /**
49      * Returns the OEM implementation of {@link WindowLayoutComponent} if it is supported on the
50      * device, {@code null} otherwise. The implementation must match the API level reported in
51      * {@link WindowExtensions}.
52      * @return the OEM implementation of {@link WindowLayoutComponent}
53      */
getWindowLayoutComponent()54     @Nullable WindowLayoutComponent getWindowLayoutComponent();
55 
56     /**
57      * Returns the OEM implementation of {@link ActivityEmbeddingComponent} if it is supported on
58      * the device, {@code null} otherwise. The implementation must match the API level reported in
59      * {@link WindowExtensions}.
60      * @return the OEM implementation of {@link ActivityEmbeddingComponent}
61      */
getActivityEmbeddingComponent()62     default @Nullable ActivityEmbeddingComponent getActivityEmbeddingComponent() {
63         return null;
64     }
65 
66     /**
67      * Returns the OEM implementation of {@link WindowAreaComponent} if it is supported on
68      * the device, {@code null} otherwise. The implementation must match the API level reported in
69      * {@link WindowExtensions}.
70      * @return the OEM implementation of {@link WindowAreaComponent}
71      */
getWindowAreaComponent()72     default @Nullable WindowAreaComponent getWindowAreaComponent() {
73         return null;
74     }
75 }
76