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

Commit b1264948 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove WindowStateTransactionItem pooling (3/n)." into main

parents 34f06f80 26aa2cc4
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -75,6 +75,17 @@ public abstract class ClientTransactionItem implements BaseClientRequest, Parcel
        pw.append(prefix).println(this);
    }

    /**
     * Provides a default empty implementation for progressive cleanup.
     *
     * @deprecated This method is deprecated. The object pool is no longer used, so there's
     * no need to recycle objects.
     * TODO(b/311089192): Remove once ObjectPoolItem inheritance is removed.
     */
    @Override
    @Deprecated
    public void recycle() {}

    // Parcelable

    @Override
+37 −37
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app.servertransaction;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ClientTransactionHandler;
@@ -33,16 +35,47 @@ import java.util.Objects;

/**
 * Message to deliver window insets control change info.
 *
 * @hide
 */
public class WindowStateInsetsControlChangeItem extends WindowStateTransactionItem {

    private static final String TAG = "WindowStateInsetsControlChangeItem";

    private InsetsState mInsetsState;
    @NonNull
    private final InsetsState mInsetsState;

    @NonNull
    private final InsetsSourceControl.Array mActiveControls;

    public WindowStateInsetsControlChangeItem(@NonNull IWindow window,
            @NonNull InsetsState insetsState, @NonNull InsetsSourceControl.Array activeControls) {
        this(window, insetsState, activeControls, true /* copyActiveControls */);
    }

    @VisibleForTesting
    public InsetsSourceControl.Array mActiveControls;
    public WindowStateInsetsControlChangeItem(@NonNull IWindow window,
            @NonNull InsetsState insetsState,
            @NonNull InsetsSourceControl.Array activeControls, boolean copyActiveControls) {
        super(window);
        mInsetsState = new InsetsState(insetsState, true /* copySources */);
        if (copyActiveControls) {
            mActiveControls = copy(requireNonNull(activeControls));
        } else {
            mActiveControls = requireNonNull(activeControls);
        }
    }

    @NonNull
    private static InsetsSourceControl.Array copy(@NonNull InsetsSourceControl.Array controls) {
        final InsetsSourceControl.Array copiedControls = new InsetsSourceControl.Array(
                controls, true /* copyControls */);
        // This source control is an extra copy if the client is not local. By setting
        // PARCELABLE_WRITE_RETURN_VALUE, the leash will be released at the end of
        // SurfaceControl.writeToParcel.
        copiedControls.setParcelableFlags(PARCELABLE_WRITE_RETURN_VALUE);
        return copiedControls;
    }

    @Override
    public void execute(@NonNull ClientTransactionHandler client, @NonNull IWindow window,
@@ -61,38 +94,6 @@ public class WindowStateInsetsControlChangeItem extends WindowStateTransactionIt
        Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
    }

    // ObjectPoolItem implementation

    private WindowStateInsetsControlChangeItem() {}

    /** Obtains an instance initialized with provided params. */
    public static WindowStateInsetsControlChangeItem obtain(@NonNull IWindow window,
            @NonNull InsetsState insetsState, @NonNull InsetsSourceControl.Array activeControls) {
        WindowStateInsetsControlChangeItem instance =
                ObjectPool.obtain(WindowStateInsetsControlChangeItem.class);
        if (instance == null) {
            instance = new WindowStateInsetsControlChangeItem();
        }
        instance.setWindow(window);
        instance.mInsetsState = new InsetsState(insetsState, true /* copySources */);
        instance.mActiveControls = new InsetsSourceControl.Array(
                activeControls, true /* copyControls */);
        // This source control is an extra copy if the client is not local. By setting
        // PARCELABLE_WRITE_RETURN_VALUE, the leash will be released at the end of
        // SurfaceControl.writeToParcel.
        instance.mActiveControls.setParcelableFlags(PARCELABLE_WRITE_RETURN_VALUE);

        return instance;
    }

    @Override
    public void recycle() {
        super.recycle();
        mInsetsState = null;
        mActiveControls = null;
        ObjectPool.recycle(this);
    }

    // Parcelable implementation

