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

Commit 8720c55b authored by Eric Lin's avatar Eric Lin
Browse files

Remove ActivityResultItem object pooling (10/n).

Remove the use of ObjectPool in the creation and management of
ActivityResultItem 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:ObjectPoolTests
Test: atest FrameworksCoreTests:TransactionParcelTests
Flag: EXEMPT removing com.android.window.flags.disable_object_pool
Change-Id: I1945ad52dba0a52ef9b32e256d17cf592f84c50f
parent cd985c96
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -3818,8 +3818,7 @@ public final class ActivityThread extends ClientTransactionHandler
        final ArrayList<ResultInfo> list = new ArrayList<>();
        list.add(new ResultInfo(id, requestCode, resultCode, data, activityToken));
        final ClientTransaction clientTransaction = new ClientTransaction(mAppThread);
        final ActivityResultItem activityResultItem = ActivityResultItem.obtain(
                activityToken, list);
        final ActivityResultItem activityResultItem = new ActivityResultItem(activityToken, list);
        clientTransaction.addTransactionItem(activityResultItem);
        try {
            mAppThread.scheduleTransaction(clientTransaction);
+12 −27
Original line number Diff line number Diff line
@@ -41,10 +41,13 @@ import java.util.Objects;

/**
 * Activity result delivery callback.
 *
 * @hide
 */
public class ActivityResultItem extends ActivityTransactionItem {

    // TODO(b/170729553): Mark this with @NonNull and final once @UnsupportedAppUsage removed.
    //  We cannot do it now to avoid app compatibility regression.
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    private List<ResultInfo> mResultInfoList;

@@ -56,6 +59,12 @@ public class ActivityResultItem extends ActivityTransactionItem {
    @EnabledAfter(targetSdkVersion = Build.VERSION_CODES.S)
    public static final long CALL_ACTIVITY_RESULT_BEFORE_RESUME = 78294732L;

    public ActivityResultItem(@NonNull IBinder activityToken,
            @NonNull List<ResultInfo> resultInfoList) {
        super(activityToken);
        mResultInfoList = new ArrayList<>(resultInfoList);
    }

    @Override
    public int getPostExecutionState() {
        return CompatChanges.isChangeEnabled(CALL_ACTIVITY_RESULT_BEFORE_RESUME)
@@ -70,43 +79,19 @@ public class ActivityResultItem extends ActivityTransactionItem {
        Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
    }

    // ObjectPoolItem implementation

    private ActivityResultItem() {}

    /** Obtain an instance initialized with provided params. */
    @NonNull
    public static ActivityResultItem obtain(@NonNull IBinder activityToken,
            @NonNull List<ResultInfo> resultInfoList) {
        ActivityResultItem instance = ObjectPool.obtain(ActivityResultItem.class);
        if (instance == null) {
            instance = new ActivityResultItem();
        }
        instance.setActivityToken(activityToken);
        instance.mResultInfoList = new ArrayList<>(resultInfoList);

        return instance;
    }

    @Override
    public void recycle() {
        super.recycle();
        mResultInfoList = 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(mResultInfoList, flags);
    }

    /** Read from Parcel. */
    /** Reads from Parcel. */
    private ActivityResultItem(@NonNull Parcel in) {
        super(in);
        // TODO(b/170729553): Wrap with requireNonNull once @UnsupportedAppUsage removed.
        mResultInfoList = in.createTypedArrayList(ResultInfo.CREATOR);
    }

+0 −5
Original line number Diff line number Diff line
@@ -71,11 +71,6 @@ public class ObjectPoolTests {
    // 2. Check if the state of the object is cleared after recycling.
    // 3. Check if the same object is obtained from pool after recycling.

    @Test
    public void testRecycleActivityResultItem() {
        testRecycle(() -> ActivityResultItem.obtain(mActivityToken, resultInfoList()));
    }

    @Test
    public void testRecycleConfigurationChangeItem() {
        testRecycle(() -> ConfigurationChangeItem.obtain(config(), 1));
+2 −2
Original line number Diff line number Diff line
@@ -135,11 +135,11 @@ public class TransactionParcelTests {
    @Test
    public void testActivityResult() {
        // Write to parcel
        ActivityResultItem item = ActivityResultItem.obtain(mActivityToken, resultInfoList());
        final ActivityResultItem item = new ActivityResultItem(mActivityToken, resultInfoList());
        writeAndPrepareForReading(item);

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

        assertEquals(item.hashCode(), result.hashCode());
        assertEquals(item, result);
+5 −5
Original line number Diff line number Diff line
@@ -4994,8 +4994,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            try {
                final ArrayList<ResultInfo> list = new ArrayList<>();
                list.add(new ResultInfo(resultWho, requestCode, resultCode, data, callerToken));
                mAtmService.getLifecycleManager().scheduleTransactionItem(app.getThread(),
                        ActivityResultItem.obtain(token, list));
                final ActivityResultItem item = new ActivityResultItem(token, list);
                mAtmService.getLifecycleManager().scheduleTransactionItem(app.getThread(), item);
                return;
            } catch (Exception e) {
                Slog.w(TAG, "Exception thrown sending result to " + this, e);
@@ -5006,9 +5006,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        if (forceSendForMediaProjection && attachedToProcess() && isState(STARTED, PAUSING, PAUSED,
                STOPPING, STOPPED)) {
            // Build result to be returned immediately.
            final ActivityResultItem activityResultItem = ActivityResultItem.obtain(
                    token, List.of(new ResultInfo(resultWho, requestCode, resultCode, data,
                            callerToken)));
            final List<ResultInfo> infos = List.of(
                    new ResultInfo(resultWho, requestCode, resultCode, data, callerToken));
            final ActivityResultItem activityResultItem = new ActivityResultItem(token, infos);
            // When the activity result is delivered, the activity will transition to RESUMED.
            // Since the activity is only resumed so the result can be immediately delivered,
            // return it to its original lifecycle state.
Loading