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

Commit ae5ddfaf authored by Chris Li's avatar Chris Li Committed by Android (Google) Code Review
Browse files

Merge changes If95ba8f5,I52e12fa5 into main

* changes:
  Dispatch WindowStateInsetsControlChangeItem
  Refactor WindowStateTransactionItem
parents 5f7143a7 debccf10
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -104,8 +104,8 @@ public class LaunchActivityItem extends ClientTransactionItem {
    public void execute(@NonNull ClientTransactionHandler client,
            @NonNull PendingTransactionActions pendingActions) {
        Trace.traceBegin(TRACE_TAG_ACTIVITY_MANAGER, "activityStart");
        ActivityClientRecord r = new ActivityClientRecord(mActivityToken, mIntent, mIdent, mInfo,
                mOverrideConfig, mReferrer, mVoiceInteractor, mState, mPersistentState,
        final ActivityClientRecord r = new ActivityClientRecord(mActivityToken, mIntent, mIdent,
                mInfo, mOverrideConfig, mReferrer, mVoiceInteractor, mState, mPersistentState,
                mPendingResults, mPendingNewIntents, mSceneTransitionInfo, mIsForward,
                mProfilerInfo, client, mAssistToken, mShareableActivityToken, mLaunchedFromBubble,
                mTaskFragmentToken, mInitialCallerInfoAccessToken, mActivityWindowInfo);
+11 −27
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package android.app.servertransaction;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ClientTransactionHandler;
@@ -35,23 +33,19 @@ import java.util.Objects;
 * Message to deliver window insets control change info.
 * @hide
 */
public class WindowStateInsetsControlChangeItem extends ClientTransactionItem {
public class WindowStateInsetsControlChangeItem extends WindowStateTransactionItem {

    private static final String TAG = "WindowStateInsetsControlChangeItem";

    private IWindow mWindow;
    private InsetsState mInsetsState;
    private InsetsSourceControl.Array mActiveControls;

    @Override
    public void execute(@NonNull ClientTransactionHandler client,
    public void execute(@NonNull ClientTransactionHandler client, @NonNull IWindow window,
            @NonNull PendingTransactionActions pendingActions) {
        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER, "windowInsetsControlChanged");
        if (mWindow instanceof InsetsControlChangeListener listener) {
            listener.onExecutingWindowStateInsetsControlChangeItem();
        }
        try {
            mWindow.insetsControlChanged(mInsetsState, mActiveControls);
            window.insetsControlChanged(mInsetsState, mActiveControls);
        } catch (RemoteException e) {
            // Should be a local call.
            // An exception could happen if the process is restarted. It is safe to ignore since
@@ -73,7 +67,7 @@ public class WindowStateInsetsControlChangeItem extends ClientTransactionItem {
        if (instance == null) {
            instance = new WindowStateInsetsControlChangeItem();
        }
        instance.mWindow = requireNonNull(window);
        instance.setWindow(window);
        instance.mInsetsState = new InsetsState(insetsState, true /* copySources */);
        instance.mActiveControls = new InsetsSourceControl.Array(activeControls);

@@ -82,7 +76,7 @@ public class WindowStateInsetsControlChangeItem extends ClientTransactionItem {

    @Override
    public void recycle() {
        mWindow = null;
        super.recycle();
        mInsetsState = null;
        mActiveControls = null;
        ObjectPool.recycle(this);
@@ -93,14 +87,14 @@ public class WindowStateInsetsControlChangeItem extends ClientTransactionItem {
    /** Writes to Parcel. */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeStrongBinder(mWindow.asBinder());
        super.writeToParcel(dest, flags);
        dest.writeTypedObject(mInsetsState, flags);
        dest.writeTypedObject(mActiveControls, flags);
    }

    /** Reads from Parcel. */
    private WindowStateInsetsControlChangeItem(@NonNull Parcel in) {
        mWindow = IWindow.Stub.asInterface(in.readStrongBinder());
        super(in);
        mInsetsState = in.readTypedObject(InsetsState.CREATOR);
        mActiveControls = in.readTypedObject(InsetsSourceControl.Array.CREATOR);

@@ -122,19 +116,18 @@ public class WindowStateInsetsControlChangeItem extends ClientTransactionItem {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
        if (!super.equals(o)) {
            return false;
        }
        final WindowStateInsetsControlChangeItem other = (WindowStateInsetsControlChangeItem) o;
        return Objects.equals(mWindow, other.mWindow)
                && Objects.equals(mInsetsState, other.mInsetsState)
        return Objects.equals(mInsetsState, other.mInsetsState)
                && Objects.equals(mActiveControls, other.mActiveControls);
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + Objects.hashCode(mWindow);
        result = 31 * result + super.hashCode();
        result = 31 * result + Objects.hashCode(mInsetsState);
        result = 31 * result + Objects.hashCode(mActiveControls);
        return result;
@@ -142,15 +135,6 @@ public class WindowStateInsetsControlChangeItem extends ClientTransactionItem {

    @Override
    public String toString() {
        return "WindowStateInsetsControlChangeItem{window=" + mWindow + "}";
    }

    /** The interface for IWindow to perform insets control change directly if possible. */
    public interface InsetsControlChangeListener {
        /**
         * Notifies that IWindow#insetsControlChanged is going to be called from
         * WindowStateInsetsControlChangeItem.
         */
        void onExecutingWindowStateInsetsControlChangeItem();
        return "WindowStateInsetsControlChangeItem{" + super.toString() + "}";
    }
}
+11 −24
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package android.app.servertransaction;

import static android.view.Display.INVALID_DISPLAY;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ClientTransactionHandler;
@@ -39,11 +37,10 @@ import java.util.Objects;
 * Message to deliver window resize info.
 * @hide
 */
public class WindowStateResizeItem extends ClientTransactionItem {
public class WindowStateResizeItem extends WindowStateTransactionItem {

    private static final String TAG = "WindowStateResizeItem";

    private IWindow mWindow;
    private ClientWindowFrames mFrames;
    private boolean mReportDraw;
    private MergedConfiguration mConfiguration;
@@ -59,15 +56,12 @@ public class WindowStateResizeItem extends ClientTransactionItem {
    private ActivityWindowInfo mActivityWindowInfo;

    @Override
    public void execute(@NonNull ClientTransactionHandler client,
    public void execute(@NonNull ClientTransactionHandler client, @NonNull IWindow window,
            @NonNull PendingTransactionActions pendingActions) {
        Trace.traceBegin(Trace.TRACE_TAG_WINDOW_MANAGER,
                mReportDraw ? "windowResizedReport" : "windowResized");
        if (mWindow instanceof ResizeListener listener) {
            listener.onExecutingWindowStateResizeItem();
        }
        try {
            mWindow.resized(mFrames, mReportDraw, mConfiguration, mInsetsState, mForceLayout,
            window.resized(mFrames, mReportDraw, mConfiguration, mInsetsState, mForceLayout,
                    mAlwaysConsumeSystemBars, mDisplayId, mSyncSeqId, mDragResizing,
                    mActivityWindowInfo);
        } catch (RemoteException e) {
@@ -94,7 +88,7 @@ public class WindowStateResizeItem extends ClientTransactionItem {
        if (instance == null) {
            instance = new WindowStateResizeItem();
        }
        instance.mWindow = requireNonNull(window);
        instance.setWindow(window);
        instance.mFrames = new ClientWindowFrames(frames);
        instance.mReportDraw = reportDraw;
        instance.mConfiguration = new MergedConfiguration(configuration);
@@ -113,7 +107,7 @@ public class WindowStateResizeItem extends ClientTransactionItem {

    @Override
    public void recycle() {
        mWindow = null;
        super.recycle();
        mFrames = null;
        mReportDraw = false;
        mConfiguration = null;
@@ -132,7 +126,7 @@ public class WindowStateResizeItem extends ClientTransactionItem {
    /** Writes to Parcel. */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeStrongBinder(mWindow.asBinder());
        super.writeToParcel(dest, flags);
        dest.writeTypedObject(mFrames, flags);
        dest.writeBoolean(mReportDraw);
        dest.writeTypedObject(mConfiguration, flags);
@@ -147,7 +141,7 @@ public class WindowStateResizeItem extends ClientTransactionItem {

    /** Reads from Parcel. */
    private WindowStateResizeItem(@NonNull Parcel in) {
        mWindow = IWindow.Stub.asInterface(in.readStrongBinder());
        super(in);
        mFrames = in.readTypedObject(ClientWindowFrames.CREATOR);
        mReportDraw = in.readBoolean();
        mConfiguration = in.readTypedObject(MergedConfiguration.CREATOR);
@@ -175,12 +169,11 @@ public class WindowStateResizeItem extends ClientTransactionItem {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
        if (!super.equals(o)) {
            return false;
        }
        final WindowStateResizeItem other = (WindowStateResizeItem) o;
        return Objects.equals(mWindow, other.mWindow)
                && Objects.equals(mFrames, other.mFrames)
        return Objects.equals(mFrames, other.mFrames)
                && mReportDraw == other.mReportDraw
                && Objects.equals(mConfiguration, other.mConfiguration)
                && Objects.equals(mInsetsState, other.mInsetsState)
@@ -195,7 +188,7 @@ public class WindowStateResizeItem extends ClientTransactionItem {
    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + Objects.hashCode(mWindow);
        result = 31 * result + super.hashCode();
        result = 31 * result + Objects.hashCode(mFrames);
        result = 31 * result + (mReportDraw ? 1 : 0);
        result = 31 * result + Objects.hashCode(mConfiguration);
@@ -211,16 +204,10 @@ public class WindowStateResizeItem extends ClientTransactionItem {

    @Override
    public String toString() {
        return "WindowStateResizeItem{window=" + mWindow
        return "WindowStateResizeItem{" + super.toString()
                + ", reportDrawn=" + mReportDraw
                + ", configuration=" + mConfiguration
                + ", activityWindowInfo=" + mActivityWindowInfo
                + "}";
    }

    /** The interface for IWindow to perform resize directly if possible. */
    public interface ResizeListener {
        /** Notifies that IWindow#resized is going to be called from WindowStateResizeItem. */
        void onExecutingWindowStateResizeItem();
    }
}
+118 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 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 android.app.servertransaction;


import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;

import static java.util.Objects.requireNonNull;

import android.annotation.CallSuper;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ClientTransactionHandler;
import android.os.Parcel;
import android.view.IWindow;

import com.android.internal.annotations.VisibleForTesting;

import java.util.Objects;

/**
 * {@link ClientTransactionItem} to report changes to a window.
 *
 * @hide
 */
public abstract class WindowStateTransactionItem extends ClientTransactionItem {

    /** The interface for IWindow to perform callback directly if possible. */
    public interface TransactionListener {
        /** Notifies that the transaction item is going to be executed. */
        void onExecutingWindowStateTransactionItem();
    }

    /** Target window. */
    private IWindow mWindow;

    WindowStateTransactionItem() {}

    @Override
    public final void execute(@NonNull ClientTransactionHandler client,
            @NonNull PendingTransactionActions pendingActions) {
        if (mWindow instanceof TransactionListener listener) {
            listener.onExecutingWindowStateTransactionItem();
        }
        execute(client, mWindow, pendingActions);
    }

    /**
     * Like {@link #execute(ClientTransactionHandler, PendingTransactionActions)},
     * but take non-null {@link IWindow} as a parameter.
     */
    @VisibleForTesting(visibility = PACKAGE)
    public abstract void execute(@NonNull ClientTransactionHandler client,
            @NonNull IWindow window, @NonNull PendingTransactionActions pendingActions);

    void setWindow(@NonNull IWindow window) {
        mWindow = requireNonNull(window);
    }

    // To be overridden

    WindowStateTransactionItem(@NonNull Parcel in) {
        mWindow = IWindow.Stub.asInterface(in.readStrongBinder());
    }

    @CallSuper
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeStrongBinder(mWindow.asBinder());
    }

    @CallSuper
    @Override
    public void recycle() {
        mWindow = null;
    }

    // Subclass must override and call super.equals to compare the mActivityToken.
    @SuppressWarnings("EqualsGetClass")
    @CallSuper
    @Override
    public boolean equals(@Nullable Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        final WindowStateTransactionItem other = (WindowStateTransactionItem) o;
        return Objects.equals(mWindow, other.mWindow);
    }

    @CallSuper
    @Override
    public int hashCode() {
        return Objects.hashCode(mWindow);
    }

    @CallSuper
    @Override
    public String toString() {
        return "mWindow=" + mWindow;
    }
}
+10 −7
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ import android.app.ICompatCameraControlCallback;
import android.app.ResourcesManager;
import android.app.WindowConfiguration;
import android.app.compat.CompatChanges;
import android.app.servertransaction.WindowStateResizeItem;
import android.app.servertransaction.WindowStateTransactionItem;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ClipData;
import android.content.ClipDescription;
@@ -11201,10 +11201,10 @@ public final class ViewRootImpl implements ViewParent,
        }
    }
    static class W extends IWindow.Stub implements WindowStateResizeItem.ResizeListener {
    static class W extends IWindow.Stub implements WindowStateTransactionItem.TransactionListener {
        private final WeakReference<ViewRootImpl> mViewAncestor;
        private final IWindowSession mWindowSession;
        private boolean mIsFromResizeItem;
        private boolean mIsFromTransactionItem;
        W(ViewRootImpl viewAncestor) {
            mViewAncestor = new WeakReference<ViewRootImpl>(viewAncestor);
@@ -11212,8 +11212,8 @@ public final class ViewRootImpl implements ViewParent,
        }
        @Override
        public void onExecutingWindowStateResizeItem() {
            mIsFromResizeItem = true;
        public void onExecutingWindowStateTransactionItem() {
            mIsFromTransactionItem = true;
        }
        @Override
@@ -11221,8 +11221,8 @@ public final class ViewRootImpl implements ViewParent,
                MergedConfiguration mergedConfiguration, InsetsState insetsState,
                boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId, int syncSeqId,
                boolean dragResizing, @Nullable ActivityWindowInfo activityWindowInfo) {
            final boolean isFromResizeItem = mIsFromResizeItem;
            mIsFromResizeItem = false;
            final boolean isFromResizeItem = mIsFromTransactionItem;
            mIsFromTransactionItem = false;
            // Although this is a AIDL method, it will only be triggered in local process through
            // either WindowStateResizeItem or WindowlessWindowManager.
            final ViewRootImpl viewAncestor = mViewAncestor.get();
@@ -11259,10 +11259,13 @@ public final class ViewRootImpl implements ViewParent,
        @Override
        public void insetsControlChanged(InsetsState insetsState,
                InsetsSourceControl.Array activeControls) {
            final boolean isFromInsetsControlChangeItem = mIsFromTransactionItem;
            mIsFromTransactionItem = false;
            final ViewRootImpl viewAncestor = mViewAncestor.get();
            if (viewAncestor != null) {
                viewAncestor.dispatchInsetsControlChanged(insetsState, activeControls.get());
            }
            // TODO(b/339380439): no need to post if the call is from InsetsControlChangeItem
        }
        @Override
Loading