Handle null OnSettingsClickListeners in ChannelDialogEditorController

The property was already nullable, but prepareDialogForApp() didn't
accept a null click listener.

Test: atest ChannelDialogEditorControllerTest
Fixes: 134697988
Change-Id: I08c5006ac5519f2baa0df1a5ad29d6802c63fb3c
This commit is contained in:
Evan Laird
2019-06-07 16:12:06 -04:00
parent 03cf35018a
commit 0e5378e613
2 changed files with 19 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.ColorDrawable
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.view.Window
@@ -96,7 +97,7 @@ class ChannelEditorDialogController @Inject constructor(
uid: Int,
channels: Set<NotificationChannel>,
appIcon: Drawable,
onSettingsClickListener: NotificationInfo.OnSettingsClickListener
onSettingsClickListener: NotificationInfo.OnSettingsClickListener?
) {
this.appName = appName
this.packageName = packageName
@@ -246,6 +247,11 @@ class ChannelEditorDialogController @Inject constructor(
}
}
@VisibleForTesting
fun launchSettings(sender: View) {
onSettingsClickListener?.onClick(sender, null, appUid!!)
}
private fun initDialog() {
dialog = Dialog(context)
@@ -268,7 +274,7 @@ class ChannelEditorDialogController @Inject constructor(
}
findViewById<TextView>(R.id.see_more_button)?.setOnClickListener {
onSettingsClickListener?.onClick(it, null, appUid!!)
launchSettings(it)
done()
}

View File

@@ -109,7 +109,7 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() {
}
@Test
fun testPrepareDialogForApp_retrievesUpto4Channels() {
fun testPrepareDialogForApp_retrievesUpTo4Channels() {
val channel3 = NotificationChannel("test_channel_3", "Test channel 3", IMPORTANCE_DEFAULT)
val channel4 = NotificationChannel("test_channel_4", "Test channel 4", IMPORTANCE_DEFAULT)
@@ -169,6 +169,16 @@ class ChannelEditorDialogControllerTest : SysuiTestCase() {
eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(true))
}
@Test
fun testSettingsClickListenerNull_noCrash() {
group.channels = listOf(channel1, channel2)
controller.prepareDialogForApp(TEST_APP_NAME, TEST_PACKAGE_NAME, TEST_UID,
setOf(channel1, channel2), appIcon, null)
// Pass in any old view, it should never actually be used
controller.launchSettings(View(context))
}
private val clickListener = object : NotificationInfo.OnSettingsClickListener {
override fun onClick(v: View, c: NotificationChannel, appUid: Int) {
}