Search in sources :

Example 11 with ChooserTarget

use of android.service.chooser.ChooserTarget in project android_frameworks_base by DirtyUnicorns.

the class ChooserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
    if (!(targetParcelable instanceof Intent)) {
        Log.w("ChooserActivity", "Target is not an intent: " + targetParcelable);
        finish();
        super.onCreate(null);
        return;
    }
    Intent target = (Intent) targetParcelable;
    if (target != null) {
        modifyTargetIntent(target);
    }
    Parcelable[] targetsParcelable = intent.getParcelableArrayExtra(Intent.EXTRA_ALTERNATE_INTENTS);
    if (targetsParcelable != null) {
        final boolean offset = target == null;
        Intent[] additionalTargets = new Intent[offset ? targetsParcelable.length - 1 : targetsParcelable.length];
        for (int i = 0; i < targetsParcelable.length; i++) {
            if (!(targetsParcelable[i] instanceof Intent)) {
                Log.w(TAG, "EXTRA_ALTERNATE_INTENTS array entry #" + i + " is not an Intent: " + targetsParcelable[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent additionalTarget = (Intent) targetsParcelable[i];
            if (i == 0 && target == null) {
                target = additionalTarget;
                modifyTargetIntent(target);
            } else {
                additionalTargets[offset ? i - 1 : i] = additionalTarget;
                modifyTargetIntent(additionalTarget);
            }
        }
        setAdditionalTargets(additionalTargets);
    }
    mReplacementExtras = intent.getBundleExtra(Intent.EXTRA_REPLACEMENT_EXTRAS);
    CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
    int defaultTitleRes = 0;
    if (title == null) {
        defaultTitleRes = com.android.internal.R.string.chooseActivity;
    }
    Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
    Intent[] initialIntents = null;
    if (pa != null) {
        initialIntents = new Intent[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof Intent)) {
                Log.w(TAG, "Initial intent #" + i + " not an Intent: " + pa[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent in = (Intent) pa[i];
            modifyTargetIntent(in);
            initialIntents[i] = in;
        }
    }
    mReferrerFillInIntent = new Intent().putExtra(Intent.EXTRA_REFERRER, getReferrer());
    mChosenComponentSender = intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT_INTENT_SENDER);
    mRefinementIntentSender = intent.getParcelableExtra(Intent.EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER);
    setSafeForwardingMode(true);
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_EXCLUDE_COMPONENTS);
    if (pa != null) {
        ComponentName[] names = new ComponentName[pa.length];
        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];
        }
        setFilteredComponents(names);
    }
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_CHOOSER_TARGETS);
    if (pa != null) {
        ChooserTarget[] targets = new ChooserTarget[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof ChooserTarget)) {
                Log.w(TAG, "Chooser target #" + i + " not a ChooserTarget: " + pa[i]);
                targets = null;
                break;
            }
            targets[i] = (ChooserTarget) pa[i];
        }
        mCallerChooserTargets = targets;
    }
    mPinnedSharedPrefs = getPinnedSharedPrefs(this);
    super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents, null, false);
    MetricsLogger.action(this, MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN);
}
Also used : ChooserTarget(android.service.chooser.ChooserTarget) LabeledIntent(android.content.pm.LabeledIntent) Intent(android.content.Intent) Parcelable(android.os.Parcelable) ComponentName(android.content.ComponentName)

Example 12 with ChooserTarget

use of android.service.chooser.ChooserTarget in project android_frameworks_base by crdroidandroid.

the class ChooserActivity method filterServiceTargets.

