Search in sources :

Example 6 with ChooserTarget

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

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 7 with ChooserTarget

use of android.service.chooser.ChooserTarget in project platform_frameworks_base by android.

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 8 with ChooserTarget

use of android.service.chooser.ChooserTarget in project platform_frameworks_base by android.

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 9 with ChooserTarget

use of android.service.chooser.ChooserTarget in project Signal-Android by WhisperSystems.

the class DirectShareService method onGetChooserTargets.

@Override
public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) {
    List<ChooserTarget> results = new LinkedList<>();
    MasterSecret masterSecret = KeyCachingService.getMasterSecret(this);
    if (masterSecret == null) {
        return results;
    }
    ComponentName componentName = new ComponentName(this, ShareActivity.class);
    ThreadDatabase threadDatabase = DatabaseFactory.getThreadDatabase(this);
    Cursor cursor = threadDatabase.getDirectShareList();
    try {
        ThreadDatabase.Reader reader = threadDatabase.readerFor(cursor, new MasterCipher(masterSecret));
        ThreadRecord record;
        while ((record = reader.getNext()) != null && results.size() < 10) {
            Recipients recipients = RecipientFactory.getRecipientsForIds(this, record.getRecipients().getIds(), false);
            String name = recipients.toShortString();
            Drawable drawable = recipients.getContactPhoto().asDrawable(this, recipients.getColor().toConversationColor(this));
            Bitmap avatar = BitmapUtil.createFromDrawable(drawable, 500, 500);
            Bundle bundle = new Bundle();
            bundle.putLong(ShareActivity.EXTRA_THREAD_ID, record.getThreadId());
            bundle.putLongArray(ShareActivity.EXTRA_RECIPIENT_IDS, recipients.getIds());
            bundle.putInt(ShareActivity.EXTRA_DISTRIBUTION_TYPE, record.getDistributionType());
            results.add(new ChooserTarget(name, Icon.createWithBitmap(avatar), 1.0f, componentName, bundle));
        }
        return results;
    } finally {
        if (cursor != null)
            cursor.close();
    }
}
Also used : MasterSecret(org.thoughtcrime.securesms.crypto.MasterSecret) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Bundle(android.os.Bundle) ThreadRecord(org.thoughtcrime.securesms.database.model.ThreadRecord) Drawable(android.graphics.drawable.Drawable) MasterCipher(org.thoughtcrime.securesms.crypto.MasterCipher) ThreadDatabase(org.thoughtcrime.securesms.database.ThreadDatabase) Cursor(android.database.Cursor) LinkedList(java.util.LinkedList) Bitmap(android.graphics.Bitmap) ChooserTarget(android.service.chooser.ChooserTarget) ComponentName(android.content.ComponentName)

Example 10 with ChooserTarget

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

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)

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