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

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

Merge "Remove LaunchActivityItem object pooling (12/n)." into main

parents f3666374 bf6e6a26
Loading
Loading
Loading
Loading
+164 −130
Original line number Diff line number Diff line
@@ -20,9 +20,12 @@ import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;

import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityClient;
import android.app.ActivityManager.ProcessState;
import android.app.ActivityOptions.SceneTransitionInfo;
import android.app.ActivityThread.ActivityClientRecord;
import android.app.ClientTransactionHandler;
@@ -52,41 +55,148 @@ import java.util.Objects;

/**
 * Request to launch an activity.
 *
 * @hide
 */
public class LaunchActivityItem extends ClientTransactionItem {

    private IBinder mActivityToken;
    @NonNull
    private final IBinder mActivityToken;

    // TODO(b/170729553): Mark this with @NonNull and final once @UnsupportedAppUsage removed.
    //  We cannot do it now to avoid app compatibility regression.
    @UnsupportedAppUsage
    private Intent mIntent;
    private int mIdent;

    // TODO(b/170729553): Mark this with @NonNull and final once @UnsupportedAppUsage removed.
    //  We cannot do it now to avoid app compatibility regression.
    @UnsupportedAppUsage
    private ActivityInfo mInfo;
    private Configuration mCurConfig;
    private Configuration mOverrideConfig;
    private int mDeviceId;
    private String mReferrer;
    private IVoiceInteractor mVoiceInteractor;
    private int mProcState;
    private Bundle mState;
    private PersistableBundle mPersistentState;
    private List<ResultInfo> mPendingResults;
    private List<ReferrerIntent> mPendingNewIntents;
    private SceneTransitionInfo mSceneTransitionInfo;
    private boolean mIsForward;
    private ProfilerInfo mProfilerInfo;
    private IBinder mAssistToken;
    private IBinder mShareableActivityToken;
    private boolean mLaunchedFromBubble;
    private IBinder mTaskFragmentToken;
    private IBinder mInitialCallerInfoAccessToken;
    private ActivityWindowInfo mActivityWindowInfo;

    @NonNull
    private final Configuration mCurConfig;

    @NonNull
    private final Configuration mOverrideConfig;

    @Nullable
    private final String mReferrer;

    @Nullable
    private final IVoiceInteractor mVoiceInteractor;

    @Nullable
    private final Bundle mState;

    @Nullable
    private final PersistableBundle mPersistentState;

    @Nullable
    private final List<ResultInfo> mPendingResults;

    @Nullable
    private final List<ReferrerIntent> mPendingNewIntents;

    @Nullable
    private final SceneTransitionInfo mSceneTransitionInfo;

    @Nullable
    private final ProfilerInfo mProfilerInfo;

    @NonNull
    private final IBinder mAssistToken;

    @NonNull
    private final IBinder mShareableActivityToken;

    @Nullable
    private final IBinder mTaskFragmentToken;

    @NonNull
    private final IBinder mInitialCallerInfoAccessToken;

    @NonNull
    private final ActivityWindowInfo mActivityWindowInfo;

    /**
     * It is only non-null if the process is the first time to launch activity. It is only an
     * optimization for quick look up of the interface so the field is ignored for comparison.
     */
    private IActivityClientController mActivityClientController;
    @Nullable
    private final IActivityClientController mActivityClientController;

    private final int mIdent;
    private final int mDeviceId;
    private final int mProcState;
    private final boolean mIsForward;
    private final boolean mLaunchedFromBubble;

    public LaunchActivityItem(@NonNull IBinder activityToken, @NonNull Intent intent,
            int ident, @NonNull ActivityInfo info, @NonNull Configuration curConfig,
            @NonNull Configuration overrideConfig, int deviceId, @Nullable String referrer,
            @Nullable IVoiceInteractor voiceInteractor, @ProcessState int procState,
            @Nullable Bundle state, @Nullable PersistableBundle persistentState,
            @Nullable List<ResultInfo> pendingResults,
            @Nullable List<ReferrerIntent> pendingNewIntents,
            @Nullable SceneTransitionInfo sceneTransitionInfo,
            boolean isForward, @Nullable ProfilerInfo profilerInfo, @NonNull IBinder assistToken,
            @Nullable IActivityClientController activityClientController,
            @NonNull IBinder shareableActivityToken, boolean launchedFromBubble,
            @Nullable IBinder taskFragmentToken, @NonNull IBinder initialCallerInfoAccessToken,
            @NonNull ActivityWindowInfo activityWindowInfo) {
        this(activityToken, ident, new Configuration(curConfig), new Configuration(overrideConfig),
                deviceId, referrer, voiceInteractor, procState,
                state != null ? new Bundle(state) : null,
                persistentState != null ? new PersistableBundle(persistentState) : null,
                pendingResults != null ? new ArrayList<>(pendingResults) : null,
                pendingNewIntents != null ? new ArrayList<>(pendingNewIntents) : null,
                sceneTransitionInfo, isForward,
                profilerInfo != null ? new ProfilerInfo(profilerInfo) : null,
                assistToken, activityClientController, shareableActivityToken, launchedFromBubble,
                taskFragmentToken, initialCallerInfoAccessToken,
                new ActivityWindowInfo(activityWindowInfo));
        mIntent = new Intent(intent);
        mInfo = new ActivityInfo(info);
    }

