1 /* 2 * Copyright (C) 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 android.view.WindowManager; 20 21 import androidx.annotation.NonNull; 22 import androidx.annotation.Nullable; 23 import androidx.window.extensions.area.WindowAreaComponent; 24 import androidx.window.extensions.embedding.ActivityEmbeddingComponent; 25 import androidx.window.extensions.layout.WindowLayoutComponent; 26 27 /** 28 * Provides the OEM implementation of {@link WindowExtensions}. 29 */ 30 public class WindowExtensionsProvider { 31 32 private static volatile WindowExtensions sWindowExtensions; 33 34 /** 35 * Returns the OEM implementation of {@link WindowExtensions}. This method is implemented in 36 * the library provided on the device and overwrites one in the Jetpack library included in 37 * apps. 38 * @return the OEM implementation of {@link WindowExtensions} 39 */ 40 @NonNull getWindowExtensions()41 public static WindowExtensions getWindowExtensions() { 42 if (sWindowExtensions == null) { 43 synchronized (WindowExtensionsProvider.class) { 44 if (sWindowExtensions == null) { 45 sWindowExtensions = WindowManager.hasWindowExtensionsEnabled() 46 ? new WindowExtensionsImpl() 47 : new DisabledWindowExtensions(); 48 } 49 } 50 } 51 return sWindowExtensions; 52 } 53 54 /** 55 * The stub version to return when the WindowManager Extensions is disabled 56 * @see WindowManager#hasWindowExtensionsEnabled 57 */ 58 private static class DisabledWindowExtensions implements WindowExtensions { 59 @Override getVendorApiLevel()60 public int getVendorApiLevel() { 61 return 0; 62 } 63 64 @Nullable 65 @Override getWindowLayoutComponent()66 public WindowLayoutComponent getWindowLayoutComponent() { 67 return null; 68 } 69 70 @Nullable 71 @Override getActivityEmbeddingComponent()72 public ActivityEmbeddingComponent getActivityEmbeddingComponent() { 73 return null; 74 } 75 76 @Nullable 77 @Override getWindowAreaComponent()78 public WindowAreaComponent getWindowAreaComponent() { 79 return null; 80 } 81 } 82 } 83