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 Original line Diff line number Diff line
@@ -203,6 +203,7 @@ import android.webkit.WebView;
import android.window.SizeConfigurationBuckets;
import android.window.SizeConfigurationBuckets;
import android.window.SplashScreen;
import android.window.SplashScreen;
import android.window.SplashScreenView;
import android.window.SplashScreenView;
import android.window.WindowContextInfo;
import android.window.WindowProviderService;
import android.window.WindowProviderService;
import android.window.WindowTokenClientController;
import android.window.WindowTokenClientController;


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


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


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


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


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


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


package android.app.servertransaction;
package android.app.servertransaction;


import static android.view.Display.INVALID_DISPLAY;

import static java.util.Objects.requireNonNull;
import static java.util.Objects.requireNonNull;


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


import java.util.Objects;
import java.util.Objects;


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


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


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


    // ObjectPoolItem implementation
    // ObjectPoolItem implementation


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


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


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


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


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


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


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


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


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


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


/**
/**
 * System private interface to the window manager.
 * System private interface to the window manager.
@@ -858,10 +859,10 @@ interface IWindowManager
     * @param displayId The display associated with the window context
     * @param displayId The display associated with the window context
     * @param options A bundle used to pass window-related options and choose the right DisplayArea
     * @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
     * @return the {@link WindowContextInfo} of the DisplayArea if the WindowContext is attached to
     * attached to the DisplayArea successfully. {@code null}, otherwise.
     * 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);
            IBinder clientToken, int type, int displayId, in @nullable Bundle options);


    /**
    /**
@@ -879,13 +880,15 @@ interface IWindowManager
     * the WindowContext's token}
     * the WindowContext's token}
     * @param token the WindowToken to attach
     * @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
     * @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.
     * the server or the WindowContext's type doesn't match WindowToken {@code token}'s type.
     *
     *
     * @see #attachWindowContextToDisplayArea(IBinder, int, int, Bundle)
     * @see #attachWindowContextToDisplayArea(IBinder, int, int, Bundle)
     */
     */
    void attachWindowContextToWindowToken(in IApplicationThread appThread, IBinder clientToken,
    @nullable WindowContextInfo  attachWindowContextToWindowToken(in IApplicationThread appThread,
            IBinder token);
            IBinder clientToken, IBinder token);


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


    /**
    /**
+4 −2
Original line number Original line Diff line number Diff line
@@ -137,12 +137,14 @@ public class WindowContextController {
     * @see WindowProviderService#attachToWindowToken(IBinder))
     * @see WindowProviderService#attachToWindowToken(IBinder))
     * @see IWindowManager#attachWindowContextToWindowToken
     * @see IWindowManager#attachWindowContextToWindowToken
     */
     */
    public void attachToWindowToken(IBinder windowToken) {
    public void attachToWindowToken(@NonNull IBinder windowToken) {
        if (mAttachedToDisplayArea != AttachStatus.STATUS_ATTACHED) {
        if (mAttachedToDisplayArea != AttachStatus.STATUS_ATTACHED) {
            throw new IllegalStateException("The Window Context should have been attached"
            throw new IllegalStateException("The Window Context should have been attached"
                    + " to a DisplayArea. AttachToDisplayArea:" + mAttachedToDisplayArea);
                    + " 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. */
    /** Detaches the window context from the node it's currently associated with. */
Loading