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

Commit 7df7076d authored by Graciela Putri's avatar Graciela Putri Committed by Android (Google) Code Review
Browse files

Merge changes Ifa1c51e5,I24db7165,I04d4da5a,I5656f205,I4f51148b, ... into main

* changes:
  [55/n] Integrate LetterboxTaskListenerAdapter
  [54/n] Implement ActivityLetterboxLifecycleEventFactory.
  [53/n] Define LetterboxTaskListenerAdapter
  [4/n] Create TaskAppearedListener and TaskInfoChangedListener
  [3/n] Add AppCompatTransitionInfo to ActivityTransitionInfo
  [52/n] LetterboxTaskInfoRepository implementation
parents f5061acd e0f81c5d
Loading
Loading
Loading
Loading
+30 −8
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.window;
import static com.android.internal.annotations.VisibleForTesting.Visibility.PROTECTED;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.os.Parcelable;

@@ -39,13 +40,17 @@ public final class ActivityTransitionInfo implements Parcelable {
    @NonNull
    private final ComponentName mComponent;
    private final int mTaskId;
    @Nullable
    private final AppCompatTransitionInfo mAppCompatTransitionInfo;

    @VisibleForTesting(visibility = PROTECTED)
    public ActivityTransitionInfo(@NonNull ActivityTransitionInfo other) {
        this(other.mComponent.clone(), other.mTaskId);
        this(other.mComponent.clone(), other.mTaskId, other.mAppCompatTransitionInfo);
    }


    public ActivityTransitionInfo(@NonNull ComponentName component, int taskId) {
        this(component, taskId, null);
    }

    // Code below generated by codegen v1.0.23.
    //
@@ -63,11 +68,13 @@ public final class ActivityTransitionInfo implements Parcelable {
    @DataClass.Generated.Member
    public ActivityTransitionInfo(
            @NonNull ComponentName component,
            int taskId) {
            int taskId,
            @Nullable AppCompatTransitionInfo appCompatTransitionInfo) {
        this.mComponent = component;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mComponent);
        this.mTaskId = taskId;
        this.mAppCompatTransitionInfo = appCompatTransitionInfo;

        // onConstructed(); // You can define this method to get a callback
    }
@@ -82,6 +89,11 @@ public final class ActivityTransitionInfo implements Parcelable {
        return mTaskId;
    }

    @DataClass.Generated.Member
    public @Nullable AppCompatTransitionInfo getAppCompatTransitionInfo() {
        return mAppCompatTransitionInfo;
    }

    @Override
    @DataClass.Generated.Member
    public String toString() {
@@ -90,13 +102,14 @@ public final class ActivityTransitionInfo implements Parcelable {

        return "ActivityTransitionInfo { " +
                "component = " + mComponent + ", " +
                "taskId = " + mTaskId +
                "taskId = " + mTaskId + ", " +
                "appCompatTransitionInfo = " + mAppCompatTransitionInfo +
        " }";
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@android.annotation.Nullable Object o) {
    public boolean equals(@Nullable Object o) {
        // You can override field equality logic by defining either of the methods like:
        // boolean fieldNameEquals(ActivityTransitionInfo other) { ... }
        // boolean fieldNameEquals(FieldType otherValue) { ... }
@@ -108,7 +121,8 @@ public final class ActivityTransitionInfo implements Parcelable {
        //noinspection PointlessBooleanExpression
        return true
                && java.util.Objects.equals(mComponent, that.mComponent)
                && mTaskId == that.mTaskId;
                && mTaskId == that.mTaskId
                && java.util.Objects.equals(mAppCompatTransitionInfo, that.mAppCompatTransitionInfo);
    }

    @Override
@@ -120,6 +134,7 @@ public final class ActivityTransitionInfo implements Parcelable {
        int _hash = 1;
        _hash = 31 * _hash + java.util.Objects.hashCode(mComponent);
        _hash = 31 * _hash + mTaskId;
        _hash = 31 * _hash + java.util.Objects.hashCode(mAppCompatTransitionInfo);
        return _hash;
    }

@@ -129,8 +144,12 @@ public final class ActivityTransitionInfo implements Parcelable {
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }

        byte flg = 0;
        if (mAppCompatTransitionInfo != null) flg |= 0x4;
        dest.writeByte(flg);
        dest.writeTypedObject(mComponent, flags);
        dest.writeInt(mTaskId);
        if (mAppCompatTransitionInfo != null) dest.writeTypedObject(mAppCompatTransitionInfo, flags);
    }

    @Override
@@ -144,13 +163,16 @@ public final class ActivityTransitionInfo implements Parcelable {
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }

        byte flg = in.readByte();
        ComponentName component = (ComponentName) in.readTypedObject(ComponentName.CREATOR);
        int taskId = in.readInt();
        AppCompatTransitionInfo appCompatTransitionInfo = (flg & 0x4) == 0 ? null : (AppCompatTransitionInfo) in.readTypedObject(AppCompatTransitionInfo.CREATOR);

        this.mComponent = component;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mComponent);
        this.mTaskId = taskId;
        this.mAppCompatTransitionInfo = appCompatTransitionInfo;

        // onConstructed(); // You can define this method to get a callback
    }
@@ -170,10 +192,10 @@ public final class ActivityTransitionInfo implements Parcelable {
    };

    @DataClass.Generated(
            time = 1747732592428L,
            time = 1748332897391L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/window/ActivityTransitionInfo.java",
            inputSignatures = "private final @android.annotation.NonNull android.content.ComponentName mComponent\nprivate final  int mTaskId\nclass ActivityTransitionInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=true, genGetters=true, genEqualsHashCode=true, genParcelable=true, genToString=true)")
            inputSignatures = "private final @android.annotation.NonNull android.content.ComponentName mComponent\nprivate final  int mTaskId\nprivate final @android.annotation.Nullable android.window.AppCompatTransitionInfo mAppCompatTransitionInfo\nclass ActivityTransitionInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=true, genGetters=true, genEqualsHashCode=true, genParcelable=true, genToString=true)")
    @Deprecated
    private void __metadata() {}

