summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Steven Ng <stevenckng@google.com> 2023-03-14 17:17:27 +0000
committer Steven Ng <stevenckng@google.com> 2023-03-16 19:27:39 +0000
commit75e81b72a255615604e2bf506a2440577b970904 (patch)
tree54fa9e7ac9c388de8a3d2a282baec2db2a131625
parent81a6dbd32fc0a038db2b86f00cda78f729ce8077 (diff)
Add an overloading function for starting notes app on another user
Test: atest SystemUITests:com.android.systemui.notetask.NoteTaskControllerTest Bug: 259952057 Change-Id: I3722c12aced1f28f287c5aa1e9f40c0316c74fba
-rw-r--r--packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt15
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt35
2 files changed, 47 insertions, 3 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt
index ac22b7ce8b6b..9748efd6f091 100644
--- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt
+++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt
@@ -27,6 +27,7 @@ import android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.content.pm.PackageManager
import android.os.Build
+import android.os.UserHandle
import android.os.UserManager
import android.util.Log
import androidx.annotation.VisibleForTesting
@@ -100,6 +101,14 @@ constructor(
fun showNoteTask(
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
val bubbles = optionalBubbles.getOrNull() ?: return
@@ -113,7 +122,7 @@ constructor(
// note task when the screen is locked.
if (
isKeyguardLocked &&
- devicePolicyManager.areKeyguardShortcutsDisabled(userId = userTracker.userId)
+ devicePolicyManager.areKeyguardShortcutsDisabled(userId = user.identifier)
) {
logDebug { "Enterprise policy disallows launching note app when the screen is locked." }
return
@@ -126,7 +135,7 @@ constructor(
// TODO(b/266686199): We should handle when app not available. For now, we log.
val intent = createNoteIntent(info)
try {
- logDebug { "onShowNoteTask - start: $info" }
+ logDebug { "onShowNoteTask - start: $info on user#${user.identifier}" }
when (info.launchMode) {
is NoteTaskLaunchMode.AppBubble -> {
// TODO(b/267634412, b/268351693): Should use `showOrHideAppBubbleAsUser`
@@ -135,7 +144,7 @@ constructor(
logDebug { "onShowNoteTask - opened as app bubble: $info" }
}
is NoteTaskLaunchMode.Activity -> {
- context.startActivityAsUser(intent, userTracker.userHandle)
+ context.startActivityAsUser(intent, user)
eventLogger.logNoteTaskOpened(info)
logDebug { "onShowNoteTask - opened as activity: $info" }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt
index 3f940d64f236..3e643d1c4092 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt
@@ -216,6 +216,41 @@ internal class NoteTaskControllerTest : SysuiTestCase() {
}
@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
fun showNoteTask_keyguardIsUnlocked_shouldStartBubblesWithoutLoggingUiEvent() {
val expectedInfo =
noteTaskInfo.copy(