From 86328afff73c717afbffb5744f0a5d7f8eb7e61d Mon Sep 17 00:00:00 2001 From: Steven Ng Date: Thu, 13 Apr 2023 10:46:28 +0000 Subject: [PATCH] Show a toast upon stylus button click or keyboard shortcut when the default note app is set to none. Test: atest SystemUITests:com.android.systemui.notetask.NoteTaskController Bug: 266686199 Change-Id: I1bfa08320d386c436caa283718b9351c76b82b7c --- packages/SystemUI/res/values/strings.xml | 3 ++ .../systemui/notetask/NoteTaskController.kt | 16 +++++++++- .../notetask/NoteTaskControllerTest.kt | 31 ++++++++++--------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 74ae954a539c8..19deefbc41984 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -3086,4 +3086,7 @@ Assistant attention on + + + Set default notes app in Settings diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt index 334c70b217a3c..adb91f399e9f4 100644 --- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt +++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskController.kt @@ -34,7 +34,9 @@ import android.os.Build import android.os.UserHandle import android.os.UserManager import android.util.Log +import android.widget.Toast import androidx.annotation.VisibleForTesting +import com.android.systemui.R import com.android.systemui.dagger.SysUISingleton import com.android.systemui.devicepolicy.areKeyguardShortcutsDisabled import com.android.systemui.notetask.NoteTaskRoleManagerExt.createNoteShortcutInfoAsUser @@ -170,7 +172,13 @@ constructor( return } - val info = resolver.resolveInfo(entryPoint, isKeyguardLocked) ?: return + val info = resolver.resolveInfo(entryPoint, isKeyguardLocked) + + if (info == null) { + logDebug { "Default notes app isn't set" } + showNoDefaultNotesAppToast() + return + } infoReference.set(info) @@ -207,6 +215,12 @@ constructor( logDebug { "onShowNoteTask - completed: $info" } } + @VisibleForTesting + fun showNoDefaultNotesAppToast() { + Toast.makeText(context, R.string.set_default_notes_app_toast_content, Toast.LENGTH_SHORT) + .show() + } + /** * Set `android:enabled` property in the `AndroidManifest` associated with the Shortcut * component to [value]. 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 ba29ca57cefbc..fc82de2a5506c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt @@ -63,8 +63,10 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock +import org.mockito.Mockito.doNothing import org.mockito.Mockito.isNull import org.mockito.Mockito.never +import org.mockito.Mockito.spy import org.mockito.Mockito.verify import org.mockito.Mockito.verifyZeroInteractions import org.mockito.MockitoAnnotations @@ -107,6 +109,7 @@ internal class NoteTaskControllerTest : SysuiTestCase() { .thenReturn(listOf(NOTE_TASK_PACKAGE_NAME)) whenever(activityManager.getRunningTasks(anyInt())).thenReturn(emptyList()) whenever(userManager.isManagedProfile(workUserInfo.id)).thenReturn(true) + whenever(context.resources).thenReturn(getContext().resources) } private fun createNoteTaskController( @@ -337,14 +340,14 @@ internal class NoteTaskControllerTest : SysuiTestCase() { } @Test - fun showNoteTask_intentResolverReturnsNull_shouldDoNothing() { + fun showNoteTask_intentResolverReturnsNull_shouldShowToast() { whenever(resolver.resolveInfo(any(), any())).thenReturn(null) + val noteTaskController = spy(createNoteTaskController()) + doNothing().whenever(noteTaskController).showNoDefaultNotesAppToast() - createNoteTaskController() - .showNoteTask( - entryPoint = NoteTaskEntryPoint.TAIL_BUTTON, - ) + noteTaskController.showNoteTask(entryPoint = NoteTaskEntryPoint.TAIL_BUTTON) + verify(noteTaskController).showNoDefaultNotesAppToast() verifyZeroInteractions(context, bubbles, eventLogger) } @@ -373,17 +376,17 @@ 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 = NoteTaskEntryPoint.KEYBOARD_SHORTCUT, + isKeyguardLocked = true, + ) whenever(keyguardManager.isKeyguardLocked).thenReturn(expectedInfo.isKeyguardLocked) whenever(resolver.resolveInfo(any(), any())).thenReturn(expectedInfo) createNoteTaskController() - .showNoteTask( - entryPoint = expectedInfo.entryPoint!!, - ) + .showNoteTask( + entryPoint = expectedInfo.entryPoint!!, + ) val intentCaptor = argumentCaptor() val userCaptor = argumentCaptor() @@ -393,9 +396,9 @@ internal class NoteTaskControllerTest : SysuiTestCase() { 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) + .isEqualTo(FLAG_ACTIVITY_MULTIPLE_TASK) assertThat(intent.flags and FLAG_ACTIVITY_NEW_DOCUMENT) - .isEqualTo(FLAG_ACTIVITY_NEW_DOCUMENT) + .isEqualTo(FLAG_ACTIVITY_NEW_DOCUMENT) assertThat(intent.getBooleanExtra(Intent.EXTRA_USE_STYLUS_MODE, true)).isFalse() } assertThat(userCaptor.value).isEqualTo(userTracker.userHandle)