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

Commit fd770562 authored by Ebru Kurnaz's avatar Ebru Kurnaz
Browse files

Notes QS Tile: Do nothing on click if there is an expanded bubble.

Test: Build
Bug: 357863750
Flag: com.android.systemui.notes_role_qs_tile
Change-Id: Idd4ee9dd115d79cf26723580dc643081428b1df9
parent 9893f104
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context
import android.content.Intent
import android.graphics.drawable.Icon
import android.os.UserHandle
import com.android.wm.shell.bubbles.Bubble
import com.android.wm.shell.bubbles.Bubbles
import java.util.Optional
import kotlinx.coroutines.CoroutineDispatcher
@@ -33,14 +34,29 @@ import kotlinx.coroutines.CoroutineDispatcher
class FakeNoteTaskBubbleController(
    unUsed1: Context,
    unsUsed2: CoroutineDispatcher,
    private val optionalBubbles: Optional<Bubbles>
    private val optionalBubbles: Optional<Bubbles>,
) : NoteTaskBubblesController(unUsed1, unsUsed2) {
    override suspend fun areBubblesAvailable() = optionalBubbles.isPresent

    override suspend fun showOrHideAppBubble(intent: Intent, userHandle: UserHandle, icon: Icon) {
    override suspend fun showOrHideAppBubble(
        intent: Intent,
        userHandle: UserHandle,
        icon: Icon,
        bubbleExpandBehavior: NoteTaskBubbleExpandBehavior,
    ) {
        optionalBubbles.ifPresentOrElse(
            { bubbles -> bubbles.showOrHideAppBubble(intent, userHandle, icon) },
            { throw IllegalAccessException() }
            { bubbles ->
                if (
                    bubbleExpandBehavior == NoteTaskBubbleExpandBehavior.KEEP_IF_EXPANDED &&
                        bubbles.isBubbleExpanded(
                            Bubble.getAppBubbleKeyForApp(intent.`package`, userHandle)
                        )
                ) {
                    return@ifPresentOrElse
                }
                bubbles.showOrHideAppBubble(intent, userHandle, icon)
            },
            { throw IllegalAccessException() },
        )
    }
}
+34 −3
Original line number Diff line number Diff line
@@ -21,9 +21,9 @@ import android.graphics.drawable.Icon
import android.os.UserHandle
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.res.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.notetask.NoteTaskBubblesController.NoteTaskBubblesService
import com.android.systemui.res.R
import com.android.wm.shell.bubbles.Bubbles
import com.google.common.truth.Truth.assertThat
import java.util.Optional
@@ -33,6 +33,9 @@ import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.never
import org.mockito.kotlin.whenever

/** atest SystemUITests:NoteTaskBubblesServiceTest */
@SmallTest
@@ -61,12 +64,40 @@ internal class NoteTaskBubblesServiceTest : SysuiTestCase() {
    }

    @Test
    fun showOrHideAppBubble() {
    fun showOrHideAppBubble_defaultExpandBehavior_shouldCallBubblesApi() {
        val intent = Intent()
        val user = UserHandle.SYSTEM
        val icon = Icon.createWithResource(context, R.drawable.ic_note_task_shortcut_widget)
        val bubbleExpandBehavior = NoteTaskBubbleExpandBehavior.DEFAULT
        whenever(bubbles.isBubbleExpanded(any())).thenReturn(false)

        createServiceBinder().showOrHideAppBubble(intent, user, icon, bubbleExpandBehavior)

        verify(bubbles).showOrHideAppBubble(intent, user, icon)
    }

    @Test
    fun showOrHideAppBubble_keepIfExpanded_bubbleShown_shouldNotCallBubblesApi() {
        val intent = Intent().apply { setPackage("test") }
        val user = UserHandle.SYSTEM
        val icon = Icon.createWithResource(context, R.drawable.ic_note_task_shortcut_widget)
        val bubbleExpandBehavior = NoteTaskBubbleExpandBehavior.KEEP_IF_EXPANDED
        whenever(bubbles.isBubbleExpanded(any())).thenReturn(true)

        createServiceBinder().showOrHideAppBubble(intent, user, icon, bubbleExpandBehavior)

        verify(bubbles, never()).showOrHideAppBubble(intent, user, icon)
    }

    @Test
    fun showOrHideAppBubble_keepIfExpanded_bubbleNotShown_shouldCallBubblesApi() {
        val intent = Intent().apply { setPackage("test") }
        val user = UserHandle.SYSTEM
        val icon = Icon.createWithResource(context, R.drawable.ic_note_task_shortcut_widget)
        val bubbleExpandBehavior = NoteTaskBubbleExpandBehavior.KEEP_IF_EXPANDED
        whenever(bubbles.isBubbleExpanded(any())).thenReturn(false)

        createServiceBinder().showOrHideAppBubble(intent, user, icon)
        createServiceBinder().showOrHideAppBubble(intent, user, icon, bubbleExpandBehavior)

        verify(bubbles).showOrHideAppBubble(intent, user, icon)
    }
+12 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import android.os.UserHandle
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.notetask.NoteTaskEntryPoint.QS_NOTES_TILE
import com.android.systemui.notetask.NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT_IN_MULTI_WINDOW_MODE
import com.google.common.truth.Truth.assertThat
import org.junit.Test
@@ -44,10 +45,19 @@ internal class NoteTaskInfoTest : SysuiTestCase() {
    }

    @Test
    fun launchMode_keyguardUnlocked_launchModeAppBubble() {
    fun launchMode_keyguardUnlocked_launchModeAppBubble_withDefaultExpandBehavior() {
        val underTest = DEFAULT_INFO.copy(isKeyguardLocked = false)

        assertThat(underTest.launchMode).isEqualTo(NoteTaskLaunchMode.AppBubble)
        assertThat(underTest.launchMode)
            .isEqualTo(NoteTaskLaunchMode.AppBubble(NoteTaskBubbleExpandBehavior.DEFAULT))
    }

    @Test
    fun launchMode_keyguardUnlocked_qsTileEntryPoint_launchModeAppBubble_withKeepIfExpandedExpandBehavior() {
        val underTest = DEFAULT_INFO.copy(isKeyguardLocked = false, entryPoint = QS_NOTES_TILE)

        assertThat(underTest.launchMode)
            .isEqualTo(NoteTaskLaunchMode.AppBubble(NoteTaskBubbleExpandBehavior.KEEP_IF_EXPANDED))
    }

    private companion object {
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.notetask;

import com.android.systemui.notetask.NoteTaskBubbleExpandBehavior;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.os.UserHandle;
@@ -25,5 +26,6 @@ interface INoteTaskBubblesService {

    boolean areBubblesAvailable();

    void showOrHideAppBubble(in Intent intent, in UserHandle userHandle, in Icon icon);
    void showOrHideAppBubble(in Intent intent, in UserHandle userHandle, in Icon icon,
     in NoteTaskBubbleExpandBehavior bubbleExpandBehavior);
}
+3 −0
Original line number Diff line number Diff line
package com.android.systemui.notetask;

parcelable NoteTaskBubbleExpandBehavior;
 No newline at end of file
Loading