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

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

Merge changes I41b81615,Ia4324a5d,I74f25043 into main

* changes:
  Remove ConfigurationChangeItem pooling (17/n).
  Remove RefreshCallbackItem object pooling (16/n).
  Remove NewIntent/TopResumedItem pooling (15/n).
parents d420549b b6f318ce
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) {
+24 −38
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.app.servertransaction;

import static java.util.Objects.requireNonNull;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ClientTransactionHandler;
@@ -27,12 +29,20 @@ import java.util.Objects;

/**
 * App configuration change message.
 *
 * @hide
 */
public class ConfigurationChangeItem extends ClientTransactionItem {

    private Configuration mConfiguration;
    private int mDeviceId;
    @NonNull
    private final Configuration mConfiguration;

    private final int mDeviceId;

    public ConfigurationChangeItem(@NonNull Configuration config, int deviceId) {
        mConfiguration = new Configuration(config);
        mDeviceId = deviceId;
    }

    @Override
    public void preExecute(@NonNull ClientTransactionHandler client) {
@@ -46,47 +56,23 @@ public class ConfigurationChangeItem extends ClientTransactionItem {
        client.handleConfigurationChanged(mConfiguration, mDeviceId);
    }

    // ObjectPoolItem implementation

    private ConfigurationChangeItem() {}

    /** Obtain an instance initialized with provided params. */
    public static ConfigurationChangeItem obtain(@NonNull Configuration config, int deviceId) {
        ConfigurationChangeItem instance = ObjectPool.obtain(ConfigurationChangeItem.class);
        if (instance == null) {
            instance = new ConfigurationChangeItem();
        }
        instance.mConfiguration = new Configuration(config);
        instance.mDeviceId = deviceId;

        return instance;
    }

    @Override
    public void recycle() {
        mConfiguration = null;
        mDeviceId = 0;
        ObjectPool.recycle(this);
    }


    // Parcelable implementation

    /** Write to Parcel. */
    /** Writes to Parcel. */
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeTypedObject(mConfiguration, flags);
        dest.writeInt(mDeviceId);
    }

    /** Read from Parcel. */
    /** Reads from Parcel. */
    private ConfigurationChangeItem(Parcel in) {
        mConfiguration = in.readTypedObject(Configuration.CREATOR);
        mConfiguration = requireNonNull(in.readTypedObject(Configuration.CREATOR));
        mDeviceId = in.readInt();
    }

    public static final @android.annotation.NonNull Creator<ConfigurationChangeItem> CREATOR =
            new Creator<ConfigurationChangeItem>() {
            new Creator<>() {
                public ConfigurationChangeItem createFromParcel(Parcel in) {
                    return new ConfigurationChangeItem(in);
                }
+15 −30
Original line number Diff line number Diff line
@@ -38,13 +38,24 @@ import java.util.Objects;

/**
 * New intent message.
 *
 * @hide
 */
public class NewIntentItem 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<ReferrerIntent> mIntents;
    private boolean mResume;

    private final boolean mResume;

    public NewIntentItem(@NonNull IBinder activityToken,
            @NonNull List<ReferrerIntent> intents, boolean resume) {
        super(activityToken);
        mIntents = new ArrayList<>(intents);
        mResume = resume;
    }

    @Override
    public int getPostExecutionState() {
@@ -59,36 +70,9 @@ public class NewIntentItem extends ActivityTransactionItem {
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
    }

    // ObjectPoolItem implementation

    private NewIntentItem() {}

    /** Obtain an instance initialized with provided params. */
    @NonNull
    public static NewIntentItem obtain(@NonNull IBinder activityToken,
            @NonNull List<ReferrerIntent> intents, boolean resume) {
        NewIntentItem instance = ObjectPool.obtain(NewIntentItem.class);
        if (instance == null) {
            instance = new NewIntentItem();
        }
        instance.setActivityToken(activityToken);
        instance.mIntents = new ArrayList<>(intents);
        instance.mResume = resume;

        return instance;
    }

    @Override
    public void recycle() {
        super.recycle();
        mIntents = null;
        mResume = false;
        ObjectPool.recycle(this);
    }

    // Parcelable implementation

    /** Write to Parcel. */
    /** Writes to Parcel. */
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        super.writeToParcel(dest, flags);
@@ -96,10 +80,11 @@ public class NewIntentItem extends ActivityTransactionItem {
        dest.writeTypedList(mIntents, flags);
    }

    /** Read from Parcel. */
    /** Reads from Parcel. */
    private NewIntentItem(@NonNull Parcel in) {
        super(in);
        mResume = in.readBoolean();
        // TODO(b/170729553): Wrap with requireNonNull once @UnsupportedAppUsage removed.
        mIntents = in.createTypedArrayList(ReferrerIntent.CREATOR);
    }

+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) {
+11 −31
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app.servertransaction;

import static android.os.Trace.TRACE_TAG_ACTIVITY_MANAGER;
@@ -28,11 +29,17 @@ import android.os.Trace;

/**
 * Top resumed activity changed callback.
 *
 * @hide
 */
public class TopResumedActivityChangeItem extends ActivityTransactionItem {

    private boolean mOnTop;
    private final boolean mOnTop;

    public TopResumedActivityChangeItem(@NonNull IBinder activityToken, boolean onTop) {
        super(activityToken);
        mOnTop = onTop;
    }

    @Override
    public void execute(@NonNull ClientTransactionHandler client, @NonNull ActivityClientRecord r,
@@ -58,42 +65,16 @@ public class TopResumedActivityChangeItem extends ActivityTransactionItem {
        ActivityClient.getInstance().activityTopResumedStateLost();
    }

    // ObjectPoolItem implementation

    private TopResumedActivityChangeItem() {}

    /** Obtain an instance initialized with provided params. */
    @NonNull
    public static TopResumedActivityChangeItem obtain(@NonNull IBinder activityToken,
            boolean onTop) {
        TopResumedActivityChangeItem instance =
                ObjectPool.obtain(TopResumedActivityChangeItem.class);
        if (instance == null) {
            instance = new TopResumedActivityChangeItem();
        }
        instance.setActivityToken(activityToken);
        instance.mOnTop = onTop;

        return instance;
    }

    @Override
    public void recycle() {
        super.recycle();
        mOnTop = false;
        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.writeBoolean(mOnTop);
    }

    /** Read from Parcel. */
    /** Reads from Parcel. */
    private TopResumedActivityChangeItem(@NonNull Parcel in) {
        super(in);
        mOnTop = in.readBoolean();
@@ -131,7 +112,6 @@ public class TopResumedActivityChangeItem extends ActivityTransactionItem {

    @Override
    public String toString() {
        return "TopResumedActivityChangeItem{" + super.toString()
                + ",onTop=" + mOnTop + "}";
        return "TopResumedActivityChangeItem{" + super.toString() + ",onTop=" + mOnTop + "}";
    }
}
Loading