From d2dc31332a89a6f9eff46f6fc2353e9861cf9607 Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Wed, 13 Oct 2021 16:44:05 +0200 Subject: [PATCH] Ensure that ghosted view is attached when calculating its matrix. This CL ensures that the ghosted view is attached to a ViewGroup before calculating the matrix of that view. It could happen that the view would be detached after the animation was started, which would then crash SysUI when calling GhostView.calculateMatrix. I tested this CL manually by first reproducing this b/202668591 by detaching ghostedView from its parent after the animation started, and then confirmed that this fix prevents the animation from crashing. Test: Manual Bug: 202668591 Fixes: 202668591 Change-Id: I7bf0bedb4860a00f1c44cac9258ff5dc753fb355 --- .../animation/GhostedViewLaunchAnimatorController.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt index f7e0d588407f0..3ccf5e4fbdd0f 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt @@ -209,8 +209,13 @@ open class GhostedViewLaunchAnimatorController( val heightRatio = state.height.toFloat() / ghostedViewState.height val scale = min(widthRatio, heightRatio) + if (ghostedView.parent is ViewGroup) { + // Recalculate the matrix in case the ghosted view moved. We ensure that the ghosted + // view is still attached to a ViewGroup, otherwise calculateMatrix will throw. + GhostView.calculateMatrix(ghostedView, launchContainer, ghostViewMatrix) + } + launchContainer.getLocationOnScreen(launchContainerLocation) - GhostView.calculateMatrix(ghostedView, launchContainer, ghostViewMatrix) ghostViewMatrix.postScale( scale, scale, ghostedViewState.centerX - launchContainerLocation[0],