summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Johannes Gallmann <gallmann@google.com> 2024-02-06 12:34:48 +0000
committer Johannes Gallmann <gallmann@google.com> 2024-02-09 11:07:13 +0000
commit8078ff7a98eb87e5eccab0c19e438d6ac0581bc5 (patch)
treee1b0555a36de692e1a892f86620236f72480ff80 /libs
parent90b68205ba712799e89dba6efd3a7c845fcda6cb (diff)
Fix back callback ordering for quick back gestures in succession
Bug: 324036420 Flag: Flag: ACONFIG com.android.systemui.predictive_back_system_animations TEAMFOOD Test: atest BackProgressAnimatorTest Test: Manual, i.e. verifying that starting a back gesture quickly after another one is cancelled doesn't invoke callback functions in wrong order Change-Id: Ie5ebef743f8de07032b304f8a89dff03f318426a
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackProgressAnimatorTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackProgressAnimatorTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackProgressAnimatorTest.java
index 91503b1c3619..7e26577e96d4 100644
--- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackProgressAnimatorTest.java
+++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/back/BackProgressAnimatorTest.java
@@ -18,6 +18,7 @@ package com.android.wm.shell.back;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import android.os.Handler;
import android.os.Looper;
@@ -28,6 +29,7 @@ import android.window.BackMotionEvent;
import android.window.BackProgressAnimator;
import androidx.test.filters.SmallTest;
+import androidx.test.platform.app.InstrumentationRegistry;
import org.junit.Before;
import org.junit.Test;
@@ -102,6 +104,36 @@ public class BackProgressAnimatorTest {
assertEquals(mReceivedBackEvent.getProgress(), mTargetProgress, 0 /* delta */);
}
+ @Test
+ public void testResetCallsCancelCallbackImmediately() throws InterruptedException {
+ // Give the animator some progress.
+ final BackMotionEvent backEvent = backMotionEventFrom(100, mTargetProgress);
+ mMainThreadHandler.post(
+ () -> mProgressAnimator.onBackProgressed(backEvent));
+ mTargetProgressCalled.await(1, TimeUnit.SECONDS);
+ assertNotNull(mReceivedBackEvent);
+
+ mTargetProgress = 0;
+ mReceivedBackEvent = null;
+ mTargetProgressCalled = new CountDownLatch(1);
+
+ CountDownLatch cancelCallbackCalled = new CountDownLatch(1);
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(
+ () -> mProgressAnimator.onBackCancelled(cancelCallbackCalled::countDown));
+
+ // verify onBackProgressed and onBackCancelled not yet called
+ assertNull(mReceivedBackEvent);
+ assertEquals(1, cancelCallbackCalled.getCount());
+
+ // call reset
+ InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> mProgressAnimator.reset());
+
+ // verify that back event with progress 0 is sent and cancel callback is invoked
+ assertNotNull(mReceivedBackEvent);
+ assertEquals(mReceivedBackEvent.getProgress(), mTargetProgress, 0 /* delta */);
+ assertEquals(0, cancelCallbackCalled.getCount());
+ }
+
private void onGestureProgress(BackEvent backEvent) {
if (mTargetProgress == backEvent.getProgress()) {
mReceivedBackEvent = backEvent;