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

Commit cd985c96 authored by Eric Lin's avatar Eric Lin
Browse files

Remove ActivityRelaunchItem object pooling (9/n).

Remove the use of ObjectPool in the creation and management of
ActivityRelaunchItem 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:ActivityThreadTest
Test: atest FrameworksCoreTests:ObjectPoolTests
Test: atest FrameworksCoreTests:TransactionParcelTests
Flag: EXEMPT removing com.android.window.flags.disable_object_pool
Change-Id: I236a5bf704b5944350c2f66aea20bd804d3609ad
parent c3d12d78
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -6239,7 +6239,7 @@ public final class ActivityThread extends ClientTransactionHandler
                r.createdConfig != null
                r.createdConfig != null
                        ? r.createdConfig : mConfigurationController.getConfiguration(),
                        ? r.createdConfig : mConfigurationController.getConfiguration(),
                r.overrideConfig);
                r.overrideConfig);
        final ActivityRelaunchItem activityRelaunchItem = ActivityRelaunchItem.obtain(
        final ActivityRelaunchItem activityRelaunchItem = new ActivityRelaunchItem(
                r.token, null /* pendingResults */, null /* pendingIntents */,
                r.token, null /* pendingResults */, null /* pendingIntents */,
                0 /* configChanges */, mergedConfiguration, r.mPreserveWindow,
                0 /* configChanges */, mergedConfiguration, r.mPreserveWindow,
                r.getActivityWindowInfo());
                r.getActivityWindowInfo());
+48 −61
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@ package android.app.servertransaction;


import static android.app.ActivityThread.DEBUG_ORDER;
import static android.app.ActivityThread.DEBUG_ORDER;


import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityThread.ActivityClientRecord;
import android.app.ActivityThread.ActivityClientRecord;
@@ -39,25 +41,50 @@ import java.util.Objects;


/**
/**
 * Activity relaunch callback.
 * Activity relaunch callback.
 *
 * @hide
 * @hide
 */
 */
public class ActivityRelaunchItem extends ActivityTransactionItem {
public class ActivityRelaunchItem extends ActivityTransactionItem {


    private static final String TAG = "ActivityRelaunchItem";
    private static final String TAG = "ActivityRelaunchItem";


    private List<ResultInfo> mPendingResults;
    @Nullable
    private List<ReferrerIntent> mPendingNewIntents;
    private final List<ResultInfo> mPendingResults;
    private int mConfigChanges;

    private MergedConfiguration mConfig;
    @Nullable
    private boolean mPreserveWindow;
    private final List<ReferrerIntent> mPendingNewIntents;
    private ActivityWindowInfo mActivityWindowInfo;

    @NonNull
    private final MergedConfiguration mConfig;

    @NonNull
    private final ActivityWindowInfo mActivityWindowInfo;

    private final int mConfigChanges;
    private final boolean mPreserveWindow;


    /**
    /**
     * A record that was properly configured for relaunch. Execution will be cancelled if not
     * A record that was properly configured for relaunch. Execution will be cancelled if not
     * initialized after {@link #preExecute(ClientTransactionHandler)}.
     * initialized after {@link #preExecute(ClientTransactionHandler)}.
     */
     */
    @Nullable
    private ActivityClientRecord mActivityClientRecord;
    private ActivityClientRecord mActivityClientRecord;


    public ActivityRelaunchItem(@NonNull IBinder activityToken,
            @Nullable List<ResultInfo> pendingResults,
            @Nullable List<ReferrerIntent> pendingNewIntents, int configChanges,
            @NonNull MergedConfiguration config, boolean preserveWindow,
            @NonNull ActivityWindowInfo activityWindowInfo) {
        super(activityToken);
        mPendingResults = pendingResults != null ? new ArrayList<>(pendingResults) : null;
        mPendingNewIntents =
                pendingNewIntents != null ? new ArrayList<>(pendingNewIntents) : null;
        mConfig = new MergedConfiguration(config);
        mActivityWindowInfo = new ActivityWindowInfo(activityWindowInfo);
        mConfigChanges = configChanges;
        mPreserveWindow = preserveWindow;
    }

