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

Commit 7ef648e6 authored by Chris Li's avatar Chris Li
Browse files

Migrate WindowContext#onConfigurationChanged to ClientTransaction (7/n)

1. Introdce WindowContextInfo to store info that we want to pass for
WindowContext.
2. Update #attachToWindowToken to be consistent with
   #attachToDisplayArea that it also return the current WindowContext
   config.

Before, when #attachToWindowToken, the server side will trigger an
onConfigurationChanged to the WindowContext. Now, this will be done in
the client side by post to the main thread so it doesn't change the
client side behavior.

Bug: 290876897
Test: atest FrameworksCoreTests:WindowTokenClientControllerTest
Change-Id: I7655ac454a941a795d519351de4741778c514d82
parent 6603c879
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -203,6 +203,7 @@ import android.webkit.WebView;
import android.window.SizeConfigurationBuckets;
import android.window.SplashScreen;
import android.window.SplashScreenView;
import android.window.WindowContextInfo;
import android.window.WindowProviderService;
import android.window.WindowTokenClientController;

@@ -6248,10 +6249,9 @@ public final class ActivityThread extends ClientTransactionHandler
    }

    @Override
    public void handleWindowContextConfigurationChanged(@NonNull IBinder clientToken,
            @NonNull Configuration configuration, int displayId) {
        WindowTokenClientController.getInstance().onWindowContextConfigurationChanged(clientToken,
                configuration, displayId);
    public void handleWindowContextInfoChanged(@NonNull IBinder clientToken,
            @NonNull WindowContextInfo info) {
        WindowTokenClientController.getInstance().onWindowContextInfoChanged(clientToken, info);
    }

    @Override
+4 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.os.IBinder;
import android.util.MergedConfiguration;
import android.view.SurfaceControl;
import android.window.SplashScreenView.SplashScreenViewParcelable;
import android.window.WindowContextInfo;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.ReferrerIntent;
@@ -163,9 +164,9 @@ public abstract class ClientTransactionHandler {
    public abstract void handleActivityConfigurationChanged(@NonNull ActivityClientRecord r,
            Configuration overrideConfig, int displayId);

    /** Deliver {@link android.window.WindowContext} configuration change. */
    public abstract void handleWindowContextConfigurationChanged(@NonNull IBinder clientToken,
            @NonNull Configuration configuration, int displayId);
    /** Deliver {@link android.window.WindowContextInfo} change. */
    public abstract void handleWindowContextInfoChanged(@NonNull IBinder clientToken,
            @NonNull WindowContextInfo info);

    /** Deliver {@link android.window.WindowContext} window removal event. */
    public abstract void handleWindowContextWindowRemoval(@NonNull IBinder clientToken);
+24 −33
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.app.servertransaction;

import static android.view.Display.INVALID_DISPLAY;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
@@ -26,6 +24,7 @@ import android.app.ClientTransactionHandler;
import android.content.res.Configuration;
import android.os.IBinder;
import android.os.Parcel;
import android.window.WindowContextInfo;

import java.util.Objects;

@@ -33,35 +32,33 @@ import java.util.Objects;
 * {@link android.window.WindowContext} configuration change message.
 * @hide
 */
public class WindowContextConfigurationChangeItem extends ClientTransactionItem {
public class WindowContextInfoChangeItem extends ClientTransactionItem {

    @Nullable
    private IBinder mClientToken;
    @Nullable
    private Configuration mConfiguration;
    private int mDisplayId;
    private WindowContextInfo mInfo;

    @Override
    public void execute(@NonNull ClientTransactionHandler client, @NonNull IBinder token,
            @NonNull PendingTransactionActions pendingActions) {
        client.handleWindowContextConfigurationChanged(mClientToken, mConfiguration, mDisplayId);
        client.handleWindowContextInfoChanged(mClientToken, mInfo);
    }

    // ObjectPoolItem implementation

    private WindowContextConfigurationChangeItem() {}
    private WindowContextInfoChangeItem() {}

    /** Obtains an instance initialized with provided params. */
    public static WindowContextConfigurationChangeItem obtain(
    public static WindowContextInfoChangeItem obtain(
            @NonNull IBinder clientToken, @NonNull Configuration config, int displayId) {
        WindowContextConfigurationChangeItem instance =
                ObjectPool.obtain(WindowContextConfigurationChangeItem.class);
        WindowContextInfoChangeItem instance =
                ObjectPool.obtain(WindowContextInfoChangeItem.class);
        if (instance == null) {
            instance = new WindowContextConfigurationChangeItem();
            instance = new WindowContextInfoChangeItem();
        }
        instance.mClientToken = requireNonNull(clientToken);
        instance.mConfiguration = requireNonNull(config);
        instance.mDisplayId = displayId;
        instance.mInfo = new WindowContextInfo(config, displayId);

        return instance;
    }
@@ -69,8 +66,7 @@ public class WindowContextConfigurationChangeItem extends ClientTransactionItem
    @Override
    public void recycle() {
        mClientToken = null;
        mConfiguration = null;
        mDisplayId = INVALID_DISPLAY;
        mInfo = null;
        ObjectPool.recycle(this);
    }

@@ -80,25 +76,23 @@ public class WindowContextConfigurationChangeItem extends ClientTransactionItem
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeStrongBinder(mClientToken);
        dest.writeTypedObject(mConfiguration, flags);
        dest.writeInt(mDisplayId);
        dest.writeTypedObject(mInfo, flags);
    }

    /** Reads from Parcel. */
    private WindowContextConfigurationChangeItem(@NonNull Parcel in) {
    private WindowContextInfoChangeItem(@NonNull Parcel in) {
        mClientToken = in.readStrongBinder();
        mConfiguration = in.readTypedObject(Configuration.CREATOR);
        mDisplayId = in.readInt();
        mInfo = in.readTypedObject(WindowContextInfo.CREATOR);
    }

    public static final @NonNull Creator<WindowContextConfigurationChangeItem> CREATOR =
    public static final @NonNull Creator<WindowContextInfoChangeItem> CREATOR =
            new Creator<>() {
                public WindowContextConfigurationChangeItem createFromParcel(Parcel in) {
                    return new WindowContextConfigurationChangeItem(in);
                public WindowContextInfoChangeItem createFromParcel(Parcel in) {
                    return new WindowContextInfoChangeItem(in);
                }

                public WindowContextConfigurationChangeItem[] newArray(int size) {
                    return new WindowContextConfigurationChangeItem[size];
                public WindowContextInfoChangeItem[] newArray(int size) {
                    return new WindowContextInfoChangeItem[size];
                }
    };

@@ -110,26 +104,23 @@ public class WindowContextConfigurationChangeItem extends ClientTransactionItem
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final WindowContextConfigurationChangeItem other = (WindowContextConfigurationChangeItem) o;
        final WindowContextInfoChangeItem other = (WindowContextInfoChangeItem) o;
        return Objects.equals(mClientToken, other.mClientToken)
                && Objects.equals(mConfiguration, other.mConfiguration)
                && mDisplayId == other.mDisplayId;
                && Objects.equals(mInfo, other.mInfo);
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + Objects.hashCode(mClientToken);
        result = 31 * result + Objects.hashCode(mConfiguration);
        result = 31 * result + mDisplayId;
        result = 31 * result + Objects.hashCode(mInfo);
        return result;
    }

    @Override
    public String toString() {
        return "WindowContextConfigurationChangeItem{clientToken=" + mClientToken
                + ", config=" + mConfiguration
                + ", displayId=" + mDisplayId
        return "WindowContextInfoChangeItem{clientToken=" + mClientToken
                + ", info=" + mInfo
                + "}";
    }
}
+11 −8
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ import android.window.AddToSurfaceSyncGroupResult;
import android.window.ISurfaceSyncGroupCompletedListener;
import android.window.ITaskFpsCallback;
import android.window.ScreenCapture;
import android.window.WindowContextInfo;

/**
 * System private interface to the window manager.
@@ -858,10 +859,10 @@ interface IWindowManager
     * @param displayId The display associated with the window context
     * @param options A bundle used to pass window-related options and choose the right DisplayArea
     *
     * @return the DisplayArea's {@link android.app.res.Configuration} if the WindowContext is
     * attached to the DisplayArea successfully. {@code null}, otherwise.
     * @return the {@link WindowContextInfo} of the DisplayArea if the WindowContext is attached to
     * the DisplayArea successfully. {@code null}, otherwise.
     */
    @nullable Configuration attachWindowContextToDisplayArea(in IApplicationThread appThread,
    @nullable WindowContextInfo attachWindowContextToDisplayArea(in IApplicationThread appThread,
            IBinder clientToken, int type, int displayId, in @nullable Bundle options);

    /**
@@ -879,13 +880,15 @@ interface IWindowManager
     * the WindowContext's token}
     * @param token the WindowToken to attach
     *
     * @return the {@link WindowContextInfo} of the WindowToken if the WindowContext is attached to
     * the WindowToken successfully. {@code null}, otherwise.
     * @throws IllegalArgumentException if the {@code clientToken} have not been attached to
     * the server or the WindowContext's type doesn't match WindowToken {@code token}'s type.
     *
     * @see #attachWindowContextToDisplayArea(IBinder, int, int, Bundle)
     */
    void attachWindowContextToWindowToken(in IApplicationThread appThread, IBinder clientToken,
            IBinder token);
    @nullable WindowContextInfo  attachWindowContextToWindowToken(in IApplicationThread appThread,
            IBinder clientToken, IBinder token);

    /**
     * Attaches a {@code clientToken} to associate with DisplayContent.
@@ -899,11 +902,11 @@ interface IWindowManager
     * the WindowContext's token}
     * @param displayId The display associated with the window context
     *
     * @return the DisplayContent's {@link android.app.res.Configuration} if the Context is
     * attached to the DisplayContent successfully. {@code null}, otherwise.
     * @return the {@link WindowContextInfo} of the DisplayContent if the WindowContext is attached
     * to the DisplayContent successfully. {@code null}, otherwise.
     * @throws android.view.WindowManager.InvalidDisplayException if the display ID is invalid
     */
    @nullable Configuration attachWindowContextToDisplayContent(in IApplicationThread appThread,
    @nullable WindowContextInfo attachWindowContextToDisplayContent(in IApplicationThread appThread,
            IBinder clientToken, int displayId);

    /**
+4 −2
Original line number Diff line number Diff line
@@ -137,12 +137,14 @@ public class WindowContextController {
     * @see WindowProviderService#attachToWindowToken(IBinder))
     * @see IWindowManager#attachWindowContextToWindowToken
     */
    public void attachToWindowToken(IBinder windowToken) {
    public void attachToWindowToken(@NonNull IBinder windowToken) {
        if (mAttachedToDisplayArea != AttachStatus.STATUS_ATTACHED) {
            throw new IllegalStateException("The Window Context should have been attached"
                    + " to a DisplayArea. AttachToDisplayArea:" + mAttachedToDisplayArea);
        }
        getWindowTokenClientController().attachToWindowToken(mToken, windowToken);
        if (!getWindowTokenClientController().attachToWindowToken(mToken, windowToken)) {
            Log.e(TAG, "attachToWindowToken fail");
        }
    }

    /** Detaches the window context from the node it's currently associated with. */
Loading