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

Commit 4aa6ef60 authored by Diego Vela's avatar Diego Vela Committed by Automerger Merge Worker
Browse files

Merge changes from topic "embedding_interface_0922" into sc-v2-dev am: 731b8775

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15881690

Change-Id: I9b6e6c68e788d54a4199c556e865669ebcc3a335
parents 82c1b831 731b8775
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -3616,6 +3616,11 @@ public final class ActivityThread extends ClientTransactionHandler
                }
                }
                activity.mLaunchedFromBubble = r.mLaunchedFromBubble;
                activity.mLaunchedFromBubble = r.mLaunchedFromBubble;
                activity.mCalled = false;
                activity.mCalled = false;
                // Assigning the activity to the record before calling onCreate() allows
                // ActivityThread#getActivity() lookup for the callbacks triggered from
                // ActivityLifecycleCallbacks#onActivityCreated() or
                // ActivityLifecycleCallback#onActivityPostCreated().
                r.activity = activity;
                if (r.isPersistable()) {
                if (r.isPersistable()) {
                    mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState);
                    mInstrumentation.callActivityOnCreate(activity, r.state, r.persistentState);
                } else {
                } else {
@@ -3626,7 +3631,6 @@ public final class ActivityThread extends ClientTransactionHandler
                        "Activity " + r.intent.getComponent().toShortString() +
                        "Activity " + r.intent.getComponent().toShortString() +
                        " did not call through to super.onCreate()");
                        " did not call through to super.onCreate()");
                }
                }
                r.activity = activity;
                mLastReportedWindowingMode.put(activity.getActivityToken(),
                mLastReportedWindowingMode.put(activity.getActivityToken(),
                        config.windowConfiguration.getWindowingMode());
                        config.windowConfiguration.getWindowingMode());
            }
            }
+0 −51
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.content.Context;

import androidx.annotation.NonNull;
import androidx.window.extensions.embedding.ActivityEmbeddingComponent;
import androidx.window.extensions.organizer.EmbeddingExtensionImpl;

/**
 * Provider class that will instantiate the library implementation. It must be included in the
 * vendor library, and the vendor implementation must match the signature of this class.
 */
public class ExtensionProvider {
    /**
     * Provides a simple implementation of {@link ExtensionInterface} that can be replaced by
     * an OEM by overriding this method.
     */
    public static ExtensionInterface getExtensionImpl(Context context) {
        return new SampleExtensionImpl(context);
    }

    /** Provides a reference implementation of {@link ActivityEmbeddingComponent}. */
    public static ActivityEmbeddingComponent getActivityEmbeddingExtensionImpl(
            @NonNull Context context) {
        return new EmbeddingExtensionImpl();
    }

    /**
     * The support library will use this method to check API version compatibility.
     * @return API version string in MAJOR.MINOR.PATCH-description format.
     */
    public static String getApiVersion() {
        return "1.0.0-settings_sample";
    }
}
+0 −72
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.app.Activity;

import androidx.annotation.NonNull;

import java.util.HashSet;
import java.util.Set;

/**
 * Basic implementation of the {@link ExtensionInterface}. An OEM can choose to use it as the base
 * class for their implementation.
 */
abstract class StubExtension implements ExtensionInterface {

    private ExtensionCallback mExtensionCallback;
    private final Set<Activity> mWindowLayoutChangeListenerActivities = new HashSet<>();

    StubExtension() {
    }

    @Override
    public void setExtensionCallback(@NonNull ExtensionCallback extensionCallback) {
        this.mExtensionCallback = extensionCallback;
    }

    @Override
    public void onWindowLayoutChangeListenerAdded(@NonNull Activity activity) {
        this.mWindowLayoutChangeListenerActivities.add(activity);
        this.onListenersChanged();
    }

    @Override
    public void onWindowLayoutChangeListenerRemoved(@NonNull Activity activity) {
        this.mWindowLayoutChangeListenerActivities.remove(activity);
        this.onListenersChanged();
    }

    void updateWindowLayout(@NonNull Activity activity,
            @NonNull ExtensionWindowLayoutInfo newLayout) {
        if (this.mExtensionCallback != null) {
            mExtensionCallback.onWindowLayoutChanged(activity, newLayout);
        }
    }

    @NonNull
    Set<Activity> getActivitiesListeningForLayoutChanges() {
        return mWindowLayoutChangeListenerActivities;
    }

    protected boolean hasListeners() {
        return !mWindowLayoutChangeListenerActivities.isEmpty();
    }

    protected abstract void onListenersChanged();
}
+91 −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.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;
    }
}
+38 −0
Original line number Original line Diff line number Diff line
@@ -14,35 +14,25 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


package androidx.window.extensions.organizer;
package androidx.window.extensions;


import androidx.annotation.NonNull;
import android.annotation.NonNull;
import androidx.window.extensions.embedding.ActivityEmbeddingComponent;
import androidx.window.extensions.embedding.EmbeddingRule;
import androidx.window.extensions.embedding.SplitInfo;

import java.util.List;
import java.util.Set;
import java.util.function.Consumer;


/**
/**
 * Reference implementation of the activity embedding interface defined in WM Jetpack.
 * Provides the OEM implementation of {@link WindowExtensions}.
 */
 */
public class EmbeddingExtensionImpl implements ActivityEmbeddingComponent {
public class WindowExtensionsProvider {

    private final SplitController mSplitController;


    public EmbeddingExtensionImpl() {
    private static final WindowExtensions sWindowExtensions = new WindowExtensionsImpl();
        mSplitController = new SplitController();
    }


    @Override
    /**
    public void setEmbeddingRules(@NonNull Set<EmbeddingRule> rules) {
     * Returns the OEM implementation of {@link WindowExtensions}. This method is implemented in
        mSplitController.setEmbeddingRules(rules);
     * the library provided on the device and overwrites one in the Jetpack library included in
    }
     * apps.

     * @return the OEM implementation of {@link WindowExtensions}
    @Override
     */
    public void setEmbeddingCallback(@NonNull Consumer<List<SplitInfo>> consumer) {
    @NonNull
        mSplitController.setEmbeddingCallback(consumer);
    public static WindowExtensions getWindowExtensions() {
        return sWindowExtensions;
    }
    }
}
}
Loading