    @Override
    @Override
    public void preExecute(@NonNull ClientTransactionHandler client) {
    public void preExecute(@NonNull ClientTransactionHandler client) {
        // The local config is already scaled so only apply if this item is from server side.
        // The local config is already scaled so only apply if this item is from server side.
@@ -87,70 +114,29 @@ public class ActivityRelaunchItem extends ActivityTransactionItem {
        client.reportRelaunch(r);
        client.reportRelaunch(r);
    }
    }


    // ObjectPoolItem implementation

    private ActivityRelaunchItem() {}

    /** Obtain an instance initialized with provided params. */
    @NonNull
    public static ActivityRelaunchItem obtain(@NonNull IBinder activityToken,
            @Nullable List<ResultInfo> pendingResults,
            @Nullable List<ReferrerIntent> pendingNewIntents, int configChanges,
            @NonNull MergedConfiguration config, boolean preserveWindow,
            @NonNull ActivityWindowInfo activityWindowInfo) {
        ActivityRelaunchItem instance = ObjectPool.obtain(ActivityRelaunchItem.class);
        if (instance == null) {
            instance = new ActivityRelaunchItem();
        }
        instance.setActivityToken(activityToken);
        instance.mPendingResults = pendingResults != null ? new ArrayList<>(pendingResults) : null;
        instance.mPendingNewIntents =
                pendingNewIntents != null ? new ArrayList<>(pendingNewIntents) : null;
        instance.mConfigChanges = configChanges;
        instance.mConfig = new MergedConfiguration(config);
        instance.mPreserveWindow = preserveWindow;
        instance.mActivityWindowInfo = new ActivityWindowInfo(activityWindowInfo);

        return instance;
    }

    @Override
    public void recycle() {
        super.recycle();
        mPendingResults = null;
        mPendingNewIntents = null;
        mConfigChanges = 0;
        mConfig = null;
        mPreserveWindow = false;
        mActivityClientRecord = null;
        mActivityWindowInfo = null;
        ObjectPool.recycle(this);
    }


    // Parcelable implementation
    // Parcelable implementation


    /** Write to Parcel. */
    /** Writes to Parcel. */
    @Override
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
        super.writeToParcel(dest, flags);
        dest.writeTypedList(mPendingResults, flags);
        dest.writeTypedList(mPendingResults, flags);
        dest.writeTypedList(mPendingNewIntents, flags);
        dest.writeTypedList(mPendingNewIntents, flags);
        dest.writeInt(mConfigChanges);
        dest.writeTypedObject(mConfig, flags);
        dest.writeTypedObject(mConfig, flags);
        dest.writeBoolean(mPreserveWindow);
        dest.writeTypedObject(mActivityWindowInfo, flags);
        dest.writeTypedObject(mActivityWindowInfo, flags);
        dest.writeInt(mConfigChanges);
        dest.writeBoolean(mPreserveWindow);
    }
    }


    /** Read from Parcel. */
    /** Reads from Parcel. */
    private ActivityRelaunchItem(@NonNull Parcel in) {
    private ActivityRelaunchItem(@NonNull Parcel in) {
        super(in);
        super(in);
        mPendingResults = in.createTypedArrayList(ResultInfo.CREATOR);
        mPendingResults = in.createTypedArrayList(ResultInfo.CREATOR);
        mPendingNewIntents = in.createTypedArrayList(ReferrerIntent.CREATOR);
        mPendingNewIntents = in.createTypedArrayList(ReferrerIntent.CREATOR);
        mConfig = requireNonNull(in.readTypedObject(MergedConfiguration.CREATOR));
        mActivityWindowInfo = requireNonNull(in.readTypedObject(ActivityWindowInfo.CREATOR));
        mConfigChanges = in.readInt();
        mConfigChanges = in.readInt();
        mConfig = in.readTypedObject(MergedConfiguration.CREATOR);
        mPreserveWindow = in.readBoolean();
        mPreserveWindow = in.readBoolean();
        mActivityWindowInfo = in.readTypedObject(ActivityWindowInfo.CREATOR);
    }
    }