+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.window;

parcelable AppCompatTransitionInfo;
+159 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.window;

import android.annotation.NonNull;
import android.graphics.Rect;
import android.os.Parcelable;

import com.android.internal.util.DataClass;

/**
 * Encapsulate all the information useful to AppCompat in an Activity transition.
 *
 * @hide
 */
@DataClass(genConstructor = true, genGetters = true, genEqualsHashCode = true,
        genParcelable = true, genToString = true)
public class AppCompatTransitionInfo implements Parcelable {

    @NonNull
    private final Rect mLetterboxBounds;


    // Code below generated by codegen v1.0.23.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/window/AppCompatTransitionInfo.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    @DataClass.Generated.Member
    public AppCompatTransitionInfo(
            @NonNull Rect letterboxBounds) {
        this.mLetterboxBounds = letterboxBounds;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mLetterboxBounds);

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public @NonNull Rect getLetterboxBounds() {
        return mLetterboxBounds;
    }

    @Override
    @DataClass.Generated.Member
    public String toString() {
        // You can override field toString logic by defining methods like:
        // String fieldNameToString() { ... }

        return "AppCompatTransitionInfo { " +
                "letterboxBounds = " + mLetterboxBounds +
        " }";
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@android.annotation.Nullable Object o) {
        // You can override field equality logic by defining either of the methods like:
        // boolean fieldNameEquals(AppCompatTransitionInfo other) { ... }
        // boolean fieldNameEquals(FieldType otherValue) { ... }

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        @SuppressWarnings("unchecked")
        AppCompatTransitionInfo that = (AppCompatTransitionInfo) o;
        //noinspection PointlessBooleanExpression
        return true
                && java.util.Objects.equals(mLetterboxBounds, that.mLetterboxBounds);
    }

    @Override
    @DataClass.Generated.Member
    public int hashCode() {
        // You can override field hashCode logic by defining methods like:
        // int fieldNameHashCode() { ... }

        int _hash = 1;
        _hash = 31 * _hash + java.util.Objects.hashCode(mLetterboxBounds);
        return _hash;
    }

