Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e5378e6 authored by Evan Laird's avatar Evan Laird
Browse files

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
parent 03cf3501
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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()
            }

+11 −1
Original line number Diff line number Diff line
@@ -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) {
        }