Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 322a5aee authored by Diego Vela's avatar Diego Vela
Browse files

Update Reference implementation for window-extensions.

Update reference implementation for window-extensions.

Bug: 200716579
Test: manual
Change-Id: Iabcab8b2aba45d24ebcde825c26681079999d81c
parent 00af00c4
Loading
Loading
Loading
Loading
+91 −0
Original line number Original line Diff line number Diff line
@@ -14,20 +14,47 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package androidx.window.extensions.embedding;
package androidx.window.extensions;


import android.app.ActivityThread;
import android.content.Context;
import android.content.Context;


import androidx.annotation.NonNull;
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;


/**
/**
 * Provider for the reference implementation of androidx.window.extensions.embedding OEM interface
 * The reference implementation of {@link WindowExtensions} that implements the initial API version.
 * for use with WindowManager Jetpack.
 */
 */
public class ActivityEmbeddingComponentProvider {
public class WindowExtensionsImpl implements WindowExtensions {
    private static SplitController sInstance;


    private ActivityEmbeddingComponentProvider() {
    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;
    }
    }


    /**
    /**
@@ -35,30 +62,30 @@ public class ActivityEmbeddingComponentProvider {
     * {@code false} otherwise. If the component is not available the developer will receive a
     * {@code false} otherwise. If the component is not available the developer will receive a
     * single callback with empty data or default values where possible.
     * single callback with empty data or default values where possible.
     */
     */
    public static boolean isEmbeddingComponentAvailable() {
    @Override
    public boolean isEmbeddingComponentAvailable() {
        return true;
        return true;
    }
    }


    /**
    /**
     * Returns the OEM implementation of {@link ActivityEmbeddingComponent} if it is supported on
     * Returns the OEM implementation of {@link ActivityEmbeddingComponent} if it is supported on
     * the device. The implementation must match the API level reported in
     * the device. The implementation must match the API level reported in
     * {@link androidx.window.extensions.WindowLibraryInfo}. An
     * {@link androidx.window.extensions.WindowExtensions}. An
     * {@link UnsupportedOperationException} will be thrown if the device does not support
     * {@link UnsupportedOperationException} will be thrown if the device does not support
     * Activity Embedding. Use
     * Activity Embedding. Use
     * {@link ActivityEmbeddingComponentProvider#isEmbeddingComponentAvailable()} to determine if
     * {@link WindowExtensions#isEmbeddingComponentAvailable()} to determine if
     * {@link ActivityEmbeddingComponent} is present.
     * {@link ActivityEmbeddingComponent} is present.
     * @return the OEM implementation of {@link ActivityEmbeddingComponent}
     * @return the OEM implementation of {@link ActivityEmbeddingComponent}
     */
     */
    @NonNull
    @NonNull
    public static ActivityEmbeddingComponent getActivityEmbeddingComponent(
    public ActivityEmbeddingComponent getActivityEmbeddingComponent() {
            @NonNull Context context) {
        if (mSplitController == null) {
        if (sInstance == null) {
            synchronized (mLock) {
            synchronized (ActivityEmbeddingComponentProvider.class) {
                if (mSplitController == null) {
                if (sInstance == null) {
                    mSplitController = new SplitController();
                    sInstance = new SplitController();
                }
                }
            }
            }
        }
        }
        return sInstance;
        return mSplitController;
    }
    }
}
}
+38 −0
Original line number Original line Diff line number Diff line
/*
 * 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;
    }
}
+2 −18
Original line number Original line Diff line number Diff line
@@ -27,7 +27,6 @@ import android.graphics.Rect;
import android.util.Log;
import android.util.Log;


import androidx.annotation.NonNull;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.window.common.DeviceStateManagerPostureProducer;
import androidx.window.common.DeviceStateManagerPostureProducer;
import androidx.window.common.DisplayFeature;
import androidx.window.common.DisplayFeature;
import androidx.window.common.ResourceConfigDisplayFeatureProducer;
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.
 * production builds since the interface can still change before reaching stable version.
 * Please refer to {@link androidx.window.sidecar.SampleSidecarImpl} instead.
 * 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 final String TAG = "SampleExtension";
    private static WindowLayoutComponent sInstance;
    private static WindowLayoutComponent sInstance;


@@ -65,7 +64,7 @@ public class WindowLayoutComponent {
    private final SettingsDisplayFeatureProducer mSettingsDisplayFeatureProducer;
    private final SettingsDisplayFeatureProducer mSettingsDisplayFeatureProducer;
    private final DataProducer<List<DisplayFeature>> mDisplayFeatureProducer;
    private final DataProducer<List<DisplayFeature>> mDisplayFeatureProducer;


    private WindowLayoutComponent(Context context) {
    public WindowLayoutComponentImpl(Context context) {
        mSettingsDevicePostureProducer = new SettingsDevicePostureProducer(context);
        mSettingsDevicePostureProducer = new SettingsDevicePostureProducer(context);
        mDevicePostureProducer = new PriorityDataProducer<>(List.of(
        mDevicePostureProducer = new PriorityDataProducer<>(List.of(
                mSettingsDevicePostureProducer,
                mSettingsDevicePostureProducer,
@@ -82,21 +81,6 @@ public class WindowLayoutComponent {
        mDisplayFeatureProducer.addDataChangedCallback(this::onDisplayFeaturesChanged);
        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}
     * Adds a listener interested in receiving updates to {@link WindowLayoutInfo}
     * @param activity hosting a {@link android.view.Window}
     * @param activity hosting a {@link android.view.Window}