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

Commit 10fc25da authored by Winson Chung's avatar Winson Chung
Browse files

Clean up remote animation definitions when activity is destroyed

- Remove the remote animation definition when the associated process dies
- Also expose method to unregister any registered animation defs

Bug: 139137636
Test: Kill launcher, ensure the remote animation ref is removed
Change-Id: Ia38d037397703221c17c8258ec1a245055d5896d
parent 8cdd14c9
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -8674,7 +8674,6 @@ public class Activity extends ContextThemeWrapper
     * @hide
     */
    @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS)
    @UnsupportedAppUsage
    public void registerRemoteAnimations(RemoteAnimationDefinition definition) {
        try {
            ActivityTaskManager.getService().registerRemoteAnimations(mToken, definition);
@@ -8683,6 +8682,20 @@ public class Activity extends ContextThemeWrapper
        }
    }

    /**
     * Unregisters all remote animations for this activity.
     *
     * @hide
     */
    @RequiresPermission(CONTROL_REMOTE_APP_TRANSITION_ANIMATIONS)
    public void unregisterRemoteAnimations() {
        try {
            ActivityTaskManager.getService().unregisterRemoteAnimations(mToken);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    class HostCallbacks extends FragmentHostCallback<Activity> {
        public HostCallbacks() {
            super(Activity.this /*activity*/);
+5 −0
Original line number Diff line number Diff line
@@ -436,6 +436,11 @@ interface IActivityTaskManager {
     */
    void registerRemoteAnimations(in IBinder token, in RemoteAnimationDefinition definition);

    /**
     * Unregisters all remote animations for a specific activity.
     */
    void unregisterRemoteAnimations(in IBinder token);

    /**
     * Registers a remote animation to be run for all activity starts from a certain package during
     * a short predefined amount of time.
+17 −0
Original line number Diff line number Diff line
@@ -22,9 +22,12 @@ import android.annotation.Nullable;
import android.app.WindowConfiguration;
import android.app.WindowConfiguration.ActivityType;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.util.ArraySet;
import android.util.Slog;
import android.util.SparseArray;
import android.view.WindowManager.TransitionType;

@@ -124,6 +127,20 @@ public class RemoteAnimationDefinition implements Parcelable {
        }
    }

    /**
     * Links the death of the runner to the provided death recipient.
     */
    public void linkToDeath(IBinder.DeathRecipient deathRecipient) {
        try {
            for (int i = 0; i < mTransitionAnimationMap.size(); i++) {
                mTransitionAnimationMap.valueAt(i).adapter.getRunner().asBinder()
                        .linkToDeath(deathRecipient, 0 /* flags */);
            }
        } catch (RemoteException e) {
            Slog.e("RemoteAnimationDefinition", "Failed to link to death recipient");
        }
    }

    @Override
    public int describeContents() {
        return 0;
+7 −0
Original line number Diff line number Diff line
@@ -36,6 +36,13 @@ public class ActivityCompat {
        mWrapped.registerRemoteAnimations(definition.getWrapped());
    }

    /**
     * @see Activity#unregisterRemoteAnimations
     */
    public void unregisterRemoteAnimations() {
        mWrapped.unregisterRemoteAnimations();
    }

    /**
     * @see android.view.ViewDebug#dumpv2(View, ByteArrayOutputStream)
     */
+7 −0
Original line number Diff line number Diff line
@@ -6063,6 +6063,13 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    void registerRemoteAnimations(RemoteAnimationDefinition definition) {
        mRemoteAnimationDefinition = definition;
        if (definition != null) {
            definition.linkToDeath(this::unregisterRemoteAnimations);
        }
    }

    void unregisterRemoteAnimations() {
        mRemoteAnimationDefinition = null;
    }

    RemoteAnimationDefinition getRemoteAnimationDefinition() {
Loading