From 3d88dccf7cfd8131a0211dba26a9611be6d06ee7 Mon Sep 17 00:00:00 2001 From: Alison Cichowlas Date: Fri, 19 Jun 2020 10:14:51 -0400 Subject: [PATCH] When Nearby is present as a chip, exclude it from app list. Fixes: 156514997 Test: atest ChooserActivityTest; manual with Nearby enabled Change-Id: Ibfb1cd2b25d41e56aea7ecd861af78ae7b48898b --- .../com/android/internal/app/ChooserActivity.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index dc4c8fd76e8ed..c362a7410aec2 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -691,8 +691,14 @@ public class ChooserActivity extends ResolverActivity implements mPinnedSharedPrefs = getPinnedSharedPrefs(this); pa = intent.getParcelableArrayExtra(Intent.EXTRA_EXCLUDE_COMPONENTS); + + + // Exclude out Nearby from main list if chip is present, to avoid duplication + ComponentName nearbySharingComponent = getNearbySharingComponent(); + boolean hasNearby = nearbySharingComponent != null; + if (pa != null) { - ComponentName[] names = new ComponentName[pa.length]; + ComponentName[] names = new ComponentName[pa.length + (hasNearby ? 1 : 0)]; for (int i = 0; i < pa.length; i++) { if (!(pa[i] instanceof ComponentName)) { Log.w(TAG, "Filtered component #" + i + " not a ComponentName: " + pa[i]); @@ -701,7 +707,14 @@ public class ChooserActivity extends ResolverActivity implements } names[i] = (ComponentName) pa[i]; } + if (hasNearby) { + names[names.length - 1] = nearbySharingComponent; + } + mFilteredComponentNames = names; + } else if (hasNearby) { + mFilteredComponentNames = new ComponentName[1]; + mFilteredComponentNames[0] = nearbySharingComponent; } pa = intent.getParcelableArrayExtra(Intent.EXTRA_CHOOSER_TARGETS);