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

Commit 28376cc4 authored by yyalan's avatar yyalan
Browse files

Fix notification HSUM bug

notify() uses mContext.getUser() which should be avoided. Using notifyAsUser fixes the issue.

Bug: 375175345
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Test: notification is visible
Change-Id: I78795bc0ca761c773f06c08e2d6b57648b98cce4
parent f76196eb
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.systemui.keyboard.data.repository.FakeKeyboardRepository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
import com.android.systemui.settings.userTracker
import com.android.systemui.touchpad.data.repository.FakeTouchpadRepository
import com.google.common.truth.Truth.assertThat
import kotlin.time.Duration.Companion.hours
@@ -91,6 +92,7 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() {
                context,
                interactor,
                notificationManager,
                kosmos.userTracker,
            )
        notificationCaptor = ArgumentCaptor.forClass(Notification::class.java)
        underTest.start()
@@ -140,12 +142,13 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() {
    fun doNotShowNotification() =
        testScope.runTest {
            advanceTimeBy(LAUNCH_DELAY)
            verify(notificationManager, never()).notify(eq(TAG), eq(NOTIFICATION_ID), any())
            verify(notificationManager, never())
                .notifyAsUser(eq(TAG), eq(NOTIFICATION_ID), any(), any())
        }

    private fun verifyNotification(@StringRes titleResId: Int, @StringRes contentResId: Int) {
        verify(notificationManager)
            .notify(eq(TAG), eq(NOTIFICATION_ID), notificationCaptor.capture())
            .notifyAsUser(eq(TAG), eq(NOTIFICATION_ID), notificationCaptor.capture(), any())
        val notification = notificationCaptor.value
        val actualTitle = notification.getString(Notification.EXTRA_TITLE)
        val actualContent = notification.getString(Notification.EXTRA_TEXT)
+3 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutoria
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEYBOARD
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_TOUCHPAD
import com.android.systemui.res.R
import com.android.systemui.settings.UserTracker
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
@@ -51,6 +52,7 @@ constructor(
    @Application private val context: Context,
    private val tutorialSchedulerInteractor: TutorialSchedulerInteractor,
    private val notificationManager: NotificationManager,
    private val userTracker: UserTracker,
) {
    fun start() {
        backgroundScope.launch {
@@ -85,7 +87,7 @@ constructor(
                .addExtras(extras)
                .build()

        notificationManager.notify(TAG, NOTIFICATION_ID, notification)
        notificationManager.notifyAsUser(TAG, NOTIFICATION_ID, notification, userTracker.userHandle)
    }

    private fun createNotificationChannel() {