diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/WindowExtensionsImpl.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/WindowExtensionsImpl.java new file mode 100644 index 0000000000000..990d7b6a0101c --- /dev/null +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/WindowExtensionsImpl.java @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package androidx.window.extensions; + +import android.app.ActivityThread; +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.window.extensions.embedding.ActivityEmbeddingComponent; +import androidx.window.extensions.embedding.SplitController; +import androidx.window.extensions.layout.WindowLayoutComponent; +import androidx.window.extensions.layout.WindowLayoutComponentImpl; + +/** + * The reference implementation of {@link WindowExtensions} that implements the initial API version. + */ +public class WindowExtensionsImpl implements WindowExtensions { + + private final Object mLock = new Object(); + private volatile WindowLayoutComponent mWindowLayoutComponent; + private volatile SplitController mSplitController; + + @Override + public int getVendorApiLevel() { + return 1; + } + + @Override + public boolean isWindowLayoutComponentAvailable() { + return true; + } + + @Override + public WindowLayoutComponent getWindowLayoutComponent() { + if (mWindowLayoutComponent == null) { + synchronized (mLock) { + if (mWindowLayoutComponent == null) { + Context context = ActivityThread.currentApplication(); + mWindowLayoutComponent = new WindowLayoutComponentImpl(context); + } + } + } + return mWindowLayoutComponent; + } + + /** + * Returns {@code true} if {@link ActivityEmbeddingComponent} is present on the device, + * {@code false} otherwise. If the component is not available the developer will receive a + * single callback with empty data or default values where possible. + */ + @Override + public boolean isEmbeddingComponentAvailable() { + return true; + } + + /** + * Returns the OEM implementation of {@link ActivityEmbeddingComponent} if it is supported on + * the device. The implementation must match the API level reported in + * {@link androidx.window.extensions.WindowExtensions}. An + * {@link UnsupportedOperationException} will be thrown if the device does not support + * Activity Embedding. Use + * {@link WindowExtensions#isEmbeddingComponentAvailable()} to determine if + * {@link ActivityEmbeddingComponent} is present. + * @return the OEM implementation of {@link ActivityEmbeddingComponent} + */ + @NonNull + public ActivityEmbeddingComponent getActivityEmbeddingComponent() { + if (mSplitController == null) { + synchronized (mLock) { + if (mSplitController == null) { + mSplitController = new SplitController(); + } + } + } + return mSplitController; + } +} diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/WindowExtensionsProvider.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/WindowExtensionsProvider.java new file mode 100644 index 0000000000000..f9e1f077cffc0 --- /dev/null +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/WindowExtensionsProvider.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package androidx.window.extensions; + +import android.annotation.NonNull; + +/** + * Provides the OEM implementation of {@link WindowExtensions}. + */ +public class WindowExtensionsProvider { + + private static final WindowExtensions sWindowExtensions = new WindowExtensionsImpl(); + + /** + * Returns the OEM implementation of {@link WindowExtensions}. This method is implemented in + * the library provided on the device and overwrites one in the Jetpack library included in + * apps. + * @return the OEM implementation of {@link WindowExtensions} + */ + @NonNull + public static WindowExtensions getWindowExtensions() { + return sWindowExtensions; + } +} diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/ActivityEmbeddingComponentProvider.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/ActivityEmbeddingComponentProvider.java deleted file mode 100644 index 56da30cb43831..0000000000000 --- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/ActivityEmbeddingComponentProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package androidx.window.extensions.embedding; - -import android.content.Context; - -import androidx.annotation.NonNull; - -/** - * Provider for the reference implementation of androidx.window.extensions.embedding OEM interface - * for use with WindowManager Jetpack. - */ -public class ActivityEmbeddingComponentProvider { - private static SplitController sInstance; - - private ActivityEmbeddingComponentProvider() { - } - - /** - * Returns {@code true} if {@link ActivityEmbeddingComponent} is present on the device, - * {@code false} otherwise. If the component is not available the developer will receive a - * single callback with empty data or default values where possible. - */ - public static boolean isEmbeddingComponentAvailable() { - return true; - } - - /** - * Returns the OEM implementation of {@link ActivityEmbeddingComponent} if it is supported on - * the device. The implementation must match the API level reported in - * {@link androidx.window.extensions.WindowLibraryInfo}. An - * {@link UnsupportedOperationException} will be thrown if the device does not support - * Activity Embedding. Use - * {@link ActivityEmbeddingComponentProvider#isEmbeddingComponentAvailable()} to determine if - * {@link ActivityEmbeddingComponent} is present. - * @return the OEM implementation of {@link ActivityEmbeddingComponent} - */ - @NonNull - public static ActivityEmbeddingComponent getActivityEmbeddingComponent( - @NonNull Context context) { - if (sInstance == null) { - synchronized (ActivityEmbeddingComponentProvider.class) { - if (sInstance == null) { - sInstance = new SplitController(); - } - } - } - return sInstance; - } -} diff --git a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponent.java b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java similarity index 93% rename from libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponent.java rename to libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java index df76894fb544a..383d91da6af80 100644 --- a/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponent.java +++ b/libs/WindowManager/Jetpack/src/androidx/window/extensions/layout/WindowLayoutComponentImpl.java @@ -27,7 +27,6 @@ import android.graphics.Rect; import android.util.Log; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.window.common.DeviceStateManagerPostureProducer; import androidx.window.common.DisplayFeature; import androidx.window.common.ResourceConfigDisplayFeatureProducer; @@ -52,7 +51,7 @@ import java.util.function.Consumer; * production builds since the interface can still change before reaching stable version. * Please refer to {@link androidx.window.sidecar.SampleSidecarImpl} instead. */ -public class WindowLayoutComponent { +public class WindowLayoutComponentImpl implements WindowLayoutComponent { private static final String TAG = "SampleExtension"; private static WindowLayoutComponent sInstance; @@ -65,7 +64,7 @@ public class WindowLayoutComponent { private final SettingsDisplayFeatureProducer mSettingsDisplayFeatureProducer; private final DataProducer> mDisplayFeatureProducer; - private WindowLayoutComponent(Context context) { + public WindowLayoutComponentImpl(Context context) { mSettingsDevicePostureProducer = new SettingsDevicePostureProducer(context); mDevicePostureProducer = new PriorityDataProducer<>(List.of( mSettingsDevicePostureProducer, @@ -82,21 +81,6 @@ public class WindowLayoutComponent { mDisplayFeatureProducer.addDataChangedCallback(this::onDisplayFeaturesChanged); } - /** - * Returns a shared instance. - */ - @Nullable - public static WindowLayoutComponent getInstance(@NonNull Context context) { - if (sInstance == null) { - synchronized (WindowLayoutComponent.class) { - if (sInstance == null) { - sInstance = new WindowLayoutComponent(context); - } - } - } - return sInstance; - } - /** * Adds a listener interested in receiving updates to {@link WindowLayoutInfo} * @param activity hosting a {@link android.view.Window} diff --git a/libs/WindowManager/Jetpack/window-extensions-release.aar b/libs/WindowManager/Jetpack/window-extensions-release.aar index b61b5bdf160f0..42e829e3e5ab7 100644 Binary files a/libs/WindowManager/Jetpack/window-extensions-release.aar and b/libs/WindowManager/Jetpack/window-extensions-release.aar differ