diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt index b295f6659f81b..d5965ec8fbfcd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt @@ -85,7 +85,7 @@ class OngoingCallController @Inject constructor( val newOngoingCallInfo = CallNotificationInfo( entry.sbn.key, entry.sbn.notification.`when`, - entry.sbn.notification.contentIntent.intent, + entry.sbn.notification.contentIntent?.intent, entry.sbn.uid, entry.sbn.notification.extras.getInt( Notification.EXTRA_CALL_TYPE, -1) == CALL_TYPE_ONGOING @@ -176,14 +176,17 @@ class OngoingCallController @Inject constructor( systemClock.elapsedRealtime() timeView.start() - currentChipView.setOnClickListener { - logger.logChipClicked() - activityStarter.postStartActivityDismissingKeyguard( - currentCallNotificationInfo.intent, 0, - ActivityLaunchAnimator.Controller.fromView( - backgroundView, - InteractionJankMonitor.CUJ_STATUS_BAR_APP_LAUNCH_FROM_CALL_CHIP) - ) + currentCallNotificationInfo.intent?.let { intent -> + currentChipView.setOnClickListener { + logger.logChipClicked() + activityStarter.postStartActivityDismissingKeyguard( + intent, + 0, + ActivityLaunchAnimator.Controller.fromView( + backgroundView, + InteractionJankMonitor.CUJ_STATUS_BAR_APP_LAUNCH_FROM_CALL_CHIP) + ) + } } setUpUidObserver(currentCallNotificationInfo) @@ -254,7 +257,7 @@ class OngoingCallController @Inject constructor( private data class CallNotificationInfo( val key: String, val callStartTime: Long, - val intent: Intent, + val intent: Intent?, val uid: Int, /** True if the call is currently ongoing (as opposed to incoming, screening, etc.). */ val isOngoing: Boolean diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt index ca3cff98b78ce..94c9de0d20359 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt @@ -40,23 +40,23 @@ import com.android.systemui.statusbar.notification.collection.NotificationEntryB import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener import com.android.systemui.util.concurrency.FakeExecutor -import com.android.systemui.util.time.FakeSystemClock import com.android.systemui.util.mockito.any +import com.android.systemui.util.time.FakeSystemClock import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor -import org.mockito.ArgumentMatchers.* +import org.mockito.ArgumentMatchers.anyBoolean +import org.mockito.ArgumentMatchers.nullable import org.mockito.Mock import org.mockito.Mockito.`when` import org.mockito.Mockito.eq import org.mockito.Mockito.mock import org.mockito.Mockito.never +import org.mockito.Mockito.reset import org.mockito.Mockito.times import org.mockito.Mockito.verify -import org.mockito.Mockito.reset - import org.mockito.MockitoAnnotations private const val CALL_UID = 900 @@ -140,6 +140,13 @@ class OngoingCallControllerTest : SysuiTestCase() { .onOngoingCallStateChanged(anyBoolean()) } + /** Regression test for b/191472854. */ + @Test + fun onEntryUpdated_notifHasNullContentIntent_noCrash() { + notifCollectionListener.onEntryUpdated( + createCallNotifEntry(ongoingCallStyle, nullContentIntent = true)) + } + /** * If a call notification is never added before #onEntryRemoved is called, then the listener * should never be notified. @@ -357,14 +364,22 @@ class OngoingCallControllerTest : SysuiTestCase() { private fun createScreeningCallNotifEntry() = createCallNotifEntry(screeningCallStyle) - private fun createCallNotifEntry(callStyle: Notification.CallStyle): NotificationEntry { + private fun createCallNotifEntry( + callStyle: Notification.CallStyle, + nullContentIntent: Boolean = false + ): NotificationEntry { val notificationEntryBuilder = NotificationEntryBuilder() notificationEntryBuilder.modifyNotification(context).style = callStyle - - val contentIntent = mock(PendingIntent::class.java) - `when`(contentIntent.intent).thenReturn(mock(Intent::class.java)) - notificationEntryBuilder.modifyNotification(context).setContentIntent(contentIntent) notificationEntryBuilder.setUid(CALL_UID) + + if (nullContentIntent) { + notificationEntryBuilder.modifyNotification(context).setContentIntent(null) + } else { + val contentIntent = mock(PendingIntent::class.java) + `when`(contentIntent.intent).thenReturn(mock(Intent::class.java)) + notificationEntryBuilder.modifyNotification(context).setContentIntent(contentIntent) + } + return notificationEntryBuilder.build() }