Merge "Fix potential NPE crash in ConversationHeaderPreferenceController" am: 4378ee11ad am: 1f9c4c483a am: 693ce48efb am: 2d1b325cd0

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/2210776

Change-Id: I8fc0d30dd8338152ce2e9c7dc7741b9543f6dcf3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2022-09-09 16:10:43 +00:00
committed by Automerger Merge Worker
2 changed files with 11 additions and 3 deletions

View File

@@ -126,8 +126,12 @@ public class ConversationHeaderPreferenceController extends NotificationPreferen
@VisibleForTesting
CharSequence getLabel() {
return mConversationInfo != null
? mConversationInfo.getLabel()
: mChannel.getName();
CharSequence label = null;
if (mConversationInfo != null) {
label = mConversationInfo.getLabel();
} else if (mChannel != null) {
label = mChannel.getName();
}
return label;
}
}

View File

@@ -20,6 +20,7 @@ import static android.app.NotificationManager.IMPORTANCE_NONE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
@@ -121,6 +122,9 @@ public class ConversationHeaderPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, null, null, null, null, null);
assertEquals(channel.getName(), mController.getLabel());
mController.onResume(appRow, null, null, null, null, null, null);
assertNull(mController.getLabel());
}
@Test