    // TODO(b/170729553): Merge this constructor with previous one if no @UnsupportedAppUsage filed.
    //  We cannot do it now to avoid app compatibility regression.
    private LaunchActivityItem(@NonNull IBinder activityToken, int ident,
            @NonNull Configuration curConfig,
            @NonNull Configuration overrideConfig, int deviceId, @Nullable String referrer,
            @Nullable IVoiceInteractor voiceInteractor, @ProcessState int procState,
            @Nullable Bundle state, @Nullable PersistableBundle persistentState,
            @Nullable List<ResultInfo> pendingResults,
            @Nullable List<ReferrerIntent> pendingNewIntents,
            @Nullable SceneTransitionInfo sceneTransitionInfo,
            boolean isForward, @Nullable ProfilerInfo profilerInfo, @NonNull IBinder assistToken,
            @Nullable IActivityClientController activityClientController,
            @NonNull IBinder shareableActivityToken, boolean launchedFromBubble,
            @Nullable IBinder taskFragmentToken, @NonNull IBinder initialCallerInfoAccessToken,
            @NonNull ActivityWindowInfo activityWindowInfo) {
        mActivityToken = activityToken;
        mIdent = ident;
        mCurConfig = curConfig;
        mOverrideConfig = overrideConfig;
        mDeviceId = deviceId;
        mReferrer = referrer;
        mVoiceInteractor = voiceInteractor;
        mProcState = procState;
        mState = state;
        mPersistentState = persistentState;
        mPendingResults = pendingResults;
        mPendingNewIntents = pendingNewIntents;
        mSceneTransitionInfo = sceneTransitionInfo;
        mIsForward = isForward;
        mProfilerInfo = profilerInfo;
        mAssistToken = assistToken;
        mActivityClientController = activityClientController;
        mShareableActivityToken = shareableActivityToken;
        mLaunchedFromBubble = launchedFromBubble;
        mTaskFragmentToken = taskFragmentToken;
        mInitialCallerInfoAccessToken = initialCallerInfoAccessToken;
        mActivityWindowInfo = activityWindowInfo;
    }