    public static final @NonNull Creator<ActivityRelaunchItem> CREATOR =
    public static final @NonNull Creator<ActivityRelaunchItem> CREATOR =
@@ -175,9 +161,10 @@ public class ActivityRelaunchItem extends ActivityTransactionItem {
        final ActivityRelaunchItem other = (ActivityRelaunchItem) o;
        final ActivityRelaunchItem other = (ActivityRelaunchItem) o;
        return Objects.equals(mPendingResults, other.mPendingResults)
        return Objects.equals(mPendingResults, other.mPendingResults)
                && Objects.equals(mPendingNewIntents, other.mPendingNewIntents)
                && Objects.equals(mPendingNewIntents, other.mPendingNewIntents)
                && mConfigChanges == other.mConfigChanges && Objects.equals(mConfig, other.mConfig)
                && Objects.equals(mConfig, other.mConfig)
                && mPreserveWindow == other.mPreserveWindow
                && Objects.equals(mActivityWindowInfo, other.mActivityWindowInfo)
                && Objects.equals(mActivityWindowInfo, other.mActivityWindowInfo);
                && mConfigChanges == other.mConfigChanges
                && mPreserveWindow == other.mPreserveWindow;
    }
    }


    @Override
    @Override
@@ -186,10 +173,10 @@ public class ActivityRelaunchItem extends ActivityTransactionItem {
        result = 31 * result + super.hashCode();
        result = 31 * result + super.hashCode();
        result = 31 * result + Objects.hashCode(mPendingResults);
        result = 31 * result + Objects.hashCode(mPendingResults);
        result = 31 * result + Objects.hashCode(mPendingNewIntents);
        result = 31 * result + Objects.hashCode(mPendingNewIntents);
        result = 31 * result + mConfigChanges;
        result = 31 * result + Objects.hashCode(mConfig);
        result = 31 * result + Objects.hashCode(mConfig);
        result = 31 * result + (mPreserveWindow ? 1 : 0);
        result = 31 * result + Objects.hashCode(mActivityWindowInfo);
        result = 31 * result + Objects.hashCode(mActivityWindowInfo);
        result = 31 * result + mConfigChanges;
        result = 31 * result + (mPreserveWindow ? 1 : 0);
        return result;
        return result;
    }
    }


@@ -198,9 +185,9 @@ public class ActivityRelaunchItem extends ActivityTransactionItem {
        return "ActivityRelaunchItem{" + super.toString()
        return "ActivityRelaunchItem{" + super.toString()
                + ",pendingResults=" + mPendingResults
                + ",pendingResults=" + mPendingResults
                + ",pendingNewIntents=" + mPendingNewIntents
                + ",pendingNewIntents=" + mPendingNewIntents
                + ",configChanges="  + mConfigChanges
                + ",config=" + mConfig
                + ",config=" + mConfig
                + ",preserveWindow=" + mPreserveWindow
                + ",activityWindowInfo=" + mActivityWindowInfo
                + ",activityWindowInfo=" + mActivityWindowInfo + "}";
                + ",configChanges=" + mConfigChanges
                + ",preserveWindow=" + mPreserveWindow + "}";
    }
    }
}
}
+2 −2
Original line number Original line Diff line number Diff line
@@ -847,7 +847,7 @@ public class ActivityThreadTest {
            final ActivityWindowInfo newInfo = new ActivityWindowInfo();
            final ActivityWindowInfo newInfo = new ActivityWindowInfo();
            newInfo.set(true /* isEmbedded */, new Rect(0, 0, 1000, 2000),
            newInfo.set(true /* isEmbedded */, new Rect(0, 0, 1000, 2000),
                    new Rect(0, 0, 1000, 1000));
                    new Rect(0, 0, 1000, 1000));
            final ActivityRelaunchItem relaunchItem = ActivityRelaunchItem.obtain(
            final ActivityRelaunchItem relaunchItem = new ActivityRelaunchItem(
                    activity.getActivityToken(), null, null, 0,
                    activity.getActivityToken(), null, null, 0,
                    new MergedConfiguration(currentConfig, currentConfig),
                    new MergedConfiguration(currentConfig, currentConfig),
                    false /* preserveWindow */, newInfo);
                    false /* preserveWindow */, newInfo);
@@ -978,7 +978,7 @@ public class ActivityThreadTest {
        } else {
        } else {
            activityWindowInfo = record.getActivityWindowInfo();
            activityWindowInfo = record.getActivityWindowInfo();
        }
        }
        final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(
        final ClientTransactionItem callbackItem = new ActivityRelaunchItem(
                activity.getActivityToken(), null, null, 0,
                activity.getActivityToken(), null, null, 0,
                new MergedConfiguration(currentConfig, currentConfig),
                new MergedConfiguration(currentConfig, currentConfig),
                false /* preserveWindow */, activityWindowInfo);
                false /* preserveWindow */, activityWindowInfo);