void filterServiceTargets(String packageName, List<ChooserTarget> targets) {
    if (targets == null) {
        return;
    }
    final PackageManager pm = getPackageManager();
    for (int i = targets.size() - 1; i >= 0; i--) {
        final ChooserTarget target = targets.get(i);
        final ComponentName targetName = target.getComponentName();
        if (packageName != null && packageName.equals(targetName.getPackageName())) {
            // Anything from the original target's package is fine.
            continue;
        }
        boolean remove;
        try {
            final ActivityInfo ai = pm.getActivityInfo(targetName, 0);
            remove = !ai.exported || ai.permission != null;
        } catch (NameNotFoundException e) {
            Log.e(TAG, "Target " + target + " returned by " + packageName + " component not found");
            remove = true;
        }
        if (remove) {
            targets.remove(i);
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName)

Example 13 with ChooserTarget

use of android.service.chooser.ChooserTarget in project android_frameworks_base by crdroidandroid.

the class ChooserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Intent intent = getIntent();
    Parcelable targetParcelable = intent.getParcelableExtra(Intent.EXTRA_INTENT);
    if (!(targetParcelable instanceof Intent)) {
        Log.w("ChooserActivity", "Target is not an intent: " + targetParcelable);
        finish();
        super.onCreate(null);
        return;
    }
    Intent target = (Intent) targetParcelable;
    if (target != null) {
        modifyTargetIntent(target);
    }
    Parcelable[] targetsParcelable = intent.getParcelableArrayExtra(Intent.EXTRA_ALTERNATE_INTENTS);
    if (targetsParcelable != null) {
        final boolean offset = target == null;
        Intent[] additionalTargets = new Intent[offset ? targetsParcelable.length - 1 : targetsParcelable.length];
        for (int i = 0; i < targetsParcelable.length; i++) {
            if (!(targetsParcelable[i] instanceof Intent)) {
                Log.w(TAG, "EXTRA_ALTERNATE_INTENTS array entry #" + i + " is not an Intent: " + targetsParcelable[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent additionalTarget = (Intent) targetsParcelable[i];
            if (i == 0 && target == null) {
                target = additionalTarget;
                modifyTargetIntent(target);
            } else {
                additionalTargets[offset ? i - 1 : i] = additionalTarget;
                modifyTargetIntent(additionalTarget);
            }
        }
        setAdditionalTargets(additionalTargets);
    }
    mReplacementExtras = intent.getBundleExtra(Intent.EXTRA_REPLACEMENT_EXTRAS);
    CharSequence title = intent.getCharSequenceExtra(Intent.EXTRA_TITLE);
    int defaultTitleRes = 0;
    if (title == null) {
        defaultTitleRes = com.android.internal.R.string.chooseActivity;
    }
    Parcelable[] pa = intent.getParcelableArrayExtra(Intent.EXTRA_INITIAL_INTENTS);
    Intent[] initialIntents = null;
    if (pa != null) {
        initialIntents = new Intent[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof Intent)) {
                Log.w(TAG, "Initial intent #" + i + " not an Intent: " + pa[i]);
                finish();
                super.onCreate(null);
                return;
            }
            final Intent in = (Intent) pa[i];
            modifyTargetIntent(in);
            initialIntents[i] = in;
        }
    }
    mReferrerFillInIntent = new Intent().putExtra(Intent.EXTRA_REFERRER, getReferrer());
    mChosenComponentSender = intent.getParcelableExtra(Intent.EXTRA_CHOSEN_COMPONENT_INTENT_SENDER);
    mRefinementIntentSender = intent.getParcelableExtra(Intent.EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER);
    setSafeForwardingMode(true);
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_EXCLUDE_COMPONENTS);
    if (pa != null) {
        ComponentName[] names = new ComponentName[pa.length];
        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];
        }
        setFilteredComponents(names);
    }
    pa = intent.getParcelableArrayExtra(Intent.EXTRA_CHOOSER_TARGETS);
    if (pa != null) {
        ChooserTarget[] targets = new ChooserTarget[pa.length];
        for (int i = 0; i < pa.length; i++) {
            if (!(pa[i] instanceof ChooserTarget)) {
                Log.w(TAG, "Chooser target #" + i + " not a ChooserTarget: " + pa[i]);
                targets = null;
                break;
            }
            targets[i] = (ChooserTarget) pa[i];
        }
        mCallerChooserTargets = targets;
    }
    mPinnedSharedPrefs = getPinnedSharedPrefs(this);
    super.onCreate(savedInstanceState, target, title, defaultTitleRes, initialIntents, null, false);
    MetricsLogger.action(this, MetricsEvent.ACTION_ACTIVITY_CHOOSER_SHOWN);
}
Also used : ChooserTarget(android.service.chooser.ChooserTarget) LabeledIntent(android.content.pm.LabeledIntent) Intent(android.content.Intent) Parcelable(android.os.Parcelable) ComponentName(android.content.ComponentName)

Aggregations

ComponentName (android.content.ComponentName)13 ChooserTarget (android.service.chooser.ChooserTarget)13 Intent (android.content.Intent)6 ActivityInfo (android.content.pm.ActivityInfo)5 LabeledIntent (android.content.pm.LabeledIntent)5 PackageManager (android.content.pm.PackageManager)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 Parcelable (android.os.Parcelable)5 Bundle (android.os.Bundle)3 Icon (android.graphics.drawable.Icon)2 PendingIntent (android.app.PendingIntent)1 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Conversation (eu.siacs.conversations.entities.Conversation)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 MasterCipher (org.thoughtcrime.securesms.crypto.MasterCipher)1 MasterSecret (org.thoughtcrime.securesms.crypto.MasterSecret)1 ThreadDatabase (org.thoughtcrime.securesms.database.ThreadDatabase)1