    @Override
    @DataClass.Generated.Member
    public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }

        dest.writeTypedObject(mLetterboxBounds, flags);
    }

    @Override
    @DataClass.Generated.Member
    public int describeContents() { return 0; }

    /** @hide */
    @SuppressWarnings({"unchecked", "RedundantCast"})
    @DataClass.Generated.Member
    protected AppCompatTransitionInfo(@NonNull android.os.Parcel in) {
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }

        Rect letterboxBounds = (Rect) in.readTypedObject(Rect.CREATOR);

        this.mLetterboxBounds = letterboxBounds;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mLetterboxBounds);

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public static final @NonNull Parcelable.Creator<AppCompatTransitionInfo> CREATOR
            = new Parcelable.Creator<AppCompatTransitionInfo>() {
        @Override
        public AppCompatTransitionInfo[] newArray(int size) {
            return new AppCompatTransitionInfo[size];
        }

        @Override
        public AppCompatTransitionInfo createFromParcel(@NonNull android.os.Parcel in) {
            return new AppCompatTransitionInfo(in);
        }
    };

    @DataClass.Generated(
            time = 1748331474800L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/window/AppCompatTransitionInfo.java",
            inputSignatures = "private final @android.annotation.NonNull android.graphics.Rect mLetterboxBounds\nclass AppCompatTransitionInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=true, genGetters=true, genEqualsHashCode=true, genParcelable=true, genToString=true)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}
+35 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.window

import android.content.ComponentName
import android.graphics.Rect
import android.os.test.recreateFromParcel
import android.platform.test.annotations.Presubmit
import android.view.SurfaceControl
@@ -41,9 +42,12 @@ class TransitionInfoTest {
    private val token = WindowContainerToken(mock<IWindowContainerToken>())
    private val change = TransitionInfo.Change(token, SurfaceControl() /* leash */)
    private val activityTransitionInfo = ActivityTransitionInfo(component, TASK_ID)
    private val appCompatTransitionInfo = AppCompatTransitionInfo(letterboxBounds)
    private val activityTransitionInfoWithAppCompat =
        ActivityTransitionInfo(component, TASK_ID, appCompatTransitionInfo)

    @Test
    fun parcelable_recreatewithActivityTransitionInfoSucceeds() {
    fun parcelable_recreateWithActivityTransitionInfoSucceeds() {
        change.activityTransitionInfo = activityTransitionInfo
        val transitionInfo = TransitionInfo(TRANSIT_OPEN, 0 /* flags */)
        transitionInfo.addChange(change)
@@ -69,10 +73,40 @@ class TransitionInfoTest {
        assertThat(chg.activityTransitionInfo).isNotSameInstanceAs(activityTransitionInfo)
    }

    @Test
    fun parcelable_recreateWithActivityTransitionInfoWithAppCompatSucceeds() {
        change.activityTransitionInfo = activityTransitionInfoWithAppCompat
        val transitionInfo = TransitionInfo(TRANSIT_OPEN, 0 /* flags */)
        transitionInfo.addChange(change)

        val createdFromParcel = transitionInfo.recreateFromParcel(TransitionInfo.CREATOR)

        assertThat(createdFromParcel.changes).hasSize(1)
        val chg = createdFromParcel.changes[0]
        assertThat(chg.activityTransitionInfo).isEqualTo(activityTransitionInfoWithAppCompat)
    }

    @Test
    fun localRemoteCopy_copiesActivityTransitionInfoWithAppCompat() {
        change.activityTransitionInfo = activityTransitionInfoWithAppCompat
        val transitionInfo = TransitionInfo(TRANSIT_OPEN, 0 /* flags */)
        transitionInfo.addChange(change)

        val copiedTransitionInfo = transitionInfo.localRemoteCopy()

        assertThat(copiedTransitionInfo.changes).hasSize(1)
        val chg = copiedTransitionInfo.changes[0]
        assertThat(chg.activityTransitionInfo).isEqualTo(activityTransitionInfoWithAppCompat)
        assertThat(chg.activityTransitionInfo).isNotSameInstanceAs(
            activityTransitionInfoWithAppCompat
        )
    }

    companion object {
        private const val TASK_ID = 123
        private const val TEST_PACKAGE_NAME = "com.example.app"
        private const val TEST_CLASS_NAME = "com.example.app.MainActivity"
        private val component = ComponentName(TEST_PACKAGE_NAME, TEST_CLASS_NAME)
        private val letterboxBounds = Rect(1, 2, 3, 4)
    }
}
 No newline at end of file
+89 −5
Original line number Diff line number Diff line
@@ -103,10 +103,9 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    /**
     * Callbacks for when the tasks change in the system.
     */
    public interface TaskListener {
        default void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) {}
        default void onTaskInfoChanged(RunningTaskInfo taskInfo) {}
        default void onTaskVanished(RunningTaskInfo taskInfo) {}
    public interface TaskListener extends TaskVanishedListener, TaskAppearedListener,
            TaskInfoChangedListener {

        default void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {}
        /** Whether this task listener supports compat UI. */
        default boolean supportCompatUI() {
@@ -133,9 +132,44 @@ public class ShellTaskOrganizer extends TaskOrganizer {
     * that is necessary.
     */
    public interface TaskVanishedListener {
        /**
         * Invoked when a Task is removed from Shell.
         *
         * @param taskInfo The RunningTaskInfo for the Task.
         */
        default void onTaskVanished(RunningTaskInfo taskInfo) {}
    }

    /**
     * Limited scope callback to notify when a task is added from the system. This signal is
     * not synchronized with anything (or any transition), and should not be used in cases where
     * that is necessary.
     */
    public interface TaskAppearedListener {
        /**
         * Invoked when a Task appears on Shell. Because the leash can be shared between different
         * implementations, it's important to not apply changes in the related callback.
         *
         * @param taskInfo The RunningTaskInfo for the Task.
         * @param leash    The leash for the Task which should not be changed through this callback.
         */
        default void onTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) {}
    }

    /**
     * Limited scope callback to notify when a task has updated. This signal is
     * not synchronized with anything (or any transition), and should not be used in cases where
     * that is necessary.
     */
    public interface TaskInfoChangedListener {
        /**
         * Invoked when a Task is updated on Shell.
         *
         * @param taskInfo The RunningTaskInfo for the Task.
         */
        default void onTaskInfoChanged(RunningTaskInfo taskInfo) {}
    }

    /**
     * Callbacks for events on a task with a locus id.
     */
@@ -185,10 +219,18 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    private final CopyOnWriteArrayList<FocusListener> mFocusListeners =
            new CopyOnWriteArrayList<>();

    // Listeners that should be notified when a task is removed
    // Listeners that should be notified when a task is vanished.
    private final CopyOnWriteArrayList<TaskVanishedListener> mTaskVanishedListeners =
            new CopyOnWriteArrayList<>();

    // Listeners that should be notified when a task has appeared.
    private final CopyOnWriteArrayList<TaskAppearedListener> mTaskAppearedListeners =
            new CopyOnWriteArrayList<>();

    // Listeners that should be notified when a task is updated
    private final CopyOnWriteArrayList<TaskInfoChangedListener> mTaskInfoChangedListeners =
            new CopyOnWriteArrayList<>();

    private final Object mLock = new Object();
    private StartingWindowController mStartingWindow;

@@ -543,6 +585,42 @@ public class ShellTaskOrganizer extends TaskOrganizer {
        }
    }

    /**
     * Adds a listener to be notified when a task is appears.
     */
    public void addTaskAppearedListener(TaskAppearedListener listener) {
        synchronized (mLock) {
            mTaskAppearedListeners.add(listener);
        }
    }

    /**
     * Removes a task-appeared listener.
     */
    public void removeTaskAppearedListener(TaskAppearedListener listener) {
        synchronized (mLock) {
            mTaskAppearedListeners.remove(listener);
        }
    }

    /**
     * Adds a listener to be notified when a task is updated.
     */
    public void addTaskInfoChangedListener(TaskInfoChangedListener listener) {
        synchronized (mLock) {
            mTaskInfoChangedListeners.add(listener);
        }
    }

    /**
     * Removes a taskInfo-update listener.
     */
    public void removeTaskInfoChangedListener(TaskInfoChangedListener listener) {
        synchronized (mLock) {
            mTaskInfoChangedListeners.remove(listener);
        }
    }

    /**
     * Returns a surface which can be used to attach overlays to the home root task
     */
@@ -635,6 +713,9 @@ public class ShellTaskOrganizer extends TaskOrganizer {
        notifyLocusVisibilityIfNeeded(info.getTaskInfo());
        notifyCompatUI(info.getTaskInfo(), listener);
        mRecentTasks.ifPresent(recentTasks -> recentTasks.onTaskAdded(info.getTaskInfo()));
        for (TaskAppearedListener l : mTaskAppearedListeners) {
            l.onTaskAppeared(info.getTaskInfo(), info.getLeash());
        }
    }

    @Override
@@ -682,6 +763,9 @@ public class ShellTaskOrganizer extends TaskOrganizer {
                }
                mLastFocusedTaskInfo = taskInfo;
            }
            for (TaskInfoChangedListener l : mTaskInfoChangedListeners) {
                l.onTaskInfoChanged(taskInfo);
            }
        }
    }

Loading