Update Reference implementation for window-extensions.

Update reference implementation for window-extensions.

Bug: 200716579
Test: manual
Change-Id: Iabcab8b2aba45d24ebcde825c26681079999d81c
This commit is contained in:
Diego Vela
2021-09-21 13:58:40 -07:00
parent 00af00c414
commit 322a5aee69
5 changed files with 131 additions and 82 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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<List<DisplayFeature>> 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}