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

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

Merge "Intent chooser callback" into lmp-mr1-dev

parents 74af6700 0b3c1126
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7432,6 +7432,7 @@ package android.content {
    method public java.lang.Object clone();
    method public android.content.Intent cloneFilter();
    method public static android.content.Intent createChooser(android.content.Intent, java.lang.CharSequence);
    method public static android.content.Intent createChooser(android.content.Intent, java.lang.CharSequence, android.content.IntentSender);
    method public int describeContents();
    method public int fillIn(android.content.Intent, int);
    method public boolean filterEquals(android.content.Intent);
@@ -7707,6 +7708,8 @@ package android.content {
    field public static final java.lang.String EXTRA_CHANGED_COMPONENT_NAME_LIST = "android.intent.extra.changed_component_name_list";
    field public static final java.lang.String EXTRA_CHANGED_PACKAGE_LIST = "android.intent.extra.changed_package_list";
    field public static final java.lang.String EXTRA_CHANGED_UID_LIST = "android.intent.extra.changed_uid_list";
    field public static final java.lang.String EXTRA_CHOSEN_COMPONENT = "android.intent.extra.CHOSEN_COMPONENT";
    field public static final java.lang.String EXTRA_CHOSEN_COMPONENT_INTENT_SENDER = "android.intent.extra.CHOSEN_COMPONENT_INTENT_SENDER";
    field public static final java.lang.String EXTRA_DATA_REMOVED = "android.intent.extra.DATA_REMOVED";
    field public static final java.lang.String EXTRA_DOCK_STATE = "android.intent.extra.DOCK_STATE";
    field public static final int EXTRA_DOCK_STATE_CAR = 2; // 0x2
+52 −0
Original line number Diff line number Diff line
@@ -876,12 +876,44 @@ public class Intent implements Parcelable, Cloneable {
     * related methods.
     */
    public static Intent createChooser(Intent target, CharSequence title) {
        return createChooser(target, title, null);
    }

    /**
     * Convenience function for creating a {@link #ACTION_CHOOSER} Intent.
     *
     * <p>Builds a new {@link #ACTION_CHOOSER} Intent that wraps the given
     * target intent, also optionally supplying a title.  If the target
     * intent has specified {@link #FLAG_GRANT_READ_URI_PERMISSION} or
     * {@link #FLAG_GRANT_WRITE_URI_PERMISSION}, then these flags will also be
     * set in the returned chooser intent, with its ClipData set appropriately:
     * either a direct reflection of {@link #getClipData()} if that is non-null,
     * or a new ClipData built from {@link #getData()}.</p>
     *
     * <p>The caller may optionally supply an {@link IntentSender} to receive a callback
     * when the user makes a choice. This can be useful if the calling application wants
     * to remember the last chosen target and surface it as a more prominent or one-touch
     * affordance elsewhere in the UI for next time.</p>
     *
     * @param target The Intent that the user will be selecting an activity
     * to perform.
     * @param title Optional title that will be displayed in the chooser.
     * @param sender Optional IntentSender to be called when a choice is made.
     * @return Return a new Intent object that you can hand to
     * {@link Context#startActivity(Intent) Context.startActivity()} and
     * related methods.
     */
    public static Intent createChooser(Intent target, CharSequence title, IntentSender sender) {
        Intent intent = new Intent(ACTION_CHOOSER);
        intent.putExtra(EXTRA_INTENT, target);
        if (title != null) {
            intent.putExtra(EXTRA_TITLE, title);
        }

        if (sender != null) {
            intent.putExtra(EXTRA_CHOSEN_COMPONENT_INTENT_SENDER, sender);
        }

        // Migrate any clip data and flags from target.
        int permFlags = target.getFlags() & (FLAG_GRANT_READ_URI_PERMISSION
                | FLAG_GRANT_WRITE_URI_PERMISSION | FLAG_GRANT_PERSISTABLE_URI_PERMISSION
@@ -3139,6 +3171,26 @@ public class Intent implements Parcelable, Cloneable {
    public static final String EXTRA_REPLACEMENT_EXTRAS =
            "android.intent.extra.REPLACEMENT_EXTRAS";

    /**
     * An {@link IntentSender} that will be notified if a user successfully chooses a target
     * component to handle an action in an {@link #ACTION_CHOOSER} activity. The IntentSender
     * will have the extra {@link #EXTRA_CHOSEN_COMPONENT} appended to it containing the
     * {@link ComponentName} of the chosen component.
     *
     * <p>In some situations this callback may never come, for example if the user abandons
     * the chooser, switches to another task or any number of other reasons. Apps should not
     * be written assuming that this callback will always occur.</p>
     */
    public static final String EXTRA_CHOSEN_COMPONENT_INTENT_SENDER =
            "android.intent.extra.CHOSEN_COMPONENT_INTENT_SENDER";

    /**
     * The {@link ComponentName} chosen by the user to complete an action.
     *
     * @see #EXTRA_CHOSEN_COMPONENT_INTENT_SENDER
     */
    public static final String EXTRA_CHOSEN_COMPONENT = "android.intent.extra.CHOSEN_COMPONENT";

    /**
     * A {@link android.view.KeyEvent} object containing the event that
     * triggered the creation of the Intent it is in.
+26 −0
Original line number Diff line number Diff line
@@ -16,13 +16,20 @@

package com.android.internal.app;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.util.Slog;

public class ChooserActivity extends ResolverActivity {
    private static final String TAG = "ChooserActivity";

    private Bundle mReplacementExtras;
    private IntentSender mChosenComponentSender;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -60,11 +67,14 @@ public class ChooserActivity extends ResolverActivity {
                initialIntents[i] = in;
            }
        }
        mChosenComponentSender = intent.getParcelableExtra(
                Intent.EXTRA_CHOSEN_COMPONENT_INTENT_SENDER);
        setSafeForwardingMode(true);
        super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents,
                null, false);
    }

    @Override
    public Intent getReplacementIntent(String packageName, Intent defIntent) {
        if (mReplacementExtras != null) {
            final Bundle replExtras = mReplacementExtras.getBundle(packageName);
@@ -77,6 +87,22 @@ public class ChooserActivity extends ResolverActivity {
        return defIntent;
    }

    @Override
    public void onActivityStarted(Intent intent) {
        if (mChosenComponentSender != null) {
            final ComponentName target = intent.getComponent();
            if (target != null) {
                final Intent fillIn = new Intent().putExtra(Intent.EXTRA_CHOSEN_COMPONENT, target);
                try {
                    mChosenComponentSender.sendIntent(this, Activity.RESULT_OK, fillIn, null, null);
                } catch (IntentSender.SendIntentException e) {
                    Slog.e(TAG, "Unable to launch supplied IntentSender to report "
                            + "the chosen component: " + e);
                }
            }
        }
    }

    private void modifyTargetIntent(Intent in) {
        final String action = in.getAction();
        if (Intent.ACTION_SEND.equals(action) ||
+6 −0
Original line number Diff line number Diff line
@@ -644,10 +644,12 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
    public void safelyStartActivity(Intent intent) {
        if (!mSafeForwardingMode) {
            startActivity(intent);
            onActivityStarted(intent);
            return;
        }
        try {
            startActivityAsCaller(intent, null, UserHandle.USER_NULL);
            onActivityStarted(intent);
        } catch (RuntimeException e) {
            String launchedFromPackage;
            try {
@@ -662,6 +664,10 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
        }
    }

    public void onActivityStarted(Intent intent) {
        // Do nothing
    }

    void showAppDetails(ResolveInfo ri) {
        Intent in = new Intent().setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                .setData(Uri.fromParts("package", ri.activityInfo.packageName, null))