Loading packages/SystemUI/res/values/strings.xml +4 −2 Original line number Diff line number Diff line Loading @@ -2973,9 +2973,11 @@ <xliff:g id="weather_condition" example="Partly cloudy">%1$s</xliff:g>, <xliff:g id="temperature" example="7°C">%2$s</xliff:g> </string> <!-- TODO(b/259369672): Replace with final resource. --> <!-- [CHAR LIMIT=30] Label used to open Note Task --> <string name="note_task_button_label">Notetaking</string> <string name="note_task_button_label">Note-taking</string> <!-- [CHAR LIMIT=25] Long label used by Note Task Shortcut --> <string name="note_task_shortcut_long_label">Note-taking, <xliff:g id="note_taking_app" example="Note-taking App">%1$s</xliff:g></string> <!-- [CHAR LIMIT=NONE] Le audio broadcast dialog, media app is broadcasting --> <string name="broadcasting_description_is_broadcasting">Broadcasting</string> Loading packages/SystemUI/src/com/android/systemui/notetask/NoteTaskRoleManagerExt.kt +24 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.notetask import android.app.role.RoleManager import android.app.role.RoleManager.ROLE_NOTES import android.content.Context import android.content.pm.PackageManager import android.content.pm.ShortcutInfo import android.graphics.drawable.Icon import android.os.PersistableBundle Loading @@ -42,20 +43,41 @@ internal object NoteTaskRoleManagerExt { context: Context, user: UserHandle, ): ShortcutInfo { val packageName = getDefaultRoleHolderAsUser(ROLE_NOTES, user) val extras = PersistableBundle() getDefaultRoleHolderAsUser(ROLE_NOTES, user)?.let { packageName -> if (packageName != null) { // Set custom app badge using the icon from ROLES_NOTES default app. extras.putString(NoteTaskController.EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE, packageName) } val shortLabel = context.getString(R.string.note_task_button_label) val applicationLabel = context.packageManager.getApplicationLabel(packageName) val longLabel = if (applicationLabel == null) { shortLabel } else { context.getString( R.string.note_task_shortcut_long_label, applicationLabel, ) } val icon = Icon.createWithResource(context, R.drawable.ic_note_task_shortcut_widget) return ShortcutInfo.Builder(context, NoteTaskController.SHORTCUT_ID) .setIntent(LaunchNoteTaskActivity.newIntent(context = context)) .setShortLabel(context.getString(R.string.note_task_button_label)) .setShortLabel(shortLabel) .setLongLabel(longLabel) .setLongLived(true) .setIcon(icon) .setExtras(extras) .build() } private fun PackageManager.getApplicationLabel(packageName: String?): String? = runCatching { getApplicationInfo(packageName, /* flags= */ 0)!! } .getOrNull() ?.let { info -> getApplicationLabel(info).toString() } } packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +20 −14 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.pm.PackageManager import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED import android.content.pm.ShortcutInfo import android.content.pm.ShortcutManager import android.content.pm.UserInfo import android.graphics.drawable.Icon Loading @@ -62,6 +61,7 @@ import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.mockito.withArgCaptor import com.android.systemui.util.settings.SecureSettings Loading Loading @@ -115,7 +115,11 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(context.getString(R.string.note_task_button_label)) .thenReturn(NOTE_TASK_SHORT_LABEL) whenever(context.getString(eq(R.string.note_task_shortcut_long_label), any())) .thenReturn(NOTE_TASK_LONG_LABEL) whenever(context.packageManager).thenReturn(packageManager) whenever(packageManager.getApplicationInfo(any(), any<Int>())).thenReturn(mock()) whenever(packageManager.getApplicationLabel(any())).thenReturn(NOTE_TASK_LONG_LABEL) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(NOTE_TASK_INFO) whenever(userManager.isUserUnlocked).thenReturn(true) whenever(userManager.isUserUnlocked(any<Int>())).thenReturn(true) Loading Loading @@ -706,20 +710,21 @@ internal class NoteTaskControllerTest : SysuiTestCase() { .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) verify(shortcutManager, never()).disableShortcuts(any()) verify(shortcutManager).enableShortcuts(listOf(SHORTCUT_ID)) val actualShortcuts = argumentCaptor<List<ShortcutInfo>>() verify(shortcutManager).updateShortcuts(actualShortcuts.capture()) val actualShortcut = actualShortcuts.value.first() assertThat(actualShortcut.id).isEqualTo(SHORTCUT_ID) assertThat(actualShortcut.intent).run { val shortcutInfo = withArgCaptor { verify(shortcutManager).updateShortcuts(capture()) } with(shortcutInfo.first()) { assertThat(id).isEqualTo(SHORTCUT_ID) assertThat(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) assertThat(actualShortcut.extras?.getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE)) assertThat(shortLabel).isEqualTo(NOTE_TASK_SHORT_LABEL) assertThat(longLabel).isEqualTo(NOTE_TASK_LONG_LABEL) assertThat(isLongLived).isEqualTo(true) assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) assertThat(extras?.getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE)) .isEqualTo(NOTE_TASK_PACKAGE_NAME) } } @Test fun updateNoteTaskAsUserInternal_noNotesRole_shouldDisableShortcuts() { Loading Loading @@ -893,7 +898,8 @@ internal class NoteTaskControllerTest : SysuiTestCase() { // endregion private companion object { const val NOTE_TASK_SHORT_LABEL = "Notetaking" const val NOTE_TASK_SHORT_LABEL = "Note-taking" const val NOTE_TASK_LONG_LABEL = "Note-taking, App" const val NOTE_TASK_ACTIVITY_NAME = "NoteTaskActivity" const val NOTE_TASK_PACKAGE_NAME = "com.android.note.app" const val NOTE_TASK_UID = 123456 Loading Loading
packages/SystemUI/res/values/strings.xml +4 −2 Original line number Diff line number Diff line Loading @@ -2973,9 +2973,11 @@ <xliff:g id="weather_condition" example="Partly cloudy">%1$s</xliff:g>, <xliff:g id="temperature" example="7°C">%2$s</xliff:g> </string> <!-- TODO(b/259369672): Replace with final resource. --> <!-- [CHAR LIMIT=30] Label used to open Note Task --> <string name="note_task_button_label">Notetaking</string> <string name="note_task_button_label">Note-taking</string> <!-- [CHAR LIMIT=25] Long label used by Note Task Shortcut --> <string name="note_task_shortcut_long_label">Note-taking, <xliff:g id="note_taking_app" example="Note-taking App">%1$s</xliff:g></string> <!-- [CHAR LIMIT=NONE] Le audio broadcast dialog, media app is broadcasting --> <string name="broadcasting_description_is_broadcasting">Broadcasting</string> Loading
packages/SystemUI/src/com/android/systemui/notetask/NoteTaskRoleManagerExt.kt +24 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.notetask import android.app.role.RoleManager import android.app.role.RoleManager.ROLE_NOTES import android.content.Context import android.content.pm.PackageManager import android.content.pm.ShortcutInfo import android.graphics.drawable.Icon import android.os.PersistableBundle Loading @@ -42,20 +43,41 @@ internal object NoteTaskRoleManagerExt { context: Context, user: UserHandle, ): ShortcutInfo { val packageName = getDefaultRoleHolderAsUser(ROLE_NOTES, user) val extras = PersistableBundle() getDefaultRoleHolderAsUser(ROLE_NOTES, user)?.let { packageName -> if (packageName != null) { // Set custom app badge using the icon from ROLES_NOTES default app. extras.putString(NoteTaskController.EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE, packageName) } val shortLabel = context.getString(R.string.note_task_button_label) val applicationLabel = context.packageManager.getApplicationLabel(packageName) val longLabel = if (applicationLabel == null) { shortLabel } else { context.getString( R.string.note_task_shortcut_long_label, applicationLabel, ) } val icon = Icon.createWithResource(context, R.drawable.ic_note_task_shortcut_widget) return ShortcutInfo.Builder(context, NoteTaskController.SHORTCUT_ID) .setIntent(LaunchNoteTaskActivity.newIntent(context = context)) .setShortLabel(context.getString(R.string.note_task_button_label)) .setShortLabel(shortLabel) .setLongLabel(longLabel) .setLongLived(true) .setIcon(icon) .setExtras(extras) .build() } private fun PackageManager.getApplicationLabel(packageName: String?): String? = runCatching { getApplicationInfo(packageName, /* flags= */ 0)!! } .getOrNull() ?.let { info -> getApplicationLabel(info).toString() } }
packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskControllerTest.kt +20 −14 Original line number Diff line number Diff line Loading @@ -36,7 +36,6 @@ import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.pm.PackageManager import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED import android.content.pm.ShortcutInfo import android.content.pm.ShortcutManager import android.content.pm.UserInfo import android.graphics.drawable.Icon Loading @@ -62,6 +61,7 @@ import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.argumentCaptor import com.android.systemui.util.mockito.capture import com.android.systemui.util.mockito.eq import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.android.systemui.util.mockito.withArgCaptor import com.android.systemui.util.settings.SecureSettings Loading Loading @@ -115,7 +115,11 @@ internal class NoteTaskControllerTest : SysuiTestCase() { whenever(context.getString(R.string.note_task_button_label)) .thenReturn(NOTE_TASK_SHORT_LABEL) whenever(context.getString(eq(R.string.note_task_shortcut_long_label), any())) .thenReturn(NOTE_TASK_LONG_LABEL) whenever(context.packageManager).thenReturn(packageManager) whenever(packageManager.getApplicationInfo(any(), any<Int>())).thenReturn(mock()) whenever(packageManager.getApplicationLabel(any())).thenReturn(NOTE_TASK_LONG_LABEL) whenever(resolver.resolveInfo(any(), any(), any())).thenReturn(NOTE_TASK_INFO) whenever(userManager.isUserUnlocked).thenReturn(true) whenever(userManager.isUserUnlocked(any<Int>())).thenReturn(true) Loading Loading @@ -706,20 +710,21 @@ internal class NoteTaskControllerTest : SysuiTestCase() { .isEqualTo(CreateNoteTaskShortcutActivity::class.java.name) verify(shortcutManager, never()).disableShortcuts(any()) verify(shortcutManager).enableShortcuts(listOf(SHORTCUT_ID)) val actualShortcuts = argumentCaptor<List<ShortcutInfo>>() verify(shortcutManager).updateShortcuts(actualShortcuts.capture()) val actualShortcut = actualShortcuts.value.first() assertThat(actualShortcut.id).isEqualTo(SHORTCUT_ID) assertThat(actualShortcut.intent).run { val shortcutInfo = withArgCaptor { verify(shortcutManager).updateShortcuts(capture()) } with(shortcutInfo.first()) { assertThat(id).isEqualTo(SHORTCUT_ID) assertThat(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) assertThat(actualShortcut.extras?.getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE)) assertThat(shortLabel).isEqualTo(NOTE_TASK_SHORT_LABEL) assertThat(longLabel).isEqualTo(NOTE_TASK_LONG_LABEL) assertThat(isLongLived).isEqualTo(true) assertThat(icon.resId).isEqualTo(R.drawable.ic_note_task_shortcut_widget) assertThat(extras?.getString(EXTRA_SHORTCUT_BADGE_OVERRIDE_PACKAGE)) .isEqualTo(NOTE_TASK_PACKAGE_NAME) } } @Test fun updateNoteTaskAsUserInternal_noNotesRole_shouldDisableShortcuts() { Loading Loading @@ -893,7 +898,8 @@ internal class NoteTaskControllerTest : SysuiTestCase() { // endregion private companion object { const val NOTE_TASK_SHORT_LABEL = "Notetaking" const val NOTE_TASK_SHORT_LABEL = "Note-taking" const val NOTE_TASK_LONG_LABEL = "Note-taking, App" const val NOTE_TASK_ACTIVITY_NAME = "NoteTaskActivity" const val NOTE_TASK_PACKAGE_NAME = "com.android.note.app" const val NOTE_TASK_UID = 123456 Loading