diff options
| author | 2022-12-01 18:02:14 +0100 | |
|---|---|---|
| committer | 2022-12-01 18:08:36 +0100 | |
| commit | 31da217d0651d1d28ee362ef25cd6af128d94a56 (patch) | |
| tree | f22acba044701bc760d3b20a3298e815a01afeb5 | |
| parent | 7ab95c84705fe29a8cd84394efbf9ac66b8c794a (diff) | |
Fix NPE in DialogLaunchAnimator
This CL fixes a NPE happening in DialogLaunchAnimator if it tried to
synchronize the 2 view roots at the start/end of the animation and that
the view that triggered the animation was detached from the hierarchy.
This regression was caused by the refactoring in http://ag/20139844.
Bug: 256194999
Test: Manual
Change-Id: Id264ddfa6365bfdc952d512c2c182b6cbf4906e4
3 files changed, 9 insertions, 7 deletions
diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt index fdfad2bc2fa1..54aa3516d867 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt @@ -75,7 +75,7 @@ constructor( */ interface Controller { /** The [ViewRootImpl] of this controller. */ - val viewRoot: ViewRootImpl + val viewRoot: ViewRootImpl? /** * The identity object of the source animated by this controller. This animator will ensure @@ -807,15 +807,17 @@ private class AnimatedDialog( * inversely, removed from the overlay when the source is moved back to its original position). */ private fun synchronizeNextDraw(then: () -> Unit) { - if (forceDisableSynchronization) { - // Don't synchronize when inside an automated test. + val controllerRootView = controller.viewRoot?.view + if (forceDisableSynchronization || controllerRootView == null) { + // Don't synchronize when inside an automated test or if the controller root view is + // detached. then() return } - ViewRootSync.synchronizeNextDraw(controller.viewRoot.view, decorView, then) + ViewRootSync.synchronizeNextDraw(controllerRootView, decorView, then) decorView.invalidate() - controller.viewRoot.view.invalidate() + controllerRootView.invalidate() } private fun findFirstViewGroupWithBackground(view: View): ViewGroup? { diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/ViewDialogLaunchAnimatorController.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/ViewDialogLaunchAnimatorController.kt index ecee598afe4e..964ef8c88098 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/ViewDialogLaunchAnimatorController.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/ViewDialogLaunchAnimatorController.kt @@ -28,7 +28,7 @@ internal constructor( private val source: View, override val cuj: DialogCuj?, ) : DialogLaunchAnimator.Controller { - override val viewRoot: ViewRootImpl + override val viewRoot: ViewRootImpl? get() = source.viewRootImpl override val sourceIdentity: Any = source diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ExpandableController.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ExpandableController.kt index 50c3d7e1e76b..d6db574a34ae 100644 --- a/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ExpandableController.kt +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/animation/ExpandableController.kt @@ -262,7 +262,7 @@ internal class ExpandableControllerImpl( private fun dialogController(cuj: DialogCuj?): DialogLaunchAnimator.Controller { return object : DialogLaunchAnimator.Controller { - override val viewRoot: ViewRootImpl = composeViewRoot.viewRootImpl + override val viewRoot: ViewRootImpl? = composeViewRoot.viewRootImpl override val sourceIdentity: Any = this@ExpandableControllerImpl override val cuj: DialogCuj? = cuj |