From 9bcaf18b0fda7adb1a93c5d170e390bf3b7ce0e3 Mon Sep 17 00:00:00 2001 From: Matt Casey Date: Mon, 24 Oct 2022 13:56:21 +0000 Subject: Remove experiment code to promote nearby as 1st target - Verified that we don't expect to do this experiment in U, nothing else was using this code so we can simplify. - Fix NPE that was hidden in the code (see bug). - Slight change to the excluded components behavior where the entire array given for EXTRA_EXCLUDE_COMPONENTS must be of type ComponentName[] otherwise it'll be ignored after logging an error. Relevant prior CLs: - ag/15527538 added this functionality (zzhen) - ag/17871086 added direct share pinning and modified some of these methods (songhu) Bug: 254895117 Test: atest AbstractResolverComparatorTest Test: atest CtsSharesheetDeviceTest (with flag enabled) Test: Manual verification that nearby component still hidden. Change-Id: I0306eb2547a2f60823d7c9d77d86e743d432fefc --- .../intentresolver/AbstractResolverComparator.java | 5 -- .../android/intentresolver/ChooserActivity.java | 99 +++++----------------- .../android/intentresolver/ResolverActivity.java | 9 -- .../intentresolver/ResolverListController.java | 10 --- 4 files changed, 22 insertions(+), 101 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/AbstractResolverComparator.java b/java/src/com/android/intentresolver/AbstractResolverComparator.java index 6f802876..07dcd664 100644 --- a/java/src/com/android/intentresolver/AbstractResolverComparator.java +++ b/java/src/com/android/intentresolver/AbstractResolverComparator.java @@ -161,11 +161,6 @@ public abstract class AbstractResolverComparator implements Comparator mFilteredComponentNames; private Intent mReferrerFillInIntent; @@ -619,32 +613,22 @@ 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 shouldFilterNearby = !shouldNearbyShareBeFirstInRankedRow() - && nearbySharingComponent != null; - - if (pa != null) { - ComponentName[] names = new ComponentName[pa.length + (shouldFilterNearby ? 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]); - names = null; - break; - } - names[i] = (ComponentName) pa[i]; - } - if (shouldFilterNearby) { - names[names.length - 1] = nearbySharingComponent; + mFilteredComponentNames = new ArrayList<>(); + try { + ComponentName[] exclodedComponents = intent.getParcelableArrayExtra( + Intent.EXTRA_EXCLUDE_COMPONENTS, + ComponentName.class); + if (exclodedComponents != null) { + Collections.addAll(mFilteredComponentNames, exclodedComponents); } + } catch (ClassCastException e) { + Log.e(TAG, "Excluded components must be of type ComponentName[]", e); + } - mFilteredComponentNames = names; - } else if (shouldFilterNearby) { - mFilteredComponentNames = new ComponentName[1]; - mFilteredComponentNames[0] = nearbySharingComponent; + // Exclude Nearby from main list if chip is present, to avoid duplication + ComponentName nearby = getNearbySharingComponent(); + if (nearby != null) { + mFilteredComponentNames.add(nearby); } pa = intent.getParcelableArrayExtra(Intent.EXTRA_CHOOSER_TARGETS); @@ -1325,9 +1309,7 @@ public class ChooserActivity extends ResolverActivity implements final ViewGroup actionRow = (ViewGroup) contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); addActionButton(actionRow, createCopyButton()); - if (shouldNearbyShareBeIncludedAsActionButton()) { - addActionButton(actionRow, createNearbyButton(targetIntent)); - } + addActionButton(actionRow, createNearbyButton(targetIntent)); CharSequence sharingText = targetIntent.getCharSequenceExtra(Intent.EXTRA_TEXT); if (sharingText == null) { @@ -1378,9 +1360,7 @@ public class ChooserActivity extends ResolverActivity implements final ViewGroup actionRow = (ViewGroup) contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); //TODO: addActionButton(actionRow, createCopyButton()); - if (shouldNearbyShareBeIncludedAsActionButton()) { - addActionButton(actionRow, createNearbyButton(targetIntent)); - } + addActionButton(actionRow, createNearbyButton(targetIntent)); addActionButton(actionRow, createEditButton(targetIntent)); mPreviewCoord = new ContentPreviewCoordinator(contentPreviewLayout, false); @@ -1500,9 +1480,7 @@ public class ChooserActivity extends ResolverActivity implements final ViewGroup actionRow = (ViewGroup) contentPreviewLayout.findViewById(com.android.internal.R.id.chooser_action_row); //TODO(b/120417119): addActionButton(actionRow, createCopyButton()); - if (shouldNearbyShareBeIncludedAsActionButton()) { - addActionButton(actionRow, createNearbyButton(targetIntent)); - } + addActionButton(actionRow, createNearbyButton(targetIntent)); String action = targetIntent.getAction(); if (Intent.ACTION_SEND.equals(action)) { @@ -2324,27 +2302,13 @@ public class ChooserActivity extends ResolverActivity implements @Override boolean isComponentFiltered(ComponentName name) { - if (mFilteredComponentNames == null) { - return false; - } - for (ComponentName filteredComponentName : mFilteredComponentNames) { - if (name.equals(filteredComponentName)) { - return true; - } - } - return false; + return mFilteredComponentNames != null && mFilteredComponentNames.contains(name); } @Override public boolean isComponentPinned(ComponentName name) { return mPinnedSharedPrefs.getBoolean(name.flattenToString(), false); } - - @Override - public boolean isFixedAtTop(ComponentName name) { - return name != null && name.equals(getNearbySharingComponent()) - && shouldNearbyShareBeFirstInRankedRow(); - } } @VisibleForTesting @@ -2899,8 +2863,8 @@ public class ChooserActivity extends ResolverActivity implements .targetInfoForPosition(mListPosition, /* filtered */ true); // This should always be the case for ItemViewHolder, check for validity - if (ti.isDisplayResolveInfo() && shouldShowTargetDetails(ti)) { - showTargetDetails((DisplayResolveInfo) ti); + if (ti.isDisplayResolveInfo()) { + showTargetDetails(ti); } return true; }); @@ -2908,15 +2872,6 @@ public class ChooserActivity extends ResolverActivity implements } } - private boolean shouldShowTargetDetails(TargetInfo ti) { - ComponentName nearbyShare = getNearbySharingComponent(); - // Suppress target details for nearby share to hide pin/unpin action - boolean isNearbyShare = nearbyShare != null && nearbyShare.equals( - ti.getResolvedComponentName()) && shouldNearbyShareBeFirstInRankedRow(); - return ti.isSelectableTargetInfo() - || (ti.isDisplayResolveInfo() && !isNearbyShare); - } - /** * Add a footer to the list, to support scrolling behavior below the navbar. */ @@ -3279,9 +3234,7 @@ public class ChooserActivity extends ResolverActivity implements v.setOnLongClickListener(v1 -> { TargetInfo ti = mChooserListAdapter.targetInfoForPosition( holder.getItemIndex(column), true); - if (shouldShowTargetDetails(ti)) { - showTargetDetails(ti); - } + showTargetDetails(ti); return true; }); @@ -4039,14 +3992,6 @@ public class ChooserActivity extends ResolverActivity implements getChooserActivityLogger().logSharesheetProfileChanged(); } - private boolean shouldNearbyShareBeFirstInRankedRow() { - return ActivityManager.isLowRamDeviceStatic() && mIsNearbyShareFirstTargetInRankedApp; - } - - private boolean shouldNearbyShareBeIncludedAsActionButton() { - return !shouldNearbyShareBeFirstInRankedRow(); - } - private static Map emptyIfNull(@Nullable Map map) { return map == null ? Collections.emptyMap() : map; } diff --git a/java/src/com/android/intentresolver/ResolverActivity.java b/java/src/com/android/intentresolver/ResolverActivity.java index 1d57b9f2..19251490 100644 --- a/java/src/com/android/intentresolver/ResolverActivity.java +++ b/java/src/com/android/intentresolver/ResolverActivity.java @@ -2140,7 +2140,6 @@ public class ResolverActivity extends FragmentActivity implements private final List mIntents = new ArrayList<>(); private final List mResolveInfos = new ArrayList<>(); private boolean mPinned; - private boolean mFixedAtTop; public ResolvedComponentInfo(ComponentName name, Intent intent, ResolveInfo info) { this.name = name; @@ -2189,14 +2188,6 @@ public class ResolverActivity extends FragmentActivity implements public void setPinned(boolean pinned) { mPinned = pinned; } - - public boolean isFixedAtTop() { - return mFixedAtTop; - } - - public void setFixedAtTop(boolean isFixedAtTop) { - mFixedAtTop = isFixedAtTop; - } } class ItemClickListener implements AdapterView.OnItemClickListener, diff --git a/java/src/com/android/intentresolver/ResolverListController.java b/java/src/com/android/intentresolver/ResolverListController.java index ff616ce0..6169c032 100644 --- a/java/src/com/android/intentresolver/ResolverListController.java +++ b/java/src/com/android/intentresolver/ResolverListController.java @@ -32,7 +32,6 @@ import android.os.UserHandle; import android.util.Log; import com.android.intentresolver.chooser.DisplayResolveInfo; - import com.android.internal.annotations.VisibleForTesting; import java.util.ArrayList; @@ -187,7 +186,6 @@ public class ResolverListController { final ResolverActivity.ResolvedComponentInfo rci = new ResolverActivity.ResolvedComponentInfo(name, intent, newInfo); rci.setPinned(isComponentPinned(name)); - rci.setFixedAtTop(isFixedAtTop(name)); into.add(rci); } } @@ -202,14 +200,6 @@ public class ResolverListController { return false; } - /** - * Whether this component is fixed at top in the ranked apps list. Always false for Resolver; - * overridden in Chooser. - */ - public boolean isFixedAtTop(ComponentName name) { - return false; - } - // Filter out any activities that the launched uid does not have permission for. // To preserve the inputList, optionally will return the original list if any modification has // been made. -- cgit v1.2.3-59-g8ed1b