Search in sources :

Example 31 with ActivityInfo

use of android.content.pm.ActivityInfo 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 32 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by ResurrectionRemix.

the class BroadcastRecord method cleanupDisabledPackageReceiversLocked.

boolean cleanupDisabledPackageReceiversLocked(String packageName, Set<String> filterByClasses, int userId, boolean doit) {
    if ((userId != UserHandle.USER_ALL && this.userId != userId) || receivers == null) {
        return false;
    }
    boolean didSomething = false;
    Object o;
    for (int i = receivers.size() - 1; i >= 0; i--) {
        o = receivers.get(i);
        if (!(o instanceof ResolveInfo)) {
            continue;
        }
        ActivityInfo info = ((ResolveInfo) o).activityInfo;
        final boolean sameComponent = packageName == null || (info.applicationInfo.packageName.equals(packageName) && (filterByClasses == null || filterByClasses.contains(info.name)));
        if (sameComponent) {
            if (!doit) {
                return true;
            }
            didSomething = true;
            receivers.remove(i);
            if (i < nextReceiver) {
                nextReceiver--;
            }
        }
    }
    nextReceiver = Math.min(nextReceiver, receivers.size());
    return didSomething;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo)

Example 33 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by ResurrectionRemix.

the class SuggestionsAdapter method getActivityIcon.

/**
     * Gets the activity or application icon for an activity.
     *
     * @param component Name of an activity.
     * @return A drawable, or {@code null} if neither the acitivy or the application
     *         have an icon set.
     */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0)
        return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
        return null;
    }
    return drawable;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString)

Example 34 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by ResurrectionRemix.

the class KeyguardBottomAreaView method bindCameraPrewarmService.

public void bindCameraPrewarmService() {
    Intent intent = getCameraIntent();
    ActivityInfo targetInfo = PreviewInflater.getTargetActivityInfo(mContext, intent, KeyguardUpdateMonitor.getCurrentUser(), true);
    if (targetInfo != null && targetInfo.metaData != null) {
        String clazz = targetInfo.metaData.getString(MediaStore.META_DATA_STILL_IMAGE_CAMERA_PREWARM_SERVICE);
        if (clazz != null) {
            Intent serviceIntent = new Intent();
            serviceIntent.setClassName(targetInfo.packageName, clazz);
            serviceIntent.setAction(CameraPrewarmService.ACTION_PREWARM);
            try {
                if (getContext().bindServiceAsUser(serviceIntent, mPrewarmConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(UserHandle.USER_CURRENT))) {
                    mPrewarmBound = true;
                }
            } catch (SecurityException e) {
                Log.w(TAG, "Unable to bind to prewarm service package=" + targetInfo.packageName + " class=" + clazz, e);
            }
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) UserHandle(android.os.UserHandle) Intent(android.content.Intent)

Example 35 with ActivityInfo

use of android.content.pm.ActivityInfo in project android_frameworks_base by ResurrectionRemix.

the class UsbSettingsManager method packageMatchesLocked.

// Checks to see if a package matches a device or accessory.
// Only one of device and accessory should be non-null.
private boolean packageMatchesLocked(ResolveInfo info, String metaDataName, UsbDevice device, UsbAccessory accessory) {
    ActivityInfo ai = info.activityInfo;
    XmlResourceParser parser = null;
    try {
        parser = ai.loadXmlMetaData(mPackageManager, metaDataName);
        if (parser == null) {
            Slog.w(TAG, "no meta-data for " + info);
            return false;
        }
        XmlUtils.nextElement(parser);
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            String tagName = parser.getName();
            if (device != null && "usb-device".equals(tagName)) {
                DeviceFilter filter = DeviceFilter.read(parser);
                if (filter.matches(device)) {
                    return true;
                }
            } else if (accessory != null && "usb-accessory".equals(tagName)) {
                AccessoryFilter filter = AccessoryFilter.read(parser);
                if (filter.matches(accessory)) {
                    return true;
                }
            }
            XmlUtils.nextElement(parser);
        }
    } catch (Exception e) {
        Slog.w(TAG, "Unable to load component info " + info.toString(), e);
    } finally {
        if (parser != null)
            parser.close();
    }
    return false;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

ActivityInfo (android.content.pm.ActivityInfo)886 ResolveInfo (android.content.pm.ResolveInfo)360 Intent (android.content.Intent)339 ComponentName (android.content.ComponentName)324 PackageManager (android.content.pm.PackageManager)215 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)141 ArrayList (java.util.ArrayList)139 ApplicationInfo (android.content.pm.ApplicationInfo)115 Test (org.junit.Test)113 RemoteException (android.os.RemoteException)82 Bundle (android.os.Bundle)68 PendingIntent (android.app.PendingIntent)62 Drawable (android.graphics.drawable.Drawable)61 IOException (java.io.IOException)60 PackageInfo (android.content.pm.PackageInfo)59 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)54 XmlResourceParser (android.content.res.XmlResourceParser)43 Point (android.graphics.Point)35 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)34 Context (android.content.Context)33