From 8c8dbdef5f3ce20bdb335fcda9b5c6687d24d833 Mon Sep 17 00:00:00 2001 From: Geoffrey Pitsch Date: Thu, 20 Apr 2017 11:44:33 -0400 Subject: [PATCH] Further bulletproof NotificationInfo's public api from exceptions Change-Id: Iae33e416afdaf29e932a4b1486a3902e0135d8e7 Fixes: 36568713 Test: runtest systemui --- .../android/systemui/statusbar/NotificationInfo.java | 10 ++++------ .../systemui/statusbar/NotificationInfoTest.java | 5 +++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java index 89251897e25f9..8aec4f9a98280 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java @@ -262,17 +262,15 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G private boolean hasImportanceChanged() { return mSingleNotificationChannel != null && + mChannelEnabledSwitch != null && mStartingUserImportance != getSelectedImportance(); } private void saveImportance() { - if (mSingleNotificationChannel == null) { - return; - } - int selectedImportance = getSelectedImportance(); - if (selectedImportance == mStartingUserImportance) { + if (!hasImportanceChanged()) { return; } + final int selectedImportance = getSelectedImportance(); MetricsLogger.action(mContext, MetricsEvent.ACTION_SAVE_IMPORTANCE, selectedImportance - mStartingUserImportance); mSingleNotificationChannel.setImportance(selectedImportance); @@ -384,7 +382,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G @Override public boolean willBeRemoved() { - return !mChannelEnabledSwitch.isChecked(); + return mChannelEnabledSwitch != null && !mChannelEnabledSwitch.isChecked(); } @Override diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java index 66385a1dfb01e..55bfc07630b8c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java @@ -780,4 +780,9 @@ public class NotificationInfoTest extends SysuiTestCase { enabledSwitch.setChecked(true); assertEquals(View.VISIBLE, settingsLink.getVisibility()); } + + @Test + public void testWillBeRemovedReturnsFalseBeforeBind() throws Exception { + assertFalse(mNotificationInfo.willBeRemoved()); + } }