    @Override
    public void preExecute(@NonNull ClientTransactionHandler client) {
@@ -119,44 +229,6 @@ public class LaunchActivityItem extends ClientTransactionItem {
        client.countLaunchingActivities(-1);
    }

    // ObjectPoolItem implementation

    private LaunchActivityItem() {}

    /** Obtain an instance initialized with provided params. */
    @NonNull
    public static LaunchActivityItem obtain(@NonNull IBinder activityToken, @NonNull Intent intent,
            int ident, @NonNull ActivityInfo info, @NonNull Configuration curConfig,
            @NonNull Configuration overrideConfig, int deviceId, @Nullable String referrer,
            @Nullable IVoiceInteractor voiceInteractor, int procState, @Nullable Bundle state,
            @Nullable PersistableBundle persistentState, @Nullable List<ResultInfo> pendingResults,
            @Nullable List<ReferrerIntent> pendingNewIntents,
            @Nullable SceneTransitionInfo sceneTransitionInfo,
            boolean isForward, @Nullable ProfilerInfo profilerInfo, @NonNull IBinder assistToken,
            @Nullable IActivityClientController activityClientController,
            @NonNull IBinder shareableActivityToken, boolean launchedFromBubble,
            @Nullable IBinder taskFragmentToken, @NonNull IBinder initialCallerInfoAccessToken,
            @NonNull ActivityWindowInfo activityWindowInfo) {
        LaunchActivityItem instance = ObjectPool.obtain(LaunchActivityItem.class);
        if (instance == null) {
            instance = new LaunchActivityItem();
        }
        setValues(instance, activityToken, new Intent(intent), ident,  new ActivityInfo(info),
                new Configuration(curConfig), new Configuration(overrideConfig), deviceId,
                referrer, voiceInteractor, procState,
                state != null ? new Bundle(state) : null,
                persistentState != null ? new PersistableBundle(persistentState) : null,
                pendingResults != null ? new ArrayList<>(pendingResults) : null,
                pendingNewIntents != null ? new ArrayList<>(pendingNewIntents) : null,
                sceneTransitionInfo, isForward,
                profilerInfo != null ? new ProfilerInfo(profilerInfo) : null,
                assistToken, activityClientController, shareableActivityToken,
                launchedFromBubble, taskFragmentToken, initialCallerInfoAccessToken,
                new ActivityWindowInfo(activityWindowInfo));

        return instance;
    }

    @VisibleForTesting(visibility = PACKAGE)
    @NonNull
    @Override
@@ -164,22 +236,13 @@ public class LaunchActivityItem extends ClientTransactionItem {
        return mActivityToken;
    }

    @Override
    public void recycle() {
        setValues(this, null, null, 0, null, null, null, 0, null, null, 0, null, null, null, null,
                null, false, null, null, null, null, false, null, null, null);
        ObjectPool.recycle(this);
    }

    // Parcelable implementation

    /** Write from Parcel. */
    /** Writes to Parcel. */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeStrongBinder(mActivityToken);
        dest.writeTypedObject(mIntent, flags);
        dest.writeInt(mIdent);
        dest.writeTypedObject(mInfo, flags);
        dest.writeTypedObject(mCurConfig, flags);
        dest.writeTypedObject(mOverrideConfig, flags);
        dest.writeInt(mDeviceId);
@@ -200,28 +263,40 @@ public class LaunchActivityItem extends ClientTransactionItem {
        dest.writeStrongBinder(mTaskFragmentToken);
        dest.writeStrongBinder(mInitialCallerInfoAccessToken);
        dest.writeTypedObject(mActivityWindowInfo, flags);

        dest.writeTypedObject(mIntent, flags);
        dest.writeTypedObject(mInfo, flags);
    }

    /** Read from Parcel. */
    /** Reads from Parcel. */
    private LaunchActivityItem(@NonNull Parcel in) {
        setValues(this, in.readStrongBinder(), in.readTypedObject(Intent.CREATOR), in.readInt(),
                in.readTypedObject(ActivityInfo.CREATOR), in.readTypedObject(Configuration.CREATOR),
                in.readTypedObject(Configuration.CREATOR), in.readInt(), in.readString(),
                IVoiceInteractor.Stub.asInterface(in.readStrongBinder()), in.readInt(),
                in.readBundle(getClass().getClassLoader()),
                in.readPersistableBundle(getClass().getClassLoader()),
                in.createTypedArrayList(ResultInfo.CREATOR),
                in.createTypedArrayList(ReferrerIntent.CREATOR),
                in.readTypedObject(SceneTransitionInfo.CREATOR),
                in.readBoolean(),
                in.readTypedObject(ProfilerInfo.CREATOR),
                in.readStrongBinder(),
                IActivityClientController.Stub.asInterface(in.readStrongBinder()),
                in.readStrongBinder(),
                in.readBoolean(),
                in.readStrongBinder(),
                in.readStrongBinder(),
                in.readTypedObject(ActivityWindowInfo.CREATOR));
        this(in.readStrongBinder() /* activityToken */,
                in.readInt() /* ident */,
                requireNonNull(in.readTypedObject(Configuration.CREATOR)) /* curConfig */,
                requireNonNull(in.readTypedObject(Configuration.CREATOR)) /* overrideConfig */,
                in.readInt() /* deviceId */,
                in.readString() /* referrer */,
                IVoiceInteractor.Stub.asInterface(in.readStrongBinder()) /* voiceInteractor */,
                in.readInt() /* procState */,
                in.readBundle(in.getClass().getClassLoader()) /* state */,
                in.readPersistableBundle(in.getClass().getClassLoader()) /* persistentState */,
                in.createTypedArrayList(ResultInfo.CREATOR) /* pendingResults */,
                in.createTypedArrayList(ReferrerIntent.CREATOR) /* pendingNewIntents */,
                in.readTypedObject(SceneTransitionInfo.CREATOR) /* sceneTransitionInfo */,
                in.readBoolean() /* isForward */,
                in.readTypedObject(ProfilerInfo.CREATOR) /* profilerInfo */,
                in.readStrongBinder() /* assistToken */,
                IActivityClientController.Stub.asInterface(
                        in.readStrongBinder()) /* activityClientController */,
                in.readStrongBinder() /* shareableActivityToken */,
                in.readBoolean() /* launchedFromBubble */,
                in.readStrongBinder() /* taskFragmentToken */,
                in.readStrongBinder() /* initialCallerInfoAccessToken */,
                requireNonNull(in.readTypedObject(ActivityWindowInfo.CREATOR))
                /* activityWindowInfo */
        );
        mIntent = in.readTypedObject(Intent.CREATOR);
        mInfo = in.readTypedObject(ActivityInfo.CREATOR);
    }

    public static final @NonNull Creator<LaunchActivityItem> CREATOR = new Creator<>() {
@@ -339,45 +414,4 @@ public class LaunchActivityItem extends ClientTransactionItem {
                + ",activityWindowInfo=" + mActivityWindowInfo
                + "}";
    }

    // Using the same method to set and clear values to make sure we don't forget anything
    private static void setValues(@Nullable LaunchActivityItem instance,
            @Nullable IBinder activityToken, @Nullable Intent intent, int ident,
            @Nullable ActivityInfo info, @Nullable Configuration curConfig,
            @Nullable Configuration overrideConfig, int deviceId,
            @Nullable String referrer, @Nullable IVoiceInteractor voiceInteractor,
            int procState, @Nullable Bundle state, @Nullable PersistableBundle persistentState,
            @Nullable List<ResultInfo> pendingResults,
            @Nullable List<ReferrerIntent> pendingNewIntents,
            @Nullable SceneTransitionInfo sceneTransitionInfo, boolean isForward,
            @Nullable ProfilerInfo profilerInfo, @Nullable IBinder assistToken,
            @Nullable IActivityClientController activityClientController,
            @Nullable IBinder shareableActivityToken, boolean launchedFromBubble,
            @Nullable IBinder taskFragmentToken, @Nullable IBinder initialCallerInfoAccessToken,
            @Nullable ActivityWindowInfo activityWindowInfo) {
        instance.mActivityToken = activityToken;
        instance.mIntent = intent;
        instance.mIdent = ident;
        instance.mInfo = info;
        instance.mCurConfig = curConfig;
        instance.mOverrideConfig = overrideConfig;
        instance.mDeviceId = deviceId;
        instance.mReferrer = referrer;
        instance.mVoiceInteractor = voiceInteractor;
        instance.mProcState = procState;
        instance.mState = state;
        instance.mPersistentState = persistentState;
        instance.mPendingResults = pendingResults;
        instance.mPendingNewIntents = pendingNewIntents;
        instance.mSceneTransitionInfo = sceneTransitionInfo;
        instance.mIsForward = isForward;
        instance.mProfilerInfo = profilerInfo;
        instance.mAssistToken = assistToken;
        instance.mActivityClientController = activityClientController;
        instance.mShareableActivityToken = shareableActivityToken;
        instance.mLaunchedFromBubble = launchedFromBubble;
        instance.mTaskFragmentToken = taskFragmentToken;
        instance.mInitialCallerInfoAccessToken = initialCallerInfoAccessToken;
        instance.mActivityWindowInfo = activityWindowInfo;
    }
}
+0 −57
Original line number Diff line number Diff line
@@ -18,20 +18,11 @@ package android.app.servertransaction;

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

import static org.junit.Assert.assertNotSame;

import android.annotation.NonNull;
import android.app.servertransaction.TestUtils.LaunchActivityItemBuilder;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.PersistableBundle;
import android.platform.test.annotations.Presubmit;
import android.window.ActivityWindowInfo;

@@ -76,54 +67,6 @@ public class ObjectPoolTests {
        testRecycle(() -> ConfigurationChangeItem.obtain(config(), 1));
    }

    @Test
    public void testRecycleLaunchActivityItem() {
        final IBinder activityToken = new Binder();
        final Intent intent = new Intent("action");
        final int ident = 57;
        final ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.flags = 42;
        activityInfo.setMaxAspectRatio(2.4f);
        activityInfo.launchToken = "token";
        activityInfo.applicationInfo = new ApplicationInfo();
        activityInfo.packageName = "packageName";
        activityInfo.name = "name";
        final Configuration overrideConfig = new Configuration();
        overrideConfig.assetsSeq = 5;
        final String referrer = "referrer";
        final int procState = 4;
        final Bundle bundle = new Bundle();
        bundle.putString("key", "value");
        final PersistableBundle persistableBundle = new PersistableBundle();
        persistableBundle.putInt("k", 4);
        final IBinder assistToken = new Binder();
        final IBinder shareableActivityToken = new Binder();
        final int deviceId = 3;
        final IBinder taskFragmentToken = new Binder();
        final IBinder initialCallerInfoAccessToken = new Binder();
        final ActivityWindowInfo activityWindowInfo = new ActivityWindowInfo();

        testRecycle(() -> new LaunchActivityItemBuilder(
                activityToken, intent, activityInfo)
                .setIdent(ident)
                .setCurConfig(config())
                .setOverrideConfig(overrideConfig)
                .setReferrer(referrer)
                .setProcState(procState)
                .setState(bundle)
                .setPersistentState(persistableBundle)
                .setPendingResults(resultInfoList())
                .setPendingNewIntents(referrerIntentList())
                .setIsForward(true)
                .setAssistToken(assistToken)
                .setShareableActivityToken(shareableActivityToken)
                .setTaskFragmentToken(taskFragmentToken)
                .setDeviceId(deviceId)
                .setInitialCallerInfoAccessToken(initialCallerInfoAccessToken)
                .setActivityWindowInfo(activityWindowInfo)
                .build());
    }

    @Test
    public void testRecycleMoveToDisplayItem() {
        testRecycle(() -> MoveToDisplayItem.obtain(mActivityToken, 4, config(),
+1 −1
Original line number Diff line number Diff line
@@ -271,7 +271,7 @@ class TestUtils {

        @NonNull
        LaunchActivityItem build() {
            return LaunchActivityItem.obtain(mActivityToken, mIntent, mIdent, mInfo,
            return new LaunchActivityItem(mActivityToken, mIntent, mIdent, mInfo,
                    mCurConfig, mOverrideConfig, mDeviceId, mReferrer, mVoiceInteractor,
                    mProcState, mState, mPersistentState, mPendingResults, mPendingNewIntents,
                    mActivityOptions != null ? mActivityOptions.getSceneTransitionInfo() : null,
+5 −9
Original line number Diff line number Diff line
@@ -163,7 +163,7 @@ public class TransactionParcelTests {
        // Write to parcel
        final IBinder activityToken = new Binder();
        final Intent intent = new Intent("action");
        int ident = 57;
        final int ident = 57;
        final ActivityInfo activityInfo = new ActivityInfo();
        activityInfo.flags = 42;
        activityInfo.setMaxAspectRatio(2.4f);
@@ -174,7 +174,7 @@ public class TransactionParcelTests {
        final Configuration overrideConfig = new Configuration();
        overrideConfig.assetsSeq = 5;
        final String referrer = "referrer";
        int procState = 4;
        final int procState = 4;
        final Bundle bundle = new Bundle();
        bundle.putString("key", "value");
        bundle.putParcelable("data", new ParcelableData(1));
@@ -326,9 +326,7 @@ public class TransactionParcelTests {
     *   android.app.servertransaction.TransactionParcelTests$ParcelableData".
     */
    public static class ParcelableData implements Parcelable {
        int mValue;

        ParcelableData() {}
        private final int mValue;

        ParcelableData(int value) {
            mValue = value;
@@ -344,12 +342,10 @@ public class TransactionParcelTests {
            dest.writeInt(mValue);
        }

        public static final Creator<ParcelableData> CREATOR = new Creator<ParcelableData>() {
        public static final Creator<ParcelableData> CREATOR = new Creator<>() {
            @Override
            public ParcelableData createFromParcel(Parcel source) {
                final ParcelableData data = new ParcelableData();
                data.mValue = source.readInt();
                return data;
                return new ParcelableData(source.readInt());
            }

            @Override
+1 −1
Original line number Diff line number Diff line
@@ -929,7 +929,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                final boolean isTransitionForward = r.isTransitionForward();
                final IBinder fragmentToken = r.getTaskFragment().getFragmentToken();
                final int deviceId = getDeviceIdForDisplayId(r.getDisplayId());
                final LaunchActivityItem launchActivityItem = LaunchActivityItem.obtain(r.token,
                final LaunchActivityItem launchActivityItem = new LaunchActivityItem(r.token,
                        r.intent, System.identityHashCode(r), r.info,
                        procConfig, overrideConfig, deviceId,
                        r.getFilteredReferrer(r.launchedFromPackage), task.voiceInteractor,