+0 −8
Original line number Original line Diff line number Diff line
@@ -17,7 +17,6 @@
package android.app.servertransaction;
package android.app.servertransaction;


import static android.app.servertransaction.TestUtils.config;
import static android.app.servertransaction.TestUtils.config;
import static android.app.servertransaction.TestUtils.mergedConfig;
import static android.app.servertransaction.TestUtils.referrerIntentList;
import static android.app.servertransaction.TestUtils.referrerIntentList;
import static android.app.servertransaction.TestUtils.resultInfoList;
import static android.app.servertransaction.TestUtils.resultInfoList;


@@ -130,13 +129,6 @@ public class ObjectPoolTests {
                .build());
                .build());
    }
    }


    @Test
    public void testRecycleActivityRelaunchItem() {
        testRecycle(() -> ActivityRelaunchItem.obtain(mActivityToken,
                resultInfoList(), referrerIntentList(), 42, mergedConfig(), true,
                new ActivityWindowInfo()));
    }

    @Test
    @Test
    public void testRecycleMoveToDisplayItem() {
    public void testRecycleMoveToDisplayItem() {
        testRecycle(() -> MoveToDisplayItem.obtain(mActivityToken, 4, config(),
        testRecycle(() -> MoveToDisplayItem.obtain(mActivityToken, 4, config(),
+3 −3
Original line number Original line Diff line number Diff line
@@ -216,17 +216,17 @@ public class TransactionParcelTests {
    @Test
    @Test
    public void testRelaunch() {
    public void testRelaunch() {
        // Write to parcel
        // Write to parcel
        Configuration overrideConfig = new Configuration();
        final Configuration overrideConfig = new Configuration();
        overrideConfig.assetsSeq = 5;
        overrideConfig.assetsSeq = 5;
        final ActivityWindowInfo activityWindowInfo = new ActivityWindowInfo();
        final ActivityWindowInfo activityWindowInfo = new ActivityWindowInfo();
        activityWindowInfo.set(true /* isEmbedded */, new Rect(0, 0, 500, 1000),
        activityWindowInfo.set(true /* isEmbedded */, new Rect(0, 0, 500, 1000),
                new Rect(0, 0, 500, 500));
                new Rect(0, 0, 500, 500));
        ActivityRelaunchItem item = ActivityRelaunchItem.obtain(mActivityToken, resultInfoList(),
        final ActivityRelaunchItem item = new ActivityRelaunchItem(mActivityToken, resultInfoList(),
                referrerIntentList(), 35, mergedConfig(), true, activityWindowInfo);
                referrerIntentList(), 35, mergedConfig(), true, activityWindowInfo);
        writeAndPrepareForReading(item);
        writeAndPrepareForReading(item);


        // Read from parcel and assert
        // Read from parcel and assert
        ActivityRelaunchItem result = ActivityRelaunchItem.CREATOR.createFromParcel(mParcel);
        final ActivityRelaunchItem result = ActivityRelaunchItem.CREATOR.createFromParcel(mParcel);


        assertEquals(item.hashCode(), result.hashCode());
        assertEquals(item.hashCode(), result.hashCode());
        assertEquals(item, result);
        assertEquals(item, result);
Loading