Loading packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +63 −115 Original line number Diff line number Diff line Loading @@ -25,8 +25,11 @@ import android.app.role.RoleManager.ROLE_NOTES import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.Intent.ACTION_CREATE_NOTE import android.content.Intent.ACTION_MAIN import android.content.Intent.ACTION_MANAGE_DEFAULT_APP import android.content.Intent.CATEGORY_HOME import android.content.Intent.EXTRA_USE_STYLUS_MODE import android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK import android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT import android.content.Intent.FLAG_ACTIVITY_NEW_TASK Loading @@ -47,8 +50,10 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.notetask.NoteTaskController.Companion.EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE import com.android.systemui.notetask.NoteTaskController.Companion.SHORTCUT_ID import com.android.systemui.notetask.NoteTaskEntryPoint.APP_CLIPS import com.android.systemui.notetask.NoteTaskEntryPoint.KEYBOARD_SHORTCUT import com.android.systemui.notetask.NoteTaskEntryPoint.QUICK_AFFORDANCE import com.android.systemui.notetask.NoteTaskEntryPoint.TAIL_BUTTON import com.android.systemui.notetask.NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskManagedProfileProxyActivity Loading Loading @@ -221,31 +226,22 @@ internal class NoteTaskControllerTest : SysuiTestCase() { // region showNoteTask @Test fun showNoteTask_keyguardIsLocked_shouldStartActivityAndLogUiEvent() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = true, ) val expectedInfo = NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = true) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) createNoteTaskController() .showNoteTask( entryPoint = expectedInfo.entryPoint!!, ) createNoteTaskController().showNoteTask(entryPoint = expectedInfo.entryPoint!!) 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(NOTE_TASK_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(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) hasFlags(FLAG_ACTIVITY_MULTIPLE_TASK) hasFlags(FLAG_ACTIVITY_NEW_DOCUMENT) extras().bool(EXTRA_USE_STYLUS_MODE).isTrue() } assertThat(userCaptor.value).isEqualTo(userTracker.userHandle) verify(eventLogger).logNoteTaskOpened(expectedInfo) Loading @@ -256,32 +252,23 @@ internal class NoteTaskControllerTest : SysuiTestCase() { fun showNoteTaskWithUser_keyguardIsLocked_shouldStartActivityWithExpectedUserAndLogUiEvent() { val user10 = UserHandle.of(/* userId= */ 10) val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = true, user = user10, ) NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = true, user = user10) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) createNoteTaskController() .showNoteTaskAsUser( entryPoint = expectedInfo.entryPoint!!, user = user10, ) .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(NOTE_TASK_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(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) hasFlags(FLAG_ACTIVITY_MULTIPLE_TASK) hasFlags(FLAG_ACTIVITY_NEW_DOCUMENT) extras().bool(EXTRA_USE_STYLUS_MODE).isTrue() } assertThat(userCaptor.value).isEqualTo(user10) verify(eventLogger).logNoteTaskOpened(expectedInfo) Loading @@ -290,11 +277,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_keyguardIsLocked_noteIsOpen_shouldCloseActivityAndLogUiEvent() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = true, ) val expectedInfo = NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = true) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) whenever(activityManager.getRunningTasks(anyInt())) Loading @@ -305,10 +288,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent.action).isEqualTo(ACTION_MAIN) assertThat(intent.categories).contains(CATEGORY_HOME) assertThat(intent.flags and FLAG_ACTIVITY_NEW_TASK).isEqualTo(FLAG_ACTIVITY_NEW_TASK) assertThat(intentCaptor.value).run { hasAction(ACTION_MAIN) categories().contains(CATEGORY_HOME) hasFlags(FLAG_ACTIVITY_NEW_TASK) } assertThat(userCaptor.value).isEqualTo(userTracker.userHandle) verify(eventLogger).logNoteTaskClosed(expectedInfo) Loading @@ -317,18 +300,11 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_keyguardIsUnlocked_shouldStartBubblesWithoutLoggingUiEvent() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = false, ) val expectedInfo = NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = false) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) createNoteTaskController() .showNoteTask( entryPoint = expectedInfo.entryPoint!!, ) createNoteTaskController().showNoteTask(entryPoint = expectedInfo.entryPoint!!) // Context package name used to create bubble icon from drawable resource id verify(context).packageName Loading @@ -338,10 +314,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_bubblesIsNull_shouldDoNothing() { createNoteTaskController(bubbles = null) .showNoteTask( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, ) createNoteTaskController(bubbles = null).showNoteTask(entryPoint = TAIL_BUTTON) verifyZeroInteractions(context, bubbles, eventLogger) } Loading @@ -352,7 +325,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val noteTaskController = spy(createNoteTaskController()) doNothing().whenever(noteTaskController).showNoDefaultNotesAppToast() noteTaskController.showNoteTask(entryPoint = NoteTaskEntryPoint.TAIL_BUTTON) noteTaskController.showNoteTask(entryPoint = TAIL_BUTTON) verify(noteTaskController).showNoDefaultNotesAppToast() verifyZeroInteractions(context, bubbles, eventLogger) Loading @@ -360,10 +333,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_flagDisabled_shouldDoNothing() { createNoteTaskController(isEnabled = false) .showNoteTask( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, ) createNoteTaskController(isEnabled = false).showNoteTask(entryPoint = TAIL_BUTTON) verifyZeroInteractions(context, bubbles, eventLogger) } Loading @@ -372,10 +342,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { fun showNoteTask_userIsLocked_shouldDoNothing() { whenever(userManager.isUserUnlocked).thenReturn(false) createNoteTaskController() .showNoteTask( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, ) createNoteTaskController().showNoteTask(entryPoint = TAIL_BUTTON) verifyZeroInteractions(context, bubbles, eventLogger) } Loading @@ -383,30 +350,22 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_keyboardShortcut_shouldStartActivity() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.KEYBOARD_SHORTCUT, isKeyguardLocked = true, ) NOTE_TASK_INFO.copy(entryPoint = KEYBOARD_SHORTCUT, isKeyguardLocked = true) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) createNoteTaskController() .showNoteTask( entryPoint = expectedInfo.entryPoint!!, ) createNoteTaskController().showNoteTask(entryPoint = expectedInfo.entryPoint!!) 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(NOTE_TASK_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, true)).isFalse() assertThat(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) hasFlags(FLAG_ACTIVITY_MULTIPLE_TASK) hasFlags(FLAG_ACTIVITY_NEW_DOCUMENT) extras().bool(EXTRA_USE_STYLUS_MODE).isFalse() } assertThat(userCaptor.value).isEqualTo(userTracker.userHandle) verify(eventLogger).logNoteTaskOpened(expectedInfo) Loading Loading @@ -583,7 +542,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile).thenReturn(true) userTracker.set(mainAndWorkProfileUsers, mainAndWorkProfileUsers.indexOf(mainUserInfo)) createNoteTaskController().showNoteTask(entryPoint = NoteTaskEntryPoint.TAIL_BUTTON) createNoteTaskController().showNoteTask(entryPoint = TAIL_BUTTON) verifyNoteTaskOpenInBubbleInUser(workUserInfo.userHandle) } Loading @@ -593,8 +552,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile).thenReturn(true) userTracker.set(mainAndWorkProfileUsers, mainAndWorkProfileUsers.indexOf(mainUserInfo)) createNoteTaskController() .showNoteTask(entryPoint = NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT) createNoteTaskController().showNoteTask(entryPoint = WIDGET_PICKER_SHORTCUT) verifyNoteTaskOpenInBubbleInUser(mainUserInfo.userHandle) } Loading @@ -604,7 +562,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile).thenReturn(true) userTracker.set(mainAndWorkProfileUsers, mainAndWorkProfileUsers.indexOf(mainUserInfo)) createNoteTaskController().showNoteTask(entryPoint = NoteTaskEntryPoint.APP_CLIPS) createNoteTaskController().showNoteTask(entryPoint = APP_CLIPS) verifyNoteTaskOpenInBubbleInUser(mainUserInfo.userHandle) } Loading @@ -615,13 +573,13 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val iconCaptor = argumentCaptor<Icon>() verify(bubbles) .showOrHideAppBubble(capture(intentCaptor), eq(userHandle), capture(iconCaptor)) intentCaptor.value.let { intent -> assertThat(intent.action).isEqualTo(Intent.ACTION_CREATE_NOTE) assertThat(intent.`package`).isEqualTo(NOTE_TASK_PACKAGE_NAME) assertThat(intent.flags).isEqualTo(FLAG_ACTIVITY_NEW_TASK) assertThat(intent.getBooleanExtra(Intent.EXTRA_USE_STYLUS_MODE, false)).isTrue() assertThat(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) extras().bool(EXTRA_USE_STYLUS_MODE).isTrue() } iconCaptor.value.let { icon -> iconCaptor.value?.let { icon -> assertThat(icon).isNotNull() assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) } Loading Loading @@ -679,9 +637,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() { verify(shortcutManager).updateShortcuts(actualShortcuts.capture()) val actualShortcut = actualShortcuts.value.first() assertThat(actualShortcut.id).isEqualTo(SHORTCUT_ID) assertThat(actualShortcut.intent?.component?.className) .isEqualTo(LaunchNoteTaskActivity::class.java.name) assertThat(actualShortcut.intent?.action).isEqualTo(Intent.ACTION_CREATE_NOTE) assertThat(actualShortcut.intent).run { hasComponentClass(LaunchNoteTaskActivity::class.java) hasAction(ACTION_CREATE_NOTE) } assertThat(actualShortcut.shortLabel).isEqualTo(NOTE_TASK_SHORT_LABEL) assertThat(actualShortcut.isLongLived).isEqualTo(true) assertThat(actualShortcut.icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) Loading Loading @@ -737,12 +696,9 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() verify(context).startActivityAsUser(intentCaptor.capture(), eq(user0)) intentCaptor.value.let { intent -> assertThat(intent) .hasComponent( ComponentName(context, LaunchNoteTaskManagedProfileProxyActivity::class.java) ) assertThat(intent).hasFlags(FLAG_ACTIVITY_NEW_TASK) assertThat(intentCaptor.value).run { hasComponentClass(LaunchNoteTaskManagedProfileProxyActivity::class.java) hasFlags(FLAG_ACTIVITY_NEW_TASK) } } // endregion Loading Loading @@ -817,9 +773,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(workUserInfo.id)) } Loading @@ -833,9 +787,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(mainUserInfo.id)) } Loading @@ -848,9 +800,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(mainUserInfo.id)) } Loading @@ -863,9 +813,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(mainUserInfo.id)) } // endregion Loading Loading
packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +63 −115 Original line number Diff line number Diff line Loading @@ -25,8 +25,11 @@ import android.app.role.RoleManager.ROLE_NOTES import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.Intent.ACTION_CREATE_NOTE import android.content.Intent.ACTION_MAIN import android.content.Intent.ACTION_MANAGE_DEFAULT_APP import android.content.Intent.CATEGORY_HOME import android.content.Intent.EXTRA_USE_STYLUS_MODE import android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK import android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT import android.content.Intent.FLAG_ACTIVITY_NEW_TASK Loading @@ -47,8 +50,10 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.notetask.NoteTaskController.Companion.EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE import com.android.systemui.notetask.NoteTaskController.Companion.SHORTCUT_ID import com.android.systemui.notetask.NoteTaskEntryPoint.APP_CLIPS import com.android.systemui.notetask.NoteTaskEntryPoint.KEYBOARD_SHORTCUT import com.android.systemui.notetask.NoteTaskEntryPoint.QUICK_AFFORDANCE import com.android.systemui.notetask.NoteTaskEntryPoint.TAIL_BUTTON import com.android.systemui.notetask.NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT import com.android.systemui.notetask.shortcut.CreateNoteTaskShortcutActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskActivity import com.android.systemui.notetask.shortcut.LaunchNoteTaskManagedProfileProxyActivity Loading Loading @@ -221,31 +226,22 @@ internal class NoteTaskControllerTest : SysuiTestCase() { // region showNoteTask @Test fun showNoteTask_keyguardIsLocked_shouldStartActivityAndLogUiEvent() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = true, ) val expectedInfo = NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = true) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) createNoteTaskController() .showNoteTask( entryPoint = expectedInfo.entryPoint!!, ) createNoteTaskController().showNoteTask(entryPoint = expectedInfo.entryPoint!!) 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(NOTE_TASK_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(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) hasFlags(FLAG_ACTIVITY_MULTIPLE_TASK) hasFlags(FLAG_ACTIVITY_NEW_DOCUMENT) extras().bool(EXTRA_USE_STYLUS_MODE).isTrue() } assertThat(userCaptor.value).isEqualTo(userTracker.userHandle) verify(eventLogger).logNoteTaskOpened(expectedInfo) Loading @@ -256,32 +252,23 @@ internal class NoteTaskControllerTest : SysuiTestCase() { fun showNoteTaskWithUser_keyguardIsLocked_shouldStartActivityWithExpectedUserAndLogUiEvent() { val user10 = UserHandle.of(/* userId= */ 10) val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = true, user = user10, ) NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = true, user = user10) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) createNoteTaskController() .showNoteTaskAsUser( entryPoint = expectedInfo.entryPoint!!, user = user10, ) .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(NOTE_TASK_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(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) hasFlags(FLAG_ACTIVITY_MULTIPLE_TASK) hasFlags(FLAG_ACTIVITY_NEW_DOCUMENT) extras().bool(EXTRA_USE_STYLUS_MODE).isTrue() } assertThat(userCaptor.value).isEqualTo(user10) verify(eventLogger).logNoteTaskOpened(expectedInfo) Loading @@ -290,11 +277,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_keyguardIsLocked_noteIsOpen_shouldCloseActivityAndLogUiEvent() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = true, ) val expectedInfo = NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = true) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) whenever(activityManager.getRunningTasks(anyInt())) Loading @@ -305,10 +288,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent.action).isEqualTo(ACTION_MAIN) assertThat(intent.categories).contains(CATEGORY_HOME) assertThat(intent.flags and FLAG_ACTIVITY_NEW_TASK).isEqualTo(FLAG_ACTIVITY_NEW_TASK) assertThat(intentCaptor.value).run { hasAction(ACTION_MAIN) categories().contains(CATEGORY_HOME) hasFlags(FLAG_ACTIVITY_NEW_TASK) } assertThat(userCaptor.value).isEqualTo(userTracker.userHandle) verify(eventLogger).logNoteTaskClosed(expectedInfo) Loading @@ -317,18 +300,11 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_keyguardIsUnlocked_shouldStartBubblesWithoutLoggingUiEvent() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, isKeyguardLocked = false, ) val expectedInfo = NOTE_TASK_INFO.copy(entryPoint = TAIL_BUTTON, isKeyguardLocked = false) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) createNoteTaskController() .showNoteTask( entryPoint = expectedInfo.entryPoint!!, ) createNoteTaskController().showNoteTask(entryPoint = expectedInfo.entryPoint!!) // Context package name used to create bubble icon from drawable resource id verify(context).packageName Loading @@ -338,10 +314,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_bubblesIsNull_shouldDoNothing() { createNoteTaskController(bubbles = null) .showNoteTask( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, ) createNoteTaskController(bubbles = null).showNoteTask(entryPoint = TAIL_BUTTON) verifyZeroInteractions(context, bubbles, eventLogger) } Loading @@ -352,7 +325,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val noteTaskController = spy(createNoteTaskController()) doNothing().whenever(noteTaskController).showNoDefaultNotesAppToast() noteTaskController.showNoteTask(entryPoint = NoteTaskEntryPoint.TAIL_BUTTON) noteTaskController.showNoteTask(entryPoint = TAIL_BUTTON) verify(noteTaskController).showNoDefaultNotesAppToast() verifyZeroInteractions(context, bubbles, eventLogger) Loading @@ -360,10 +333,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_flagDisabled_shouldDoNothing() { createNoteTaskController(isEnabled = false) .showNoteTask( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, ) createNoteTaskController(isEnabled = false).showNoteTask(entryPoint = TAIL_BUTTON) verifyZeroInteractions(context, bubbles, eventLogger) } Loading @@ -372,10 +342,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { fun showNoteTask_userIsLocked_shouldDoNothing() { whenever(userManager.isUserUnlocked).thenReturn(false) createNoteTaskController() .showNoteTask( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, ) createNoteTaskController().showNoteTask(entryPoint = TAIL_BUTTON) verifyZeroInteractions(context, bubbles, eventLogger) } Loading @@ -383,30 +350,22 @@ internal class NoteTaskControllerTest : SysuiTestCase() { @Test fun showNoteTask_keyboardShortcut_shouldStartActivity() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.KEYBOARD_SHORTCUT, isKeyguardLocked = true, ) NOTE_TASK_INFO.copy(entryPoint = KEYBOARD_SHORTCUT, isKeyguardLocked = true) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(expectedInfo) createNoteTaskController() .showNoteTask( entryPoint = expectedInfo.entryPoint!!, ) createNoteTaskController().showNoteTask(entryPoint = expectedInfo.entryPoint!!) 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(NOTE_TASK_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, true)).isFalse() assertThat(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) hasFlags(FLAG_ACTIVITY_MULTIPLE_TASK) hasFlags(FLAG_ACTIVITY_NEW_DOCUMENT) extras().bool(EXTRA_USE_STYLUS_MODE).isFalse() } assertThat(userCaptor.value).isEqualTo(userTracker.userHandle) verify(eventLogger).logNoteTaskOpened(expectedInfo) Loading Loading @@ -583,7 +542,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile).thenReturn(true) userTracker.set(mainAndWorkProfileUsers, mainAndWorkProfileUsers.indexOf(mainUserInfo)) createNoteTaskController().showNoteTask(entryPoint = NoteTaskEntryPoint.TAIL_BUTTON) createNoteTaskController().showNoteTask(entryPoint = TAIL_BUTTON) verifyNoteTaskOpenInBubbleInUser(workUserInfo.userHandle) } Loading @@ -593,8 +552,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile).thenReturn(true) userTracker.set(mainAndWorkProfileUsers, mainAndWorkProfileUsers.indexOf(mainUserInfo)) createNoteTaskController() .showNoteTask(entryPoint = NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT) createNoteTaskController().showNoteTask(entryPoint = WIDGET_PICKER_SHORTCUT) verifyNoteTaskOpenInBubbleInUser(mainUserInfo.userHandle) } Loading @@ -604,7 +562,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(devicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile).thenReturn(true) userTracker.set(mainAndWorkProfileUsers, mainAndWorkProfileUsers.indexOf(mainUserInfo)) createNoteTaskController().showNoteTask(entryPoint = NoteTaskEntryPoint.APP_CLIPS) createNoteTaskController().showNoteTask(entryPoint = APP_CLIPS) verifyNoteTaskOpenInBubbleInUser(mainUserInfo.userHandle) } Loading @@ -615,13 +573,13 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val iconCaptor = argumentCaptor<Icon>() verify(bubbles) .showOrHideAppBubble(capture(intentCaptor), eq(userHandle), capture(iconCaptor)) intentCaptor.value.let { intent -> assertThat(intent.action).isEqualTo(Intent.ACTION_CREATE_NOTE) assertThat(intent.`package`).isEqualTo(NOTE_TASK_PACKAGE_NAME) assertThat(intent.flags).isEqualTo(FLAG_ACTIVITY_NEW_TASK) assertThat(intent.getBooleanExtra(Intent.EXTRA_USE_STYLUS_MODE, false)).isTrue() assertThat(intentCaptor.value).run { hasAction(ACTION_CREATE_NOTE) hasPackage(NOTE_TASK_PACKAGE_NAME) hasFlags(FLAG_ACTIVITY_NEW_TASK) extras().bool(EXTRA_USE_STYLUS_MODE).isTrue() } iconCaptor.value.let { icon -> iconCaptor.value?.let { icon -> assertThat(icon).isNotNull() assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) } Loading Loading @@ -679,9 +637,10 @@ internal class NoteTaskControllerTest : SysuiTestCase() { verify(shortcutManager).updateShortcuts(actualShortcuts.capture()) val actualShortcut = actualShortcuts.value.first() assertThat(actualShortcut.id).isEqualTo(SHORTCUT_ID) assertThat(actualShortcut.intent?.component?.className) .isEqualTo(LaunchNoteTaskActivity::class.java.name) assertThat(actualShortcut.intent?.action).isEqualTo(Intent.ACTION_CREATE_NOTE) assertThat(actualShortcut.intent).run { hasComponentClass(LaunchNoteTaskActivity::class.java) hasAction(ACTION_CREATE_NOTE) } assertThat(actualShortcut.shortLabel).isEqualTo(NOTE_TASK_SHORT_LABEL) assertThat(actualShortcut.isLongLived).isEqualTo(true) assertThat(actualShortcut.icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) Loading Loading @@ -737,12 +696,9 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() verify(context).startActivityAsUser(intentCaptor.capture(), eq(user0)) intentCaptor.value.let { intent -> assertThat(intent) .hasComponent( ComponentName(context, LaunchNoteTaskManagedProfileProxyActivity::class.java) ) assertThat(intent).hasFlags(FLAG_ACTIVITY_NEW_TASK) assertThat(intentCaptor.value).run { hasComponentClass(LaunchNoteTaskManagedProfileProxyActivity::class.java) hasFlags(FLAG_ACTIVITY_NEW_TASK) } } // endregion Loading Loading @@ -817,9 +773,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(workUserInfo.id)) } Loading @@ -833,9 +787,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(mainUserInfo.id)) } Loading @@ -848,9 +800,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(mainUserInfo.id)) } Loading @@ -863,9 +813,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { val intentCaptor = argumentCaptor<Intent>() val userCaptor = argumentCaptor<UserHandle>() verify(context).startActivityAsUser(capture(intentCaptor), capture(userCaptor)) intentCaptor.value.let { intent -> assertThat(intent).hasAction(Intent.ACTION_MANAGE_DEFAULT_APP) } assertThat(intentCaptor.value).hasAction(ACTION_MANAGE_DEFAULT_APP) assertThat(userCaptor.value).isEqualTo(UserHandle.of(mainUserInfo.id)) } // endregion Loading