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

Commit b7fae17a authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Add EXTRA_REPLACEMENT_EXTRAS for ACTION_CHOOSER" into lmp-dev

parents a19d7bfa e49d9393
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7751,6 +7751,7 @@ package android.content {
    field public static final java.lang.String EXTRA_PHONE_NUMBER = "android.intent.extra.PHONE_NUMBER";
    field public static final java.lang.String EXTRA_REFERRER = "android.intent.extra.REFERRER";
    field public static final java.lang.String EXTRA_REMOTE_INTENT_TOKEN = "android.intent.extra.remote_intent_token";
    field public static final java.lang.String EXTRA_REPLACEMENT_EXTRAS = "android.intent.extra.REPLACEMENT_EXTRAS";
    field public static final java.lang.String EXTRA_REPLACING = "android.intent.extra.REPLACING";
    field public static final java.lang.String EXTRA_RESTRICTIONS_BUNDLE = "android.intent.extra.restrictions_bundle";
    field public static final java.lang.String EXTRA_RESTRICTIONS_INTENT = "android.intent.extra.restrictions_intent";
+27 −0
Original line number Diff line number Diff line
@@ -3174,6 +3174,33 @@ public class Intent implements Parcelable, Cloneable {
     */
    public static final String EXTRA_INITIAL_INTENTS = "android.intent.extra.INITIAL_INTENTS";

    /**
     * A Bundle forming a mapping of potential target package names to different extras Bundles
     * to add to the default intent extras in {@link #EXTRA_INTENT} when used with
     * {@link #ACTION_CHOOSER}. Each key should be a package name. The package need not
     * be currently installed on the device.
     *
     * <p>An application may choose to provide alternate extras for the case where a user
     * selects an activity from a predetermined set of target packages. If the activity
     * the user selects from the chooser belongs to a package with its package name as
     * a key in this bundle, the corresponding extras for that package will be merged with
     * the extras already present in the intent at {@link #EXTRA_INTENT}. If a replacement
     * extra has the same key as an extra already present in the intent it will overwrite
     * the extra from the intent.</p>
     *
     * <p><em>Examples:</em>
     * <ul>
     *     <li>An application may offer different {@link #EXTRA_TEXT} to an application
     *     when sharing with it via {@link #ACTION_SEND}, augmenting a link with additional query
     *     parameters for that target.</li>
     *     <li>An application may offer additional metadata for known targets of a given intent
     *     to pass along information only relevant to that target such as account or content
     *     identifiers already known to that application.</li>
     * </ul></p>
     */
    public static final String EXTRA_REPLACEMENT_EXTRAS =
            "android.intent.extra.REPLACEMENT_EXTRAS";

    /**
     * A {@link android.view.KeyEvent} object containing the event that
     * triggered the creation of the Intent it is in.
+27 −14
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.os.Parcelable;
import android.util.Log;

public class ChooserActivity extends ResolverActivity {
    private Bundle mReplacementExtras;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();
@@ -34,14 +36,9 @@ public class ChooserActivity extends ResolverActivity {
        }
        Intent target = (Intent)targetParcelable;
        if (target != null) {
            final String action = target.getAction();
            if (Intent.ACTION_SEND.equals(action) ||
                    Intent.ACTION_SEND_MULTIPLE.equals(action)) {
                target.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT |
                        Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
                        Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS);
            }
            modifyTargetIntent(target);
        }
        mReplacementExtras = intent.getBundleExtra(Intent.EXTRA_REPLACEMENT_EXTRAS);
        CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
        int defaultTitleRes = 0;
        if (title == null) {
@@ -59,6 +56,27 @@ public class ChooserActivity extends ResolverActivity {
                    return;
                }
                final Intent in = (Intent) pa[i];
                modifyTargetIntent(in);
                initialIntents[i] = in;
            }
        }
        super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents,
                null, false);
    }

    public Intent getReplacementIntent(String packageName, Intent defIntent) {
        if (mReplacementExtras != null) {
            final Bundle replExtras = mReplacementExtras.getBundle(packageName);
            if (replExtras != null) {
                final Intent result = new Intent(defIntent);
                result.putExtras(replExtras);
                return result;
            }
        }
        return defIntent;
    }

    private void modifyTargetIntent(Intent in) {
        final String action = in.getAction();
        if (Intent.ACTION_SEND.equals(action) ||
                Intent.ACTION_SEND_MULTIPLE.equals(action)) {
@@ -66,10 +84,5 @@ public class ChooserActivity extends ResolverActivity {
                    Intent.FLAG_ACTIVITY_MULTIPLE_TASK |
                    Intent.FLAG_ACTIVITY_AUTO_REMOVE_FROM_RECENTS);
        }
                initialIntents[i] = in;
            }
        }
        super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents,
                null, false);
    }
}
+11 −4
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.internal.app;

import android.app.Activity;
import android.os.AsyncTask;
import android.util.ArrayMap;
import android.widget.AbsListView;
import android.widget.GridView;
import com.android.internal.R;
@@ -60,6 +59,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
@@ -428,6 +428,13 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
        finish();
    }

    /**
     * Replace me in subclasses!
     */
    public Intent getReplacementIntent(String packageName, Intent defIntent) {
        return defIntent;
    }

    protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
        if ((mAlwaysUseOption || mAdapter.hasFilteredItem()) && mAdapter.mOrigResolveList != null) {
            // Build a reasonable intent filter, based on what matched.
@@ -808,8 +815,8 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
        public Intent intentForPosition(int position, boolean filtered) {
            DisplayResolveInfo dri = filtered ? getItem(position) : mList.get(position);

            Intent intent = new Intent(dri.origIntent != null
                    ? dri.origIntent : mIntent);
            Intent intent = new Intent(dri.origIntent != null ? dri.origIntent :
                    getReplacementIntent(dri.ri.activityInfo.packageName, mIntent));
            intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
                    |Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
            ActivityInfo ai = dri.ri.activityInfo;