Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 860302d2 authored by Matt Casey's avatar Matt Casey Committed by Android (Google) Code Review
Browse files

Merge "Remove legacy_chooser_pinning_removal" into main

parents ec4f801f ef2ed92c
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -27,14 +27,3 @@ flag {
  description: "Provides additional callbacks with information about user actions in ChooserResult"
  bug: "263474465"
}

flag {
  name: "legacy_chooser_pinning_removal"
  namespace: "intentresolver"
  description: "Removing pinning functionality from the legacy chooser (used by partial screenshare)"
  bug: "301068735"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+1 −87
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ import android.provider.Downloads;
import android.provider.OpenableColumns;
import android.provider.Settings;
import android.service.chooser.ChooserTarget;
import android.service.chooser.Flags;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.HashedStringCache;
@@ -1801,54 +1800,6 @@ public class ChooserActivity extends ResolverActivity implements
        return getIntent().getBooleanExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE, true);
    }

    private void showTargetDetails(TargetInfo targetInfo) {
        if (targetInfo == null) return;

        ArrayList<DisplayResolveInfo> targetList;
        ChooserTargetActionsDialogFragment fragment = new ChooserTargetActionsDialogFragment();
        Bundle bundle = new Bundle();

        if (targetInfo instanceof SelectableTargetInfo) {
            SelectableTargetInfo selectableTargetInfo = (SelectableTargetInfo) targetInfo;
            if (selectableTargetInfo.getDisplayResolveInfo() == null
                    || selectableTargetInfo.getChooserTarget() == null) {
                Log.e(TAG, "displayResolveInfo or chooserTarget in selectableTargetInfo are null");
                return;
            }
            targetList = new ArrayList<>();
            targetList.add(selectableTargetInfo.getDisplayResolveInfo());
            bundle.putString(ChooserTargetActionsDialogFragment.SHORTCUT_ID_KEY,
                    selectableTargetInfo.getChooserTarget().getIntentExtras().getString(
                            Intent.EXTRA_SHORTCUT_ID));
            bundle.putBoolean(ChooserTargetActionsDialogFragment.IS_SHORTCUT_PINNED_KEY,
                    selectableTargetInfo.isPinned());
            bundle.putParcelable(ChooserTargetActionsDialogFragment.INTENT_FILTER_KEY,
                    getTargetIntentFilter());
            if (selectableTargetInfo.getDisplayLabel() != null) {
                bundle.putString(ChooserTargetActionsDialogFragment.SHORTCUT_TITLE_KEY,
                        selectableTargetInfo.getDisplayLabel().toString());
            }
        } else if (targetInfo instanceof MultiDisplayResolveInfo) {
            // For multiple targets, include info on all targets
            MultiDisplayResolveInfo mti = (MultiDisplayResolveInfo) targetInfo;
            targetList = mti.getTargets();
        } else {
            targetList = new ArrayList<DisplayResolveInfo>();
            targetList.add((DisplayResolveInfo) targetInfo);
        }
        // Adding userHandle from ResolveInfo allows the app icon in Dialog Box to be
        // resolved correctly.
        bundle.putParcelable(ChooserTargetActionsDialogFragment.USER_HANDLE_KEY,
                getResolveInfoUserHandle(
                        targetInfo.getResolveInfo(),
                        mChooserMultiProfilePagerAdapter.getCurrentUserHandle()));
        bundle.putParcelableArrayList(ChooserTargetActionsDialogFragment.TARGET_INFOS_KEY,
                targetList);
        fragment.setArguments(bundle);

        fragment.show(getFragmentManager(), TARGET_DETAILS_FRAGMENT_TAG);
    }

    private void modifyTargetIntent(Intent in) {
        if (isSendAction(in)) {
            in.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
@@ -2544,11 +2495,8 @@ public class ChooserActivity extends ResolverActivity implements

        @Override
        public boolean isComponentPinned(ComponentName name) {
            if (Flags.legacyChooserPinningRemoval()) {
            return false;
        }
            return mPinnedSharedPrefs.getBoolean(name.flattenToString(), false);
        }

        @Override
        public boolean isFixedAtTop(ComponentName name) {
@@ -3135,32 +3083,8 @@ public class ChooserActivity extends ResolverActivity implements
            if (isClickable) {
                itemView.setOnClickListener(v -> startSelected(mListPosition,
                        false/* always */, true/* filterd */));

                itemView.setOnLongClickListener(v -> {
                    final TargetInfo ti = mChooserMultiProfilePagerAdapter.getActiveListAdapter()
                            .targetInfoForPosition(mListPosition, /* filtered */ true);

                    // This should always be the case for ItemViewHolder, check for validity
                    if (ti instanceof DisplayResolveInfo && shouldShowTargetDetails(ti)) {
                        showTargetDetails((DisplayResolveInfo) ti);
                    }
                    return true;
                });
            }
            }
        }

    private boolean shouldShowTargetDetails(TargetInfo ti) {
        if (Flags.legacyChooserPinningRemoval()) {
            // Never show the long press menu if we've removed pinning.
            return false;
        }
        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 instanceof SelectableTargetInfo
                || (ti instanceof DisplayResolveInfo && !isNearbyShare);
    }

    /**
@@ -3517,16 +3441,6 @@ public class ChooserActivity extends ResolverActivity implements
                    }
                });

                // Show menu for both direct share and app share targets after long click.
                v.setOnLongClickListener(v1 -> {
                    TargetInfo ti = mChooserListAdapter.targetInfoForPosition(
                            holder.getItemIndex(column), true);
                    if (shouldShowTargetDetails(ti)) {
                        showTargetDetails(ti);
                    }
                    return true;
                });

                holder.addView(i, v);

                // Force Direct Share to be 2 lines and auto-wrap to second line via hoz scroll =