Loading packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt +16 −4 Original line number Diff line number Diff line Loading @@ -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" } Loading @@ -199,7 +204,7 @@ constructor( } catch (e: ActivityNotFoundException) { logDebug { "onShowNoteTask - failed: $info" } } logDebug { "onShowNoteTask - compoleted: $info" } logDebug { "onShowNoteTask - completed: $info" } } /** Loading Loading @@ -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 } packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +14 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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, Loading @@ -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 Loading Loading
packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt +16 −4 Original line number Diff line number Diff line Loading @@ -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" } Loading @@ -199,7 +204,7 @@ constructor( } catch (e: ActivityNotFoundException) { logDebug { "onShowNoteTask - failed: $info" } } logDebug { "onShowNoteTask - compoleted: $info" } logDebug { "onShowNoteTask - completed: $info" } } /** Loading Loading @@ -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 }
packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +14 −3 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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, Loading @@ -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 Loading