Fix potential NPE crash in ConversationHeaderPreferenceController

mChannel is nullable and we have to do a null-check before calling its method.

Bug: 245506600

Test: manual and atest
Change-Id: Ib739f0f66f1a2aee1b2741263e7c206341782892
This commit is contained in:
Shen Lin
2022-09-08 11:50:33 +08:00
parent 6672e37864
commit 78fc8a21a4
2 changed files with 11 additions and 3 deletions

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