    /** Writes to Parcel. */
@@ -106,9 +107,8 @@ public class WindowStateInsetsControlChangeItem extends WindowStateTransactionIt
    /** Reads from Parcel. */
    private WindowStateInsetsControlChangeItem(@NonNull Parcel in) {
        super(in);
        mInsetsState = in.readTypedObject(InsetsState.CREATOR);
        mActiveControls = in.readTypedObject(InsetsSourceControl.Array.CREATOR);

        mInsetsState = requireNonNull(in.readTypedObject(InsetsState.CREATOR));
        mActiveControls = requireNonNull(in.readTypedObject(InsetsSourceControl.Array.CREATOR));
    }

    public static final @NonNull Creator<WindowStateInsetsControlChangeItem> CREATOR =
+43 −62
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

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;
@@ -35,25 +35,54 @@ import java.util.Objects;

/**
 * Message to deliver window resize info.
 *
 * @hide
 */
public class WindowStateResizeItem extends WindowStateTransactionItem {

    private static final String TAG = "WindowStateResizeItem";

    private ClientWindowFrames mFrames;
    private boolean mReportDraw;
    private MergedConfiguration mConfiguration;
    private InsetsState mInsetsState;
    private boolean mForceLayout;
    private boolean mAlwaysConsumeSystemBars;
    private int mDisplayId;
    private int mSyncSeqId;
    private boolean mDragResizing;
    @NonNull
    private final ClientWindowFrames mFrames;

    @NonNull
    private final MergedConfiguration mConfiguration;

    @NonNull
    private final InsetsState mInsetsState;

    /** {@code null} if this is not an Activity window. */
    @Nullable
    private ActivityWindowInfo mActivityWindowInfo;
    private final ActivityWindowInfo mActivityWindowInfo;

    private final boolean mReportDraw;
    private final boolean mForceLayout;
    private final boolean mAlwaysConsumeSystemBars;
    private final int mDisplayId;
    private final int mSyncSeqId;
    private final boolean mDragResizing;

    public WindowStateResizeItem(@NonNull IWindow window,
            @NonNull ClientWindowFrames frames, boolean reportDraw,
            @NonNull MergedConfiguration configuration, @NonNull InsetsState insetsState,
            boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId, int syncSeqId,
            boolean dragResizing, @Nullable ActivityWindowInfo activityWindowInfo) {
        super(window);
        mFrames = new ClientWindowFrames(frames);
        mConfiguration = new MergedConfiguration(configuration);
        mInsetsState = new InsetsState(insetsState, true /* copySources */);
        if (activityWindowInfo != null) {
            mActivityWindowInfo = new ActivityWindowInfo(activityWindowInfo);
        } else {
            mActivityWindowInfo = null;
        }
        mReportDraw = reportDraw;
        mForceLayout = forceLayout;
        mAlwaysConsumeSystemBars = alwaysConsumeSystemBars;
        mDisplayId = displayId;
        mSyncSeqId = syncSeqId;
        mDragResizing = dragResizing;
    }

    @Override
    public void execute(@NonNull ClientTransactionHandler client, @NonNull IWindow window,
@@ -73,54 +102,6 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
        Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
    }

    // ObjectPoolItem implementation

    private WindowStateResizeItem() {}

    /** Obtains an instance initialized with provided params. */
    public static WindowStateResizeItem obtain(@NonNull IWindow window,
            @NonNull ClientWindowFrames frames, boolean reportDraw,
            @NonNull MergedConfiguration configuration, @NonNull InsetsState insetsState,
            boolean forceLayout, boolean alwaysConsumeSystemBars, int displayId, int syncSeqId,
            boolean dragResizing, @Nullable ActivityWindowInfo activityWindowInfo) {
        WindowStateResizeItem instance =
                ObjectPool.obtain(WindowStateResizeItem.class);
        if (instance == null) {
            instance = new WindowStateResizeItem();
        }
        instance.setWindow(window);
        instance.mFrames = new ClientWindowFrames(frames);
        instance.mReportDraw = reportDraw;
        instance.mConfiguration = new MergedConfiguration(configuration);
        instance.mInsetsState = new InsetsState(insetsState, true /* copySources */);
        instance.mForceLayout = forceLayout;
        instance.mAlwaysConsumeSystemBars = alwaysConsumeSystemBars;
        instance.mDisplayId = displayId;
        instance.mSyncSeqId = syncSeqId;
        instance.mDragResizing = dragResizing;
        instance.mActivityWindowInfo = activityWindowInfo != null
                ? new ActivityWindowInfo(activityWindowInfo)
                : null;

        return instance;
    }

