From 7794a00407e6634fbfa09a5e8d36908440ca7c66 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 29 Apr 2020 17:13:57 +0200 Subject: [PATCH] WindowInsetsController: make available after addView Fixes an issue where the WindowInsetsController was only available after the first traversal. Bug: 155280356 Test: atest WindowInsetsControllerTests Change-Id: I225efcaa31e97da9e8ebc6bd7d24c433c8e80826 --- core/java/android/view/View.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index f98c1f660cfa0..310299910e960 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -11519,6 +11519,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, ViewParent parent = getParent(); if (parent instanceof View) { return ((View) parent).getWindowInsetsController(); + } else if (parent instanceof ViewRootImpl) { + // Between WindowManager.addView() and the first traversal AttachInfo isn't set yet. + return ((ViewRootImpl) parent).getInsetsController(); } return null; }