From d58b65cd31531445dd2dd53ae3135a9a85149d8f Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Wed, 18 Apr 2018 15:00:45 -0700 Subject: [PATCH] Don't crash during layout of non-attached but focused view Verifies that there is a viewrootimpl before calling its methods. Bug: 77193567 Test: N/A Change-Id: I301c3aede3d0f7e1d2abf6fe5bb3d852f697577b --- core/java/android/view/View.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 71b60844b17dd..6b16d42ac7ef8 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -20700,7 +20700,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, if (canTakeFocus()) { // We have a robust focus, so parents should no longer be wanting focus. clearParentsWantFocus(); - } else if (!getViewRootImpl().isInLayout()) { + } else if (getViewRootImpl() == null || !getViewRootImpl().isInLayout()) { // This is a weird case. Most-likely the user, rather than ViewRootImpl, called // layout. In this case, there's no guarantee that parent layouts will be evaluated // and thus the safest action is to clear focus here.