From c9fbc2e62505d8192a353e9322231d870c7cb923 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Tue, 22 Aug 2023 19:41:08 +0000 Subject: Append "Pinned" to content description for pinned targets Bug: 174283917 Test: atest ChooserListAdapterTest Test: turn on talkback, verify that pinned apps are specified for both direct share and app targets. Change-Id: Ia5121fbd2e99db111b5a2602fed41ae8a992a600 --- java/res/values/strings.xml | 4 ++ .../android/intentresolver/ChooserListAdapter.java | 27 ++++++-- .../intentresolver/ChooserListAdapterTest.kt | 76 ++++++++++++++++++---- 3 files changed, 89 insertions(+), 18 deletions(-) (limited to 'java') diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index 4b5367c0..0c772573 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -303,4 +303,8 @@ Exclude link Include link + + + Pinned diff --git a/java/src/com/android/intentresolver/ChooserListAdapter.java b/java/src/com/android/intentresolver/ChooserListAdapter.java index e6d6dbf4..d1101f1e 100644 --- a/java/src/com/android/intentresolver/ChooserListAdapter.java +++ b/java/src/com/android/intentresolver/ChooserListAdapter.java @@ -296,11 +296,23 @@ public class ChooserListAdapter extends ResolverListAdapter { CharSequence extendedInfo = info.getExtendedInfo(); String contentDescription = String.join(" ", info.getDisplayLabel(), extendedInfo != null ? extendedInfo : "", appName); + if (info.isPinned()) { + contentDescription = String.join( + ". ", + contentDescription, + mContext.getResources().getString(R.string.pinned)); + } holder.updateContentDescription(contentDescription); if (!info.hasDisplayIcon()) { loadDirectShareIcon((SelectableTargetInfo) info); } } else if (info.isDisplayResolveInfo()) { + if (info.isPinned()) { + holder.updateContentDescription(String.join( + ". ", + info.getDisplayLabel(), + mContext.getResources().getString(R.string.pinned))); + } DisplayResolveInfo dri = (DisplayResolveInfo) info; if (!dri.hasDisplayIcon()) { loadIcon(dri); @@ -384,18 +396,20 @@ public class ChooserListAdapter extends ResolverListAdapter { .stream() .collect(Collectors.groupingBy(target -> target.getResolvedComponentName().getPackageName() - + "#" + target.getDisplayLabel() - + '#' + target.getResolveInfo().userHandle.getIdentifier() + + "#" + target.getDisplayLabel() + + '#' + target.getResolveInfo().userHandle.getIdentifier() )) .values() .stream() .map(appTargets -> (appTargets.size() == 1) - ? appTargets.get(0) - : MultiDisplayResolveInfo.newMultiDisplayResolveInfo(appTargets)) + ? appTargets.get(0) + : MultiDisplayResolveInfo.newMultiDisplayResolveInfo( + appTargets)) .sorted(new ChooserActivity.AzInfoComparator(mContext)) .collect(Collectors.toList()); } + @Override protected void onPostExecute(List newList) { mSortedList = newList; @@ -645,8 +659,8 @@ public class ChooserListAdapter extends ResolverListAdapter { */ @Override AsyncTask, - Void, - List> createSortingTask(boolean doPostProcessing) { + Void, + List> createSortingTask(boolean doPostProcessing) { return new AsyncTask, Void, List>() { @@ -658,6 +672,7 @@ public class ChooserListAdapter extends ResolverListAdapter { Trace.endSection(); return params[0]; } + @Override protected void onPostExecute(List sortedComponents) { processSortedList(sortedComponents, doPostProcessing); diff --git a/java/tests/src/com/android/intentresolver/ChooserListAdapterTest.kt b/java/tests/src/com/android/intentresolver/ChooserListAdapterTest.kt index c8cb4b9b..9b5e2d1c 100644 --- a/java/tests/src/com/android/intentresolver/ChooserListAdapterTest.kt +++ b/java/tests/src/com/android/intentresolver/ChooserListAdapterTest.kt @@ -20,6 +20,7 @@ import android.content.ComponentName import android.content.Intent import android.content.pm.PackageManager import android.content.pm.PackageManager.ResolveInfoFlags +import android.content.pm.ShortcutInfo import android.os.UserHandle import android.view.View import android.widget.FrameLayout @@ -33,6 +34,7 @@ import com.android.intentresolver.chooser.TargetInfo import com.android.intentresolver.icons.TargetDataLoader import com.android.intentresolver.logging.EventLog import com.android.internal.R +import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -50,6 +52,8 @@ class ChooserListAdapterTest { } private val context = InstrumentationRegistry.getInstrumentation().context private val resolverListController = mock() + private val appLabel = "App" + private val targetLabel = "Target" private val mEventLog = mock() private val mTargetDataLoader = mock() @@ -132,29 +136,77 @@ class ChooserListAdapterTest { verify(mTargetDataLoader, times(1)).loadAppTargetIcon(any(), any(), any()) } - private fun createSelectableTargetInfo(): TargetInfo = - SelectableTargetInfo.newSelectableTargetInfo( - /* sourceInfo = */ DisplayResolveInfo.newDisplayResolveInfo( - Intent(), - ResolverDataProvider.createResolveInfo(2, 0, userHandle), - "label", - "extended info", - Intent(), - /* resolveInfoPresentationGetter= */ null - ), + @Test + fun onBindView_contentDescription() { + val view = createView() + val viewHolder = ResolverListAdapter.ViewHolder(view) + view.tag = viewHolder + val targetInfo = createSelectableTargetInfo() + testSubject.onBindView(view, targetInfo, 0) + + assertThat(view.contentDescription).isEqualTo("$targetLabel $appLabel") + } + + @Test + fun onBindView_contentDescriptionPinned() { + val view = createView() + val viewHolder = ResolverListAdapter.ViewHolder(view) + view.tag = viewHolder + val targetInfo = createSelectableTargetInfo(true) + testSubject.onBindView(view, targetInfo, 0) + + assertThat(view.contentDescription).isEqualTo("$targetLabel $appLabel. Pinned") + } + + @Test + fun onBindView_displayInfoContentDescriptionPinned() { + val view = createView() + val viewHolder = ResolverListAdapter.ViewHolder(view) + view.tag = viewHolder + val targetInfo = createDisplayResolveInfo(isPinned = true) + testSubject.onBindView(view, targetInfo, 0) + + assertThat(view.contentDescription).isEqualTo("$appLabel. Pinned") + } + + private fun createSelectableTargetInfo(isPinned: Boolean = false): TargetInfo { + val shortcutInfo = + createShortcutInfo("id-1", ComponentName("pkg", "Class"), 1).apply { + if (isPinned) { + addFlags(ShortcutInfo.FLAG_PINNED) + } + } + return SelectableTargetInfo.newSelectableTargetInfo( + /* sourceInfo = */ createDisplayResolveInfo(isPinned), /* backupResolveInfo = */ mock(), /* resolvedIntent = */ Intent(), /* chooserTarget = */ createChooserTarget( - "Target", + targetLabel, 0.5f, ComponentName("pkg", "Class"), "id-1" ), /* modifiedScore = */ 1f, - /* shortcutInfo = */ createShortcutInfo("id-1", ComponentName("pkg", "Class"), 1), + shortcutInfo, /* appTarget */ null, /* referrerFillInIntent = */ Intent() ) + } + + private fun createDisplayResolveInfo(isPinned: Boolean = false): DisplayResolveInfo = + DisplayResolveInfo.newDisplayResolveInfo( + Intent(), + ResolverDataProvider.createResolveInfo(2, 0, userHandle), + appLabel, + "extended info", + Intent(), + /* resolveInfoPresentationGetter= */ null + ) + .apply { + if (isPinned) { + setPinned(true) + } + } private fun createView(): View { val view = FrameLayout(context) -- cgit v1.2.3-59-g8ed1b