From e4f2b2c015eb73e149753f2fd08389a1ae8a7754 Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Thu, 2 Jun 2022 14:27:42 +0800 Subject: [PATCH] Preventing NPE crash if view is detached from window. View#getDisplay can return null if the view is detached from window. Get the display by Context#getDisplay should ensure there can always return the local display object. Bug: 209920544 Test: enable shell transition, repeatly run AppConfigurationTests testConfigurationUpdatesWhenRotatingWhileFullscreen and verify no crash in system ui. Change-Id: I792417a55a588c9552529f2815c1ab5d88f427e7 --- .../src/com/android/systemui/DisplayCutoutBaseView.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt b/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt index 8ab1ab79355fd..34164f3b7306a 100644 --- a/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt +++ b/packages/SystemUI/src/com/android/systemui/DisplayCutoutBaseView.kt @@ -87,20 +87,21 @@ open class DisplayCutoutBaseView : View, RegionInterceptableView { fun onDisplayChanged(displayId: Int) { val oldMode: Display.Mode? = displayMode - displayMode = display.mode + val display: Display? = context.display + displayMode = display?.mode - if (displayUniqueId != context.display?.uniqueId) { - displayUniqueId = context.display?.uniqueId + if (displayUniqueId != display?.uniqueId) { + displayUniqueId = display?.uniqueId shouldDrawCutout = DisplayCutout.getFillBuiltInDisplayCutout( context.resources, displayUniqueId) } // Skip if display mode or cutout hasn't changed. if (!displayModeChanged(oldMode, displayMode) && - display.cutout == displayInfo.displayCutout) { + display?.cutout == displayInfo.displayCutout) { return } - if (displayId == display.displayId) { + if (displayId == display?.displayId) { updateCutout() updateProtectionBoundingPath() onUpdate()