    @Override
    public void recycle() {
        super.recycle();
        mFrames = null;
        mReportDraw = false;
        mConfiguration = null;
        mInsetsState = null;
        mForceLayout = false;
        mAlwaysConsumeSystemBars = false;
        mDisplayId = INVALID_DISPLAY;
        mSyncSeqId = -1;
        mDragResizing = false;
        mActivityWindowInfo = null;
        ObjectPool.recycle(this);
    }

    // Parcelable implementation

    /** Writes to Parcel. */
@@ -142,10 +123,10 @@ public class WindowStateResizeItem extends WindowStateTransactionItem {
    /** Reads from Parcel. */
    private WindowStateResizeItem(@NonNull Parcel in) {
        super(in);
        mFrames = in.readTypedObject(ClientWindowFrames.CREATOR);
        mFrames = requireNonNull(in.readTypedObject(ClientWindowFrames.CREATOR));
        mReportDraw = in.readBoolean();
        mConfiguration = in.readTypedObject(MergedConfiguration.CREATOR);
        mInsetsState = in.readTypedObject(InsetsState.CREATOR);
        mConfiguration = requireNonNull(in.readTypedObject(MergedConfiguration.CREATOR));
        mInsetsState = requireNonNull(in.readTypedObject(InsetsState.CREATOR));
        mForceLayout = in.readBoolean();
        mAlwaysConsumeSystemBars = in.readBoolean();
        mDisplayId = in.readInt();
+10 −15
Original line number Diff line number Diff line
@@ -46,9 +46,12 @@ public abstract class WindowStateTransactionItem extends ClientTransactionItem {
    }

    /** Target window. */
    private IWindow mWindow;
    @NonNull
    private final IWindow mWindow;

    WindowStateTransactionItem() {}
    public WindowStateTransactionItem(@NonNull IWindow window) {
        mWindow = requireNonNull(window);
    }

    @Override
    public final void execute(@NonNull ClientTransactionHandler client,
@@ -67,26 +70,18 @@ public abstract class WindowStateTransactionItem extends ClientTransactionItem {
    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());
    }
    // Parcelable implementation

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

    @CallSuper
    @Override
    public void recycle() {
        mWindow = null;
    /** Reads from Parcel. */
    WindowStateTransactionItem(@NonNull Parcel in) {
        mWindow = requireNonNull(IWindow.Stub.asInterface(in.readStrongBinder()));
    }

    // Subclass must override and call super.equals to compare the mActivityToken.
+25 −22
Original line number Diff line number Diff line
@@ -87,10 +87,6 @@ public class ClientTransactionItemTest {
    private ActivityThread.ActivityClientRecord mActivityClientRecord;
    private ArrayMap<IBinder, DestroyActivityItem> mActivitiesToBeDestroyed;
    private InsetsState mInsetsState;
    private ClientWindowFrames mFrames;
    private MergedConfiguration mMergedConfiguration;
    private ActivityWindowInfo mActivityWindowInfo;
    private InsetsSourceControl.Array mActiveControls;

    @Before
    public void setup() {
@@ -99,10 +95,6 @@ public class ClientTransactionItemTest {
        mActivitiesToBeDestroyed = new ArrayMap<>();
        mActivityClientRecord = new ActivityThread.ActivityClientRecord();
        mInsetsState = new InsetsState();
        mFrames = new ClientWindowFrames();
        mMergedConfiguration = new MergedConfiguration(mGlobalConfig, mConfiguration);
        mActivityWindowInfo = new ActivityWindowInfo();
        mActiveControls = new InsetsSourceControl.Array();

        doReturn(mActivity).when(mHandler).getActivity(mActivityToken);
        doReturn(mActivitiesToBeDestroyed).when(mHandler).getActivitiesToBeDestroyed();
@@ -112,6 +104,7 @@ public class ClientTransactionItemTest {
    public void testDestroyActivityItem_preExecute() {
        final DestroyActivityItem item = DestroyActivityItem
                .obtain(mActivityToken, false /* finished */);

        item.preExecute(mHandler);

        assertEquals(1, mActivitiesToBeDestroyed.size());
@@ -123,6 +116,7 @@ public class ClientTransactionItemTest {
        final DestroyActivityItem item = DestroyActivityItem
                .obtain(mActivityToken, false /* finished */);
        item.preExecute(mHandler);

        item.postExecute(mHandler, mPendingActions);

        assertTrue(mActivitiesToBeDestroyed.isEmpty());
@@ -132,6 +126,7 @@ public class ClientTransactionItemTest {
    public void testDestroyActivityItem_execute() {
        final DestroyActivityItem item = DestroyActivityItem
                .obtain(mActivityToken, false /* finished */);

        item.execute(mHandler, mActivityClientRecord, mPendingActions);

        verify(mHandler).handleDestroyActivity(eq(mActivityClientRecord), eq(false) /* finishing */,
@@ -142,6 +137,7 @@ public class ClientTransactionItemTest {
    public void testWindowContextInfoChangeItem_execute() {
        final WindowContextInfoChangeItem item = WindowContextInfoChangeItem
                .obtain(mWindowClientToken, mConfiguration, DEFAULT_DISPLAY);

        item.execute(mHandler, mPendingActions);

        verify(mHandler).handleWindowContextInfoChanged(mWindowClientToken,
@@ -152,6 +148,7 @@ public class ClientTransactionItemTest {
    public void testWindowContextWindowRemovalItem_execute() {
        final WindowContextWindowRemovalItem item = WindowContextWindowRemovalItem.obtain(
                mWindowClientToken);

        item.execute(mHandler, mPendingActions);

        verify(mHandler).handleWindowContextWindowRemoval(mWindowClientToken);
@@ -159,37 +156,43 @@ public class ClientTransactionItemTest {

    @Test
    public void testWindowStateResizeItem_execute() throws RemoteException {
        final WindowStateResizeItem item = WindowStateResizeItem.obtain(mWindow, mFrames,
                true /* reportDraw */, mMergedConfiguration, mInsetsState, true /* forceLayout */,
        final MergedConfiguration mergedConfiguration = new MergedConfiguration(mGlobalConfig,
                mConfiguration);
        final ActivityWindowInfo activityWindowInfo = new ActivityWindowInfo();
        final ClientWindowFrames frames = new ClientWindowFrames();
        final WindowStateResizeItem item = new WindowStateResizeItem(mWindow, frames,
                true /* reportDraw */, mergedConfiguration, mInsetsState, true /* forceLayout */,
                true /* alwaysConsumeSystemBars */, 123 /* displayId */, 321 /* syncSeqId */,
                true /* dragResizing */, mActivityWindowInfo);
                true /* dragResizing */, activityWindowInfo);

        item.execute(mHandler, mPendingActions);

        verify(mWindow).resized(mFrames,
                true /* reportDraw */, mMergedConfiguration, mInsetsState, true /* forceLayout */,
        verify(mWindow).resized(frames,
                true /* reportDraw */, mergedConfiguration, mInsetsState, true /* forceLayout */,
                true /* alwaysConsumeSystemBars */, 123 /* displayId */, 321 /* syncSeqId */,
                true /* dragResizing */, mActivityWindowInfo);
                true /* dragResizing */, activityWindowInfo);
    }

    @Test
    public void testWindowStateInsetsControlChangeItem_execute() throws RemoteException {
        final WindowStateInsetsControlChangeItem item = WindowStateInsetsControlChangeItem.obtain(
                mWindow, mInsetsState, mActiveControls);
        final InsetsSourceControl.Array activeControls = new InsetsSourceControl.Array();
        final WindowStateInsetsControlChangeItem item = new WindowStateInsetsControlChangeItem(
                mWindow, mInsetsState, activeControls);

        item.execute(mHandler, mPendingActions);

        verify(mWindow).insetsControlChanged(mInsetsState, mActiveControls);
        verify(mWindow).insetsControlChanged(mInsetsState, activeControls);
    }

    @Test
    public void testWindowStateInsetsControlChangeItem_executeError() throws RemoteException {
        final InsetsSourceControl.Array spiedActiveControls = spy(new InsetsSourceControl.Array());
        final WindowStateInsetsControlChangeItem item = new WindowStateInsetsControlChangeItem(
                mWindow, mInsetsState, spiedActiveControls, false /* copyActiveControls */);
        doThrow(new RemoteException()).when(mWindow).insetsControlChanged(any(), any());

        mActiveControls = spy(mActiveControls);
        final WindowStateInsetsControlChangeItem item = WindowStateInsetsControlChangeItem.obtain(
                mWindow, mInsetsState, mActiveControls);
        item.mActiveControls = mActiveControls;
        item.execute(mHandler, mPendingActions);

        verify(mActiveControls).release();
        verify(spiedActiveControls).release();
    }
}
Loading