From 83b263e77eaad82f8445906e44b411ad62c9a811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6llner?= Date: Thu, 3 Mar 2022 10:02:49 +0100 Subject: [PATCH] MediaHiearchyManager: prevent NPE in `updateTargetState()` For some reason, even after adding the checks for -1 in `isCurrentlyInGuidedTransformation()`, there are still times when `startHost` and/or `endHost` can be null, causing a NPE. Fixes: 221754301 Test: N/A Change-Id: I05d02ac7dcd6b0d8a850f9a8bbef8ce6205a8231 --- .../android/systemui/media/MediaHierarchyManager.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt index c6f716ca7ac44..18b6699c80e9f 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt @@ -741,10 +741,11 @@ class MediaHierarchyManager @Inject constructor( * Updates the bounds that the view wants to be in at the end of the animation. */ private fun updateTargetState() { - if (isCurrentlyInGuidedTransformation() && !isCurrentlyFading()) { + var starthost = getHost(previousLocation) + var endHost = getHost(desiredLocation) + if (isCurrentlyInGuidedTransformation() && !isCurrentlyFading() && starthost != null && + endHost != null) { val progress = getTransformationProgress() - var endHost = getHost(desiredLocation)!! - var starthost = getHost(previousLocation)!! // If either of the hosts are invisible, let's keep them at the other host location to // have a nicer disappear animation. Otherwise the currentBounds of the state might // be undefined @@ -756,8 +757,8 @@ class MediaHierarchyManager @Inject constructor( val newBounds = endHost.currentBounds val previousBounds = starthost.currentBounds targetBounds = interpolateBounds(previousBounds, newBounds, progress) - } else { - val bounds = getHost(desiredLocation)?.currentBounds ?: return + } else if (endHost != null) { + val bounds = endHost.currentBounds targetBounds.set(bounds) } }