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

Commit 26790094 authored by Jiaming Liu's avatar Jiaming Liu
Browse files

Expose SurfaceControl of TaskFragment to system organzier

Bug: 284050041
Test: atest TaskFragmentOrganizerControllerTest TaskFragmentTest WindowFlagsTest
Change-Id: Ibcc8461d22a8c2bfbe88df388e2a5d432bf33150
parent e09e2341
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -25,9 +25,12 @@ import android.window.WindowContainerTransaction;
interface ITaskFragmentOrganizerController {

    /**
     * Registers a TaskFragmentOrganizer to manage TaskFragments.
     * Registers a TaskFragmentOrganizer to manage TaskFragments. Registering a system
     * organizer requires MANAGE_ACTIVITY_TASKS permission, and the organizer will have additional
     * system capabilities.
     */
    void registerOrganizer(in ITaskFragmentOrganizer organizer);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value=android.Manifest.permission.MANAGE_ACTIVITY_TASKS, conditional=true)")
    void registerOrganizer(in ITaskFragmentOrganizer organizer, in boolean isSystemOrganizer);

    /**
     * Unregisters a previously registered TaskFragmentOrganizer.
+28 −2
Original line number Diff line number Diff line
@@ -22,9 +22,11 @@ import static android.view.WindowManager.TRANSIT_NONE;
import static android.view.WindowManager.TRANSIT_OPEN;

import android.annotation.CallSuper;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.TestApi;
import android.os.Bundle;
import android.os.IBinder;
@@ -32,6 +34,8 @@ import android.os.RemoteException;
import android.view.RemoteAnimationDefinition;
import android.view.WindowManager;

import com.android.window.flags.Flags;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.concurrent.Executor;
@@ -140,12 +144,34 @@ public class TaskFragmentOrganizer extends WindowOrganizer {
    }

    /**
     * Registers a TaskFragmentOrganizer to manage TaskFragments.
     * Registers a {@link TaskFragmentOrganizer} to manage TaskFragments.
     */
    @CallSuper
    public void registerOrganizer() {
        // TODO(b/302420256) point to registerOrganizer(boolean) when flag is removed.
        try {
            getController().registerOrganizer(mInterface, false /* isSystemOrganizer */);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Registers a {@link TaskFragmentOrganizer} to manage TaskFragments.
     *
     * Registering a system organizer requires MANAGE_ACTIVITY_TASKS permission, and the organizer
     * will have additional system capabilities, including: (1) it will receive SurfaceControl for
     * the organized TaskFragment, and (2) it needs to update the
     * {@link android.view.SurfaceControl} following the window change accordingly.
     *
     * @hide
     */
    @CallSuper
    @RequiresPermission(value = "android.permission.MANAGE_ACTIVITY_TASKS", conditional = true)
    @FlaggedApi(Flags.FLAG_TASK_FRAGMENT_SYSTEM_ORGANIZER_FLAG)
    public void registerOrganizer(boolean isSystemOrganizer) {
        try {
            getController().registerOrganizer(mInterface);
            getController().registerOrganizer(mInterface, isSystemOrganizer);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+28 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.view.SurfaceControl;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -192,6 +193,9 @@ public final class TaskFragmentTransaction implements Parcelable {
        @Nullable
        private TaskFragmentParentInfo mTaskFragmentParentInfo;

        @Nullable
        private SurfaceControl mSurfaceControl;

        public Change(@ChangeType int type) {
            mType = type;
        }
@@ -206,6 +210,7 @@ public final class TaskFragmentTransaction implements Parcelable {
            mActivityIntent = in.readTypedObject(Intent.CREATOR);
            mActivityToken = in.readStrongBinder();
            mTaskFragmentParentInfo = in.readTypedObject(TaskFragmentParentInfo.CREATOR);
            mSurfaceControl = in.readTypedObject(SurfaceControl.CREATOR);
        }

        @Override
@@ -219,6 +224,7 @@ public final class TaskFragmentTransaction implements Parcelable {
            dest.writeTypedObject(mActivityIntent, flags);
            dest.writeStrongBinder(mActivityToken);
            dest.writeTypedObject(mTaskFragmentParentInfo, flags);
            dest.writeTypedObject(mSurfaceControl, flags);
        }

        /** The change is related to the TaskFragment created with this unique token. */
@@ -306,6 +312,13 @@ public final class TaskFragmentTransaction implements Parcelable {
            return this;
        }

        /** @hide */
        @NonNull
        public Change setTaskFragmentSurfaceControl(@Nullable SurfaceControl sc) {
            mSurfaceControl = sc;
            return this;
        }

        @ChangeType
        public int getType() {
            return mType;
@@ -359,6 +372,21 @@ public final class TaskFragmentTransaction implements Parcelable {
            return mTaskFragmentParentInfo;
        }

        /**
         * Gets the {@link SurfaceControl} of the TaskFragment. This field is {@code null} for
         * a regular {@link TaskFragmentOrganizer} and is only available for a system
         * {@link TaskFragmentOrganizer} in the
         * {@link TaskFragmentTransaction#TYPE_TASK_FRAGMENT_APPEARED} event. See
         * {@link ITaskFragmentOrganizerController#registerOrganizer(ITaskFragmentOrganizer,
         * boolean)}
         *
         * @hide
         */
        @Nullable
        public SurfaceControl getTaskFragmentSurfaceControl() {
            return mSurfaceControl;
        }

        @Override
        public String toString() {
            return "Change{ type=" + mType + " }";
+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.window.flags;

import static com.android.window.flags.Flags.syncWindowConfigUpdateFlag;
import static com.android.window.flags.Flags.taskFragmentSystemOrganizerFlag;

import android.platform.test.annotations.Presubmit;

@@ -42,4 +43,10 @@ public class WindowFlagsTest {
        // No crash when accessing the flag.
        syncWindowConfigUpdateFlag();
    }

    @Test
    public void testTaskFragmentSystemOrganizerFlag() {
        // No crash when accessing the flag.
        taskFragmentSystemOrganizerFlag();
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -254,6 +254,11 @@ class TaskFragment extends WindowContainer<WindowContainer> {
     */
    boolean mClearedForReorderActivityToFront;

    /**
     * Whether the TaskFragment surface is managed by a system {@link TaskFragmentOrganizer}.
     */
    boolean mIsSurfaceManagedBySystemOrganizer = false;

    /**
     * When we are in the process of pausing an activity, before starting the
     * next one, this variable holds the activity that is currently being paused.
@@ -449,13 +454,21 @@ class TaskFragment extends WindowContainer<WindowContainer> {

    void setTaskFragmentOrganizer(@NonNull TaskFragmentOrganizerToken organizer, int uid,
            @NonNull String processName) {
        setTaskFragmentOrganizer(organizer, uid, processName,
                false /* isSurfaceManagedBySystemOrganizer */);
    }

    void setTaskFragmentOrganizer(@NonNull TaskFragmentOrganizerToken organizer, int uid,
            @NonNull String processName, boolean isSurfaceManagedBySystemOrganizer) {
        mTaskFragmentOrganizer = ITaskFragmentOrganizer.Stub.asInterface(organizer.asBinder());
        mTaskFragmentOrganizerUid = uid;
        mTaskFragmentOrganizerProcessName = processName;
        mIsSurfaceManagedBySystemOrganizer = isSurfaceManagedBySystemOrganizer;
    }

    void onTaskFragmentOrganizerRemoved() {
        mTaskFragmentOrganizer = null;
        mIsSurfaceManagedBySystemOrganizer = false;
    }

    /** Whether this TaskFragment is organized by the given {@code organizer}. */
@@ -2396,6 +2409,9 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        if (mDelayOrganizedTaskFragmentSurfaceUpdate || mTaskFragmentOrganizer == null) {
            return;
        }
        if (mIsSurfaceManagedBySystemOrganizer) {
            return;
        }
        if (mTransitionController.isShellTransitionsEnabled()
                && !mTransitionController.isCollecting(this)) {
            // TaskFragmentOrganizer doesn't have access to the surface for security reasons, so
Loading