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

Commit 7080a7ab authored by Eric Lin's avatar Eric Lin
Browse files

Remove RefreshCallbackItem object pooling (16/n).

Remove the use of ObjectPool in the creation and management of
RefreshCallbackItem object. Instead of being obtained from the pool,
these objects are now directly instantiated, simplifying their handling
and aligning with the broader removal of the object pooling mechanism.

Bug: 311089192
Test: atest FrameworksCoreTests:ActivityRefresherTests
Test: atest WmTests:CameraCompatFreeformPolicyTests
Test: atest WmTests:DisplayRotationCompatPolicyTests
Flag: EXEMPT removing com.android.window.flags.disable_object_pool
Change-Id: Ia4324a5d7ba0e05c12470d8284fe1a0e3cd8b071
parent f9340262
Loading
Loading
Loading
Loading
+2 −19
Original line number Diff line number Diff line
@@ -49,30 +49,13 @@ import java.util.Objects;
public abstract class ActivityTransactionItem extends ClientTransactionItem {

    /** Target client activity. */
    // TODO(b/311089192): Mark this with @NonNull and final.
    private IBinder mActivityToken;
    @NonNull
    private final IBinder mActivityToken;

    public ActivityTransactionItem(@NonNull IBinder activityToken) {
        mActivityToken = requireNonNull(activityToken);
    }

    // TODO(b/311089192): Remove this method once no subclasses obtain from the object pool.
    @Deprecated
    ActivityTransactionItem() {
    }

    /**
     * Sets the activity token after the instance is obtained from the object pool.
     *
     * @deprecated This method is deprecated. The object pool is no longer used.
     *     Instead, directly create a new object with the activity token.
     * TODO(b/311089192): Remove this method once no subclasses obtain from the object pool.
     */
    @Deprecated
    void setActivityToken(@NonNull IBinder activityToken) {
        mActivityToken = requireNonNull(activityToken);
    }

    @Override
    public final void execute(@NonNull ClientTransactionHandler client,
            @NonNull PendingTransactionActions pendingActions) {
+21 −39
Original line number Diff line number Diff line
@@ -44,7 +44,20 @@ public class RefreshCallbackItem extends ActivityTransactionItem {
    // Whether refresh should happen using the "stopped -> resumed" cycle or
    // "paused -> resumed" cycle.
    @LifecycleState
    private int mPostExecutionState;
    private final int mPostExecutionState;

    /**
     * Creates a new RefreshCallbackItem.
     *
     * @param activityToken      the target client activity.
     * @param postExecutionState indicating whether refresh should happen using the
     *                           "stopped -> "resumed" cycle or "paused -> resumed" cycle.
     */
    public RefreshCallbackItem(
            @NonNull IBinder activityToken, @LifecycleState int postExecutionState) {
        super(activityToken);
        mPostExecutionState = postExecutionState;
    }

    @Override
    public void execute(@NonNull ClientTransactionHandler client,
@@ -67,47 +80,21 @@ public class RefreshCallbackItem extends ActivityTransactionItem {
        return false;
    }

    // ObjectPoolItem implementation

    @Override
    public void recycle() {
        super.recycle();
        ObjectPool.recycle(this);
    }

    /**
    * Obtain an instance initialized with provided params.
    * @param postExecutionState indicating whether refresh should happen using the
    *        "stopped -> resumed" cycle or "paused -> resumed" cycle.
    */
    @NonNull
    public static RefreshCallbackItem obtain(@NonNull IBinder activityToken,
            @LifecycleState int postExecutionState) {
        if (postExecutionState != ON_STOP && postExecutionState != ON_PAUSE) {
            throw new IllegalArgumentException(
                    "Only ON_STOP or ON_PAUSE are allowed as a post execution state for "
                            + "RefreshCallbackItem but got " + postExecutionState);
        }
        RefreshCallbackItem instance =
                ObjectPool.obtain(RefreshCallbackItem.class);
        if (instance == null) {
            instance = new RefreshCallbackItem();
        }
        instance.setActivityToken(activityToken);
        instance.mPostExecutionState = postExecutionState;
        return instance;
    }

    private RefreshCallbackItem() {}

    // Parcelable implementation

    /** Writes to Parcel. */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        dest.writeInt(mPostExecutionState);
    }

    /** Reads from Parcel. */
    private RefreshCallbackItem(@NonNull Parcel in) {
        super(in);
        mPostExecutionState = in.readInt();
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (this == o) {
@@ -134,11 +121,6 @@ public class RefreshCallbackItem extends ActivityTransactionItem {
                + ",mPostExecutionState=" + mPostExecutionState + "}";
    }

    private RefreshCallbackItem(@NonNull Parcel in) {
        super(in);
        mPostExecutionState = in.readInt();
    }

    public static final @NonNull Creator<RefreshCallbackItem> CREATOR = new Creator<>() {

        public RefreshCallbackItem createFromParcel(@NonNull Parcel in) {
+2 −2
Original line number Diff line number Diff line
@@ -84,8 +84,8 @@ class ActivityRefresher {
        ProtoLog.v(WM_DEBUG_STATES,
                "Refreshing activity for freeform camera compatibility treatment, "
                        + "activityRecord=%s", activity);
        final RefreshCallbackItem refreshCallbackItem = RefreshCallbackItem.obtain(
                activity.token, cycleThroughStop ? ON_STOP : ON_PAUSE);
        final RefreshCallbackItem refreshCallbackItem =
                new RefreshCallbackItem(activity.token, cycleThroughStop ? ON_STOP : ON_PAUSE);
        final ResumeActivityItem resumeActivityItem = new ResumeActivityItem(
                activity.token, /* isForward */ false, /* shouldSendCompatFakeFocus */ false);
        try {
+2 −2
Original line number Diff line number Diff line
@@ -191,8 +191,8 @@ public class ActivityRefresherTests extends WindowTestsBase {
        verify(mActivity.mAppCompatController.getAppCompatCameraOverrides(),
                times(refreshRequested ? 1 : 0)).setIsRefreshRequested(true);

        final RefreshCallbackItem refreshCallbackItem = RefreshCallbackItem.obtain(mActivity.token,
                cycleThroughStop ? ON_STOP : ON_PAUSE);
        final RefreshCallbackItem refreshCallbackItem =
                new RefreshCallbackItem(mActivity.token, cycleThroughStop ? ON_STOP : ON_PAUSE);
        final ResumeActivityItem resumeActivityItem = new ResumeActivityItem(mActivity.token,
                /* isForward */ false, /* shouldSendCompatFakeFocus */ false);

+2 −2
Original line number Diff line number Diff line
@@ -307,8 +307,8 @@ public class CameraCompatFreeformPolicyTests extends WindowTestsBase {
        verify(mActivity.mAppCompatController.getAppCompatCameraOverrides(),
                times(refreshRequested ? 1 : 0)).setIsRefreshRequested(true);

        final RefreshCallbackItem refreshCallbackItem = RefreshCallbackItem.obtain(mActivity.token,
                cycleThroughStop ? ON_STOP : ON_PAUSE);
        final RefreshCallbackItem refreshCallbackItem =
                new RefreshCallbackItem(mActivity.token, cycleThroughStop ? ON_STOP : ON_PAUSE);
        final ResumeActivityItem resumeActivityItem = new ResumeActivityItem(mActivity.token,
                /* isForward */ false, /* shouldSendCompatFakeFocus */ false);

Loading