From 28a24306b306dd7df247004d67921e64eb564bb3 Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Wed, 11 May 2022 12:00:04 -0700 Subject: [PATCH] Fix jank when launching the All set page on devices that support vibrations Moving haptics from the all set page background animation to the UI helper thread to reduce jank when launching the all set page from SUW. Bug: 195711508 Test: manual with pixel 6 pro Change-Id: Icca17a79161f177e3549dd780bfe9b78aa59fe51 --- .../quickstep/interaction/AllSetActivity.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java index db19c452a7..269b3c2268 100644 --- a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java +++ b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java @@ -54,6 +54,7 @@ import androidx.core.graphics.ColorUtils; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.util.Executors; import com.android.quickstep.AnimatedFloat; import com.android.quickstep.GestureState; import com.android.quickstep.TouchInteractionService.TISBinder; @@ -136,6 +137,10 @@ public class AllSetActivity extends Activity { startBackgroundAnimation(); } + private void runOnUiHelperThread(Runnable runnable) { + Executors.UI_HELPER_EXECUTOR.execute(runnable); + } + private void startBackgroundAnimation() { if (Utilities.ATLEAST_S && mVibrator != null && mVibrator.areAllPrimitivesSupported( VibrationEffect.Composition.PRIMITIVE_THUD)) { @@ -144,22 +149,22 @@ public class AllSetActivity extends Activity { new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { - mVibrator.vibrate(getVibrationEffect()); + runOnUiHelperThread(() -> mVibrator.vibrate(getVibrationEffect())); } @Override public void onAnimationRepeat(Animator animation) { - mVibrator.vibrate(getVibrationEffect()); + runOnUiHelperThread(() -> mVibrator.vibrate(getVibrationEffect())); } @Override public void onAnimationEnd(Animator animation) { - mVibrator.cancel(); + runOnUiHelperThread(mVibrator::cancel); } @Override public void onAnimationCancel(Animator animation) { - mVibrator.cancel(); + runOnUiHelperThread(mVibrator::cancel); } }; }