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

Commit b3305a61 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix OnBackAnimationCallback not receiving updates

`mProgressAnimator` in `WindowOnBackInvokedDispatcher` is static, so we must not reset it when the `WindowOnBackInvokedDispatcher` gets detached, or otherwise we risk interfering animations that belong to another `WindowOnBackInvokedDispatcher`.

Bug: 316016446
Flag: NONE
Test: atest WindowOnBackInvokedDispatcherTest
Test: Manual, i.e. verifying that back animations do not get stuck in the middle of the animation
Change-Id: I4da0179e5e5d02f5ce6fb8af6dc29b31a2101c32
parent 60dc8407
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -226,9 +226,6 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
            setTopOnBackInvokedCallback(null);
        }

        // 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);
        mAllCallbacks.clear();
        mOnBackInvokedCallbacks.clear();
    }
+5 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.window.OnBackInvokedDispatcher.PRIORITY_DEFAULT;
import static android.window.OnBackInvokedDispatcher.PRIORITY_OVERLAY;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.atLeast;
@@ -358,7 +359,7 @@ public class WindowOnBackInvokedDispatcherTest {
    }

    @Test
    public void onDetachFromWindow_cancelCallbackAndIgnoreOnBackInvoked() throws RemoteException {
    public void onDetachFromWindow_cancelsBackAnimation() throws RemoteException {
        mDispatcher.registerOnBackInvokedCallback(PRIORITY_DEFAULT, mCallback1);

        OnBackInvokedCallbackInfo callbackInfo = assertSetCallbackInfo();
@@ -368,13 +369,12 @@ public class WindowOnBackInvokedDispatcherTest {
        waitForIdle();
        verify(mCallback1).onBackStarted(any(BackEvent.class));

        // This should trigger mCallback1.onBackCancelled()
        // This should trigger mCallback1.onBackCancelled() and unset the callback in WM
        mDispatcher.detachFromWindow();
        // This should be ignored by mCallback1
        callbackInfo.getCallback().onBackInvoked();

        OnBackInvokedCallbackInfo callbackInfo1 = assertSetCallbackInfo();
        assertNull(callbackInfo1);
        waitForIdle();
        verify(mCallback1, never()).onBackInvoked();
        verify(mCallback1).onBackCancelled();
    }
}