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

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

Merge "Remove ActivityRelaunchItem object pooling (9/n)." into main

parents 6db50103 cd985c96
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6239,7 +6239,7 @@ public final class ActivityThread extends ClientTransactionHandler
                r.createdConfig != null
                        ? r.createdConfig : mConfigurationController.getConfiguration(),
                r.overrideConfig);
        final ActivityRelaunchItem activityRelaunchItem = ActivityRelaunchItem.obtain(
        final ActivityRelaunchItem activityRelaunchItem = new ActivityRelaunchItem(
                r.token, null /* pendingResults */, null /* pendingIntents */,
                0 /* configChanges */, mergedConfiguration, r.mPreserveWindow,
                r.getActivityWindowInfo());
+48 −61
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package android.app.servertransaction;

import static android.app.ActivityThread.DEBUG_ORDER;

import static java.util.Objects.requireNonNull;

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

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

    private static final String TAG = "ActivityRelaunchItem";

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

    @Nullable
    private final List<ReferrerIntent> mPendingNewIntents;

    @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
     * initialized after {@link #preExecute(ClientTransactionHandler)}.
     */
    @Nullable
    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
    public void preExecute(@NonNull ClientTransactionHandler client) {
        // 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);
    }

    // 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

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

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

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

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

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

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.resultInfoList;

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

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

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

        // 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, result);
Loading