From dd66917774b5dd03c1f5f54f3601a63083f0a880 Mon Sep 17 00:00:00 2001 From: Beverly Date: Wed, 2 Mar 2022 15:48:10 +0000 Subject: [PATCH] Cleanup KeyguardIndicationController on tearDown In case messages come in on the handler after the KeyguardIndication class is already gone which can cause NPEs. Test: atest SystemUITests Fixes: 222215310 Change-Id: Iafa5379b68994fecdea6540a20522da21af5c788 --- .../systemui/statusbar/KeyguardIndicationController.java | 8 ++++++++ .../statusbar/KeyguardIndicationControllerTest.java | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index ccec0c2d58cc6..16ddb0a7e1a82 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -293,6 +293,14 @@ public class KeyguardIndicationController { } } + /** + * Cleanup + */ + public void destroy() { + mHandler.removeCallbacksAndMessages(null); + mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver); + } + private void handleAlignStateChanged(int alignState) { String alignmentIndication = ""; if (alignState == DockManager.ALIGN_STATE_POOR) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java index 3c1a73eb672e5..ad643fed969ba 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/KeyguardIndicationControllerTest.java @@ -226,6 +226,10 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase { @After public void tearDown() throws Exception { mTextView.setAnimationsEnabled(true); + if (mController != null) { + mController.destroy(); + mController = null; + } } private void createController() {