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.app.ActivityThread; 20 import android.content.Context; 21 22 import androidx.annotation.NonNull; 23 import androidx.window.extensions.embedding.ActivityEmbeddingComponent; 24 import androidx.window.extensions.embedding.SplitController; 25 import androidx.window.extensions.layout.WindowLayoutComponent; 26 import androidx.window.extensions.layout.WindowLayoutComponentImpl; 27 28 /** 29 * The reference implementation of {@link WindowExtensions} that implements the initial API version. 30 */ 31 public class WindowExtensionsImpl implements WindowExtensions { 32 33 private final Object mLock = new Object(); 34 private volatile WindowLayoutComponent mWindowLayoutComponent; 35 private volatile SplitController mSplitController; 36 37 @Override getVendorApiLevel()38 public int getVendorApiLevel() { 39 return 1; 40 } 41 42 /** 43 * Returns a reference implementation of {@link WindowLayoutComponent} if available, 44 * {@code null} otherwise. The implementation must match the API level reported in 45 * {@link WindowExtensions#getWindowLayoutComponent()}. 46 * @return {@link WindowLayoutComponent} OEM implementation 47 */ 48 @Override getWindowLayoutComponent()49 public WindowLayoutComponent getWindowLayoutComponent() { 50 if (mWindowLayoutComponent == null) { 51 synchronized (mLock) { 52 if (mWindowLayoutComponent == null) { 53 Context context = ActivityThread.currentApplication(); 54 mWindowLayoutComponent = new WindowLayoutComponentImpl(context); 55 } 56 } 57 } 58 return mWindowLayoutComponent; 59 } 60 61 /** 62 * Returns a reference implementation of {@link ActivityEmbeddingComponent} if available, 63 * {@code null} otherwise. The implementation must match the API level reported in 64 * {@link WindowExtensions#getWindowLayoutComponent()}. 65 * @return {@link ActivityEmbeddingComponent} OEM implementation. 66 */ 67 @NonNull getActivityEmbeddingComponent()68 public ActivityEmbeddingComponent getActivityEmbeddingComponent() { 69 if (mSplitController == null) { 70 synchronized (mLock) { 71 if (mSplitController == null) { 72 mSplitController = new SplitController(); 73 } 74 } 75 } 76 return mSplitController; 77 } 78 } 79