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

Commit 16740e74 authored by Steven Ng's avatar Steven Ng Committed by Automerger Merge Worker
Browse files

Merge "Add an overloading function for starting notes app on another user"...

Merge "Add an overloading function for starting notes app on another user" into udc-dev am: 8e9d00cd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22071924



Change-Id: If33723211ca8b5e910d14c40c917ca05f5cc4cf0
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents a13f8862 8e9d00cd
Loading
Loading
Loading
Loading
+12 −3
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.pm.PackageManager
import android.content.pm.PackageManager
import android.os.Build
import android.os.Build
import android.os.UserHandle
import android.os.UserManager
import android.os.UserManager
import android.util.Log
import android.util.Log
import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting
@@ -99,6 +100,14 @@ constructor(
     */
     */
    fun showNoteTask(
    fun showNoteTask(
        entryPoint: NoteTaskEntryPoint,
        entryPoint: NoteTaskEntryPoint,
    ) {
        showNoteTaskAsUser(entryPoint, userTracker.userHandle)
    }

    /** A variant of [showNoteTask] which launches note task in the given [user]. */
    fun showNoteTaskAsUser(
        entryPoint: NoteTaskEntryPoint,
        user: UserHandle,
    ) {
    ) {
        if (!isEnabled) return
        if (!isEnabled) return


@@ -113,7 +122,7 @@ constructor(
        // note task when the screen is locked.
        // note task when the screen is locked.
        if (
        if (
            isKeyguardLocked &&
            isKeyguardLocked &&
                devicePolicyManager.areKeyguardShortcutsDisabled(userId = userTracker.userId)
                devicePolicyManager.areKeyguardShortcutsDisabled(userId = user.identifier)
        ) {
        ) {
            logDebug { "Enterprise policy disallows launching note app when the screen is locked." }
            logDebug { "Enterprise policy disallows launching note app when the screen is locked." }
            return
            return
@@ -126,7 +135,7 @@ constructor(
        // TODO(b/266686199): We should handle when app not available. For now, we log.
        // TODO(b/266686199): We should handle when app not available. For now, we log.
        val intent = createNoteIntent(info)
        val intent = createNoteIntent(info)
        try {
        try {
            logDebug { "onShowNoteTask - start: $info" }
            logDebug { "onShowNoteTask - start: $info on user#${user.identifier}" }
            when (info.launchMode) {
            when (info.launchMode) {
                is NoteTaskLaunchMode.AppBubble -> {
                is NoteTaskLaunchMode.AppBubble -> {
                    bubbles.showOrHideAppBubble(intent, userTracker.userHandle)
                    bubbles.showOrHideAppBubble(intent, userTracker.userHandle)
@@ -134,7 +143,7 @@ constructor(
                    logDebug { "onShowNoteTask - opened as app bubble: $info" }
                    logDebug { "onShowNoteTask - opened as app bubble: $info" }
                }
                }
                is NoteTaskLaunchMode.Activity -> {
                is NoteTaskLaunchMode.Activity -> {
                    context.startActivityAsUser(intent, userTracker.userHandle)
                    context.startActivityAsUser(intent, user)
                    eventLogger.logNoteTaskOpened(info)
                    eventLogger.logNoteTaskOpened(info)
                    logDebug { "onShowNoteTask - opened as activity: $info" }
                    logDebug { "onShowNoteTask - opened as activity: $info" }
                }
                }
+35 −0
Original line number Original line Diff line number Diff line
@@ -215,6 +215,41 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
        verifyZeroInteractions(bubbles)
        verifyZeroInteractions(bubbles)
    }
    }


    @Test
    fun showNoteTaskWithUser_keyguardIsLocked_shouldStartActivityWithExpectedUserAndLogUiEvent() {
        val user10 = UserHandle.of(/* userId= */ 10)
        val expectedInfo =
            noteTaskInfo.copy(
                entryPoint = NoteTaskEntryPoint.TAIL_BUTTON,
                isKeyguardLocked = true,
            )
        whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked)
        whenever(resolver.resolveInfo(any(), any())).thenReturn(expectedInfo)

        createNoteTaskController()
            .showNoteTaskAsUser(
                entryPoint = expectedInfo.entryPoint!!,
                user = user10,
            )

        val intentCaptor = argumentCaptor<Intent>()
        val userCaptor = argumentCaptor<UserHandle>()
        verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor))
        intentCaptor.value.let { intent ->
            assertThat(intent.action).isEqualTo(Intent.ACTION_CREATE_NOTE)
            assertThat(intent.`package`).isEqualTo(NOTES_PACKAGE_NAME)
            assertThat(intent.flags and FLAG_ACTIVITY_NEW_TASK).isEqualTo(FLAG_ACTIVITY_NEW_TASK)
            assertThat(intent.flags and FLAG_ACTIVITY_MULTIPLE_TASK)
                .isEqualTo(FLAG_ACTIVITY_MULTIPLE_TASK)
            assertThat(intent.flags and FLAG_ACTIVITY_NEW_DOCUMENT)
                .isEqualTo(FLAG_ACTIVITY_NEW_DOCUMENT)
            assertThat(intent.getBooleanExtra(Intent.EXTRA_USE_STYLUS_MODE, false)).isTrue()
        }
        assertThat(userCaptor.value).isEqualTo(user10)
        verify(eventLogger).logNoteTaskOpened(expectedInfo)
        verifyZeroInteractions(bubbles)
    }

    @Test
    @Test
    fun showNoteTask_keyguardIsUnlocked_shouldStartBubblesWithoutLoggingUiEvent() {
    fun showNoteTask_keyguardIsUnlocked_shouldStartBubblesWithoutLoggingUiEvent() {
        val expectedInfo =
        val expectedInfo =