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

Commit 58688653 authored by Scott Mertz's avatar Scott Mertz Committed by Gerrit Code Review
Browse files

Remove send/send multiple if intent doesn't resolve to any activity

Instead of falling back to the editor activity as a last resort for "Send",
remove the option if there's no potential candidate.  The editor activity won't
handle the ACTION_SEND/ACTION_SEND_MULTIPLE intent anyway.  This stops an error
from popping up in the editor if the file cannot be sent from any other activity.

FEIJ-1380
Change-Id: I2330299e0cb8b6f3c93d5a190067b8bfe6a3f56f
(cherry picked from commit 92ac0ff6)
parent 8328024c
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -653,6 +653,10 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                menu.removeItem(R.id.mnu_actions_send);
            }

            if (!IntentsActionPolicy.sendHandledByAnyActivity(mContext, this.mFso)) {
                menu.removeItem(R.id.mnu_actions_send);
            }

            // Create link (not allow in storage volume)
            if (StorageHelper.isPathInStorageVolume(this.mFso.getFullPath())) {
                menu.removeItem(R.id.mnu_actions_create_link);
@@ -758,7 +762,8 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
                            break;
                        }
                    }
                    if (!areAllFiles) {
                    if (!areAllFiles ||
                            !IntentsActionPolicy.sendHandledByAnyActivity(mContext, selection)) {
                        menu.removeItem(R.id.mnu_actions_send_selection);
                    }
                }
+62 −48
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import com.cyanogenmod.filemanager.util.ResourcesHelper;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -177,56 +178,26 @@ public final class IntentsActionPolicy extends ActionsPolicy {
        return context.getPackageManager().queryIntentActivities(i, 0).size() > 0;
    }

    /**
     * Method that sends a {@link FileSystemObject} with the default registered application
     * by the system, or ask the user for select a registered application.
     *
     * @param ctx The current context
     * @param fso The file system object
     * @param onDismissListener The dismiss listener
     */
    public static void sendFileSystemObject(
            final Context ctx, final FileSystemObject fso, OnDismissListener onDismissListener) {
        try {
            // Create the intent to
            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_SEND);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setType(MimeTypeHelper.getMimeType(ctx, fso));
            Uri uri = getUriFromFile(ctx, fso);
            intent.putExtra(Intent.EXTRA_STREAM, uri);

            // Resolve the intent
            resolveIntent(
                    ctx,
                    intent,
                    false,
                    onDismissListener);
    public static boolean sendHandledByAnyActivity(final Context ctx, final FileSystemObject fso) {
        return ctx.getPackageManager().queryIntentActivities(getFsoSendIntent(ctx, fso), 0).size() > 0;
    }

        } catch (Exception e) {
            ExceptionUtil.translateException(ctx, e);
    public static boolean sendHandledByAnyActivity(final Context ctx, final List<FileSystemObject> fsos) {
        return ctx.getPackageManager().queryIntentActivities(getFsoSendIntent(ctx, fsos), 0).size() > 0;
    }

    private static Intent getFsoSendIntent(final Context ctx, final FileSystemObject fso) {
        return getFsoSendIntent(ctx, Arrays.asList(fso));
    }

    /**
     * Method that sends a {@link FileSystemObject} with the default registered application
     * by the system, or ask the user for select a registered application.
     *
     * @param ctx The current context
     * @param fsos The file system objects
     * @param onDismissListener The dismiss listener
     */
    public static void sendMultipleFileSystemObject(
            final Context ctx, final List<FileSystemObject> fsos,
            OnDismissListener onDismissListener) {
        try {
            // Create the intent to
    private static Intent getFsoSendIntent(final Context ctx, final List<FileSystemObject> fsos) {
        Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
        intent.setAction(fsos.size() > 1 ? Intent.ACTION_SEND_MULTIPLE : Intent.ACTION_SEND);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

        // Create an array list of the uris to send
        ArrayList<Uri> uris = new ArrayList<Uri>();

        int cc = fsos.size();
        String lastMimeType = null;
        boolean sameMimeType = true;
@@ -251,17 +222,60 @@ public final class IntentsActionPolicy extends ActionsPolicy {
            // Add the uri
            uris.add(getUriFromFile(ctx, fso));
        }
        if (lastMimeType != null) {
            if (sameMimeType) {
                intent.setType(lastMimeType);
            } else {
                intent.setType(MimeTypeHelper.ALL_MIME_TYPES);
            }
        }
        if (uris.size() > 1) {
            intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        } else {
            intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
        }
        return intent;
    }

    /**
     * Method that sends a {@link FileSystemObject} with the default registered application
     * by the system, or ask the user for select a registered application.
     *
     * @param ctx The current context
     * @param fso The file system object
     * @param onDismissListener The dismiss listener
     */
    public static void sendFileSystemObject(
            final Context ctx, final FileSystemObject fso, OnDismissListener onDismissListener) {
        try {
            // Resolve the intent
            resolveIntent(
                    ctx,
                    intent,
                    getFsoSendIntent(ctx, fso),
                    false,
                    onDismissListener);

        } catch (Exception e) {
            ExceptionUtil.translateException(ctx, e);
        }
    }

    /**
     * Method that sends a {@link FileSystemObject} with the default registered application
     * by the system, or ask the user for select a registered application.
     *
     * @param ctx The current context
     * @param fsos The file system objects
     * @param onDismissListener The dismiss listener
     */
    public static void sendMultipleFileSystemObject(
            final Context ctx, final List<FileSystemObject> fsos,
            OnDismissListener onDismissListener) {
        try {
            // Resolve the intent
            resolveIntent(
                    ctx,
                    getFsoSendIntent(ctx, fsos),
                    false,
                    onDismissListener);