From 50be0fb14e8ce79d8aa8eec061fb03cc77674f38 Mon Sep 17 00:00:00 2001 From: Alex Florescu Date: Thu, 3 Jun 2021 09:47:19 +0100 Subject: [PATCH] Prevent crash when switching displays with screen off Bug: 189942712 Test: manual Change-Id: I0f3fd02f284e1d7509eb6f12cf8b87de9304e2a1 --- .../com/android/systemui/navigationbar/NavigationBar.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java index d8b342a6a8d81..dda1029f61545 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/NavigationBar.java @@ -1585,6 +1585,13 @@ public class NavigationBar implements View.OnAttachStateChangeListener, private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { + // This receiver is unregistered when the view is detached, but on devices with multiple + // displays, it can sometimes still receive an ACTION_SCREEN_ON/ACTION_SCREEN_OFF on + // display switch, after it was detached, so this null check ensures no crash in that + // scenario. + if (mNavigationBarView == null) { + return; + } String action = intent.getAction(); if (Intent.ACTION_SCREEN_OFF.equals(action) || Intent.ACTION_SCREEN_ON.equals(action)) {