diff options
| author | 2023-03-24 19:40:19 +0000 | |
|---|---|---|
| committer | 2023-03-29 09:32:29 +0000 | |
| commit | cad8b461f4052fb0d16645d9dbb25581c00a35bb (patch) | |
| tree | a0a053521d6ad1c1679a5ffbcc496eb747dc20de | |
| parent | 7871be0c9765b28aa3c400a0e0a7a940a38050f3 (diff) | |
Hide Note Task if triggered twice from the lock screen
Test: atest NoteTaskControllerTest
Fixes: b/274070542
Change-Id: Ia7e8ee1a44b80df41f95c6420ea9d5da46e3c822
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt | 20 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt | 17 |
2 files changed, 30 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt index 2d7861be2da9..f5c0a94d07f2 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt @@ -174,21 +174,26 @@ constructor( infoReference.set(info) - // TODO(b/266686199): We should handle when app not available. For now, we log. - val intent = createNoteTaskIntent(info) try { + // TODO(b/266686199): We should handle when app not available. For now, we log. logDebug { "onShowNoteTask - start: $info on user#${user.identifier}" } when (info.launchMode) { is NoteTaskLaunchMode.AppBubble -> { // TODO: provide app bubble icon + val intent = createNoteTaskIntent(info) bubbles.showOrHideAppBubble(intent, user, null /* icon */) // App bubble logging happens on `onBubbleExpandChanged`. logDebug { "onShowNoteTask - opened as app bubble: $info" } } is NoteTaskLaunchMode.Activity -> { if (activityManager.isInForeground(info.packageName)) { - logDebug { "onShowNoteTask - already opened as activity: $info" } + // Force note task into background by calling home. + val intent = createHomeIntent() + context.startActivityAsUser(intent, user) + eventLogger.logNoteTaskClosed(info) + logDebug { "onShowNoteTask - closed as activity: $info" } } else { + val intent = createNoteTaskIntent(info) context.startActivityAsUser(intent, user) eventLogger.logNoteTaskOpened(info) logDebug { "onShowNoteTask - opened as activity: $info" } @@ -199,7 +204,7 @@ constructor( } catch (e: ActivityNotFoundException) { logDebug { "onShowNoteTask - failed: $info" } } - logDebug { "onShowNoteTask - compoleted: $info" } + logDebug { "onShowNoteTask - completed: $info" } } /** @@ -306,3 +311,10 @@ private fun createNoteTaskIntent(info: NoteTaskInfo): Intent = private inline fun Any.logDebug(message: () -> String) { if (Build.IS_DEBUGGABLE) Log.d(this::class.java.simpleName.orEmpty(), message()) } + +/** Creates an [Intent] which forces the current app to background by calling home. */ +private fun createHomeIntent(): Intent = + Intent(Intent.ACTION_MAIN).apply { + addCategory(Intent.CATEGORY_HOME) + flags = Intent.FLAG_ACTIVITY_NEW_TASK + } 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 9897ce106137..fbe089a0616f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt @@ -25,6 +25,8 @@ import android.app.role.RoleManager.ROLE_NOTES import android.content.ComponentName import android.content.Context import android.content.Intent +import android.content.Intent.ACTION_MAIN +import android.content.Intent.CATEGORY_HOME import android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK import android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT import android.content.Intent.FLAG_ACTIVITY_NEW_TASK @@ -278,7 +280,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { } @Test - fun showNoteTask_keyguardIsLocked_noteIsOpen_shouldStartActivityAndLogUiEvent() { + fun showNoteTask_keyguardIsLocked_noteIsOpen_shouldCloseActivityAndLogUiEvent() { val expectedInfo = NOTE_TASK_INFO.copy( entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, @@ -291,8 +293,17 @@ internal class NoteTaskControllerTest : SysuiTestCase() { createNoteTaskController().showNoteTask(entryPoint = expectedInfo.entryPoint!!) - verify(context, never()).startActivityAsUser(any(), any()) - verifyZeroInteractions(bubbles, eventLogger) + 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(userCaptor.value).isEqualTo(userTracker.userHandle) + verify(eventLogger).logNoteTaskClosed(expectedInfo) + verifyZeroInteractions(bubbles) } @Test |