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

Commit 11ab9bc5 authored by Shan Huang's avatar Shan Huang
Browse files

Make ProgressAnimator non-static.

This way when WindowOnBackInvokedDispatcher gets detached, it does not
risk interferring animations that belong to another
WindowOnBackInvokedDispatcher, according ag/26012753.

Bug: 316016446
Test: m -j
Test: atest OnBackInvokedCallbackGestureTest
Test: atest BackAnimationControllerTest
Test: atest WindowOnBackInvokedDispatcherTest

Change-Id: I2b386936d2fa67ac50ce9748cbb7914591e541bd
parent 4eb8c81d
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -50,6 +50,8 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
    static final int RESULT_CODE_UNREGISTER = 1;
    @NonNull
    private final ResultReceiver mResultReceiver;
    @NonNull
    private final BackProgressAnimator mProgressAnimator = new BackProgressAnimator();

    public ImeOnBackInvokedDispatcher(Handler handler) {
        mResultReceiver = new ResultReceiver(handler) {
@@ -88,7 +90,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
        // cause a memory leak because the app side already clears the reference correctly.
        final IOnBackInvokedCallback iCallback =
                new WindowOnBackInvokedDispatcher.OnBackInvokedCallbackWrapper(
                        callback, false /* useWeakRef */);
                        callback, mProgressAnimator, false /* useWeakRef */);
        bundle.putBinder(RESULT_KEY_CALLBACK, iCallback.asBinder());
        bundle.putInt(RESULT_KEY_PRIORITY, priority);
        bundle.putInt(RESULT_KEY_ID, callback.hashCode());
@@ -179,6 +181,9 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
            }
        }
        mImeCallbacks.clear();
        // We should also stop running animations since all callbacks have been removed.
        // note: mSpring.skipToEnd(), in ProgressAnimator.reset(), requires the main handler.
        Handler.getMain().post(mProgressAnimator::reset);
    }

    static class ImeOnBackInvokedCallback implements OnBackInvokedCallback {
+11 −2
Original line number Diff line number Diff line
@@ -246,7 +246,10 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
                                    .ImeOnBackInvokedCallback
                                ? ((ImeOnBackInvokedDispatcher.ImeOnBackInvokedCallback)
                                        callback).getIOnBackInvokedCallback()
                                : new OnBackInvokedCallbackWrapper(callback, this);
                                : new OnBackInvokedCallbackWrapper(
                                        callback,
                                        mProgressAnimator,
                                        this);
                callbackInfo = new OnBackInvokedCallbackInfo(
                        iCallback,
                        priority,
@@ -272,7 +275,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
    }

    @NonNull
    private static final BackProgressAnimator mProgressAnimator = new BackProgressAnimator();
    private final BackProgressAnimator mProgressAnimator = new BackProgressAnimator();
    private boolean mIsDispatching = false;

    /**
@@ -339,18 +342,24 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
         * forwarded and registered on the app's {@link WindowOnBackInvokedDispatcher}. */
        @Nullable
        private final WindowOnBackInvokedDispatcher mDispatcher;
        @NonNull
        private final BackProgressAnimator mProgressAnimator;

        OnBackInvokedCallbackWrapper(
                @NonNull OnBackInvokedCallback callback,
                @NonNull BackProgressAnimator progressAnimator,
                WindowOnBackInvokedDispatcher dispatcher) {
            mCallbackRef = new CallbackRef(callback, true /* useWeakRef */);
            mProgressAnimator = progressAnimator;
            mDispatcher = dispatcher;
        }

        OnBackInvokedCallbackWrapper(
                @NonNull OnBackInvokedCallback callback,
                @NonNull BackProgressAnimator progressAnimator,
                boolean useWeakRef) {
            mCallbackRef = new CallbackRef(callback, useWeakRef);
            mProgressAnimator = progressAnimator;
            mDispatcher = null;
        }