From ec8ac6ba2e80fbc3c04d260c106ec58a16cc3c56 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Tue, 11 Feb 2020 16:00:13 -0800 Subject: [PATCH] InsetsAnimation: Fix crash if disabling decor fitting before view is attached Bug: 149341851 Test: atest WindowTest Change-Id: I6a688c493e79c0e95037dcc690c92fb33049dc95 --- .../android/internal/policy/PhoneWindow.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/java/com/android/internal/policy/PhoneWindow.java b/core/java/com/android/internal/policy/PhoneWindow.java index 46d7f4ec4c85f..775368ba3c186 100644 --- a/core/java/com/android/internal/policy/PhoneWindow.java +++ b/core/java/com/android/internal/policy/PhoneWindow.java @@ -1821,15 +1821,20 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } private ViewRootImpl getViewRootImpl() { - if (mDecor != null) { - ViewRootImpl viewRootImpl = mDecor.getViewRootImpl(); - if (viewRootImpl != null) { - return viewRootImpl; - } + ViewRootImpl viewRootImpl = getViewRootImplOrNull(); + if (viewRootImpl != null) { + return viewRootImpl; } throw new IllegalStateException("view not added"); } + private ViewRootImpl getViewRootImplOrNull() { + if (mDecor == null) { + return null; + } + return mDecor.getViewRootImpl(); + } + /** * Request that key events come to this activity. Use this if your activity * has no views with focus, but the activity still wants a chance to process @@ -3900,7 +3905,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { @Override public void setDecorFitsSystemWindows(boolean decorFitsSystemWindows) { - ViewRootImpl impl = getViewRootImpl(); + ViewRootImpl impl = getViewRootImplOrNull(); OnContentApplyWindowInsetsListener listener = decorFitsSystemWindows ? createDefaultContentWindowInsetsListener() : null;