Search in sources :

Example 71 with ActivityInfo

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

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 72 with ActivityInfo

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

the class Settings method applyDefaultPreferredActivityLPw.

private void applyDefaultPreferredActivityLPw(PackageManagerService service, Intent intent, int flags, ComponentName cn, String scheme, PatternMatcher ssp, IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) {
    flags = service.updateFlagsForResolve(flags, userId, intent);
    List<ResolveInfo> ri = service.mActivities.queryIntent(intent, intent.getType(), flags, 0);
    if (PackageManagerService.DEBUG_PREFERRED)
        Log.d(TAG, "Queried " + intent + " results: " + ri);
    int systemMatch = 0;
    int thirdPartyMatch = 0;
    if (ri != null && ri.size() > 1) {
        boolean haveAct = false;
        ComponentName haveNonSys = null;
        ComponentName[] set = new ComponentName[ri.size()];
        for (int i = 0; i < ri.size(); i++) {
            ActivityInfo ai = ri.get(i).activityInfo;
            set[i] = new ComponentName(ai.packageName, ai.name);
            if ((ai.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                if (ri.get(i).match >= thirdPartyMatch) {
                    // want to set a preferred app for this intent.
                    if (PackageManagerService.DEBUG_PREFERRED)
                        Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": non-system!");
                    haveNonSys = set[i];
                    break;
                }
            } else if (cn.getPackageName().equals(ai.packageName) && cn.getClassName().equals(ai.name)) {
                if (PackageManagerService.DEBUG_PREFERRED)
                    Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": default!");
                haveAct = true;
                systemMatch = ri.get(i).match;
            } else {
                if (PackageManagerService.DEBUG_PREFERRED)
                    Log.d(TAG, "Result " + ai.packageName + "/" + ai.name + ": skipped");
            }
        }
        if (haveNonSys != null && thirdPartyMatch < systemMatch) {
            // If we have a matching third party app, but its match is not as
            // good as the built-in system app, then we don't want to actually
            // consider it a match because presumably the built-in app is still
            // the thing we want users to see by default.
            haveNonSys = null;
        }
        if (haveAct && haveNonSys == null) {
            IntentFilter filter = new IntentFilter();
            if (intent.getAction() != null) {
                filter.addAction(intent.getAction());
            }
            if (intent.getCategories() != null) {
                for (String cat : intent.getCategories()) {
                    filter.addCategory(cat);
                }
            }
            if ((flags & MATCH_DEFAULT_ONLY) != 0) {
                filter.addCategory(Intent.CATEGORY_DEFAULT);
            }
            if (scheme != null) {
                filter.addDataScheme(scheme);
            }
            if (ssp != null) {
                filter.addDataSchemeSpecificPart(ssp.getPath(), ssp.getType());
            }
            if (auth != null) {
                filter.addDataAuthority(auth);
            }
            if (path != null) {
                filter.addDataPath(path);
            }
            if (intent.getType() != null) {
                try {
                    filter.addDataType(intent.getType());
                } catch (IntentFilter.MalformedMimeTypeException ex) {
                    Slog.w(TAG, "Malformed mimetype " + intent.getType() + " for " + cn);
                }
            }
            PreferredActivity pa = new PreferredActivity(filter, systemMatch, set, cn, true);
            editPreferredActivitiesLPw(userId).addFilter(pa);
        } else if (haveNonSys == null) {
            StringBuilder sb = new StringBuilder();
            sb.append("No component ");
            sb.append(cn.flattenToShortString());
            sb.append(" found setting preferred ");
            sb.append(intent);
            sb.append("; possible matches are ");
            for (int i = 0; i < set.length; i++) {
                if (i > 0)
                    sb.append(", ");
                sb.append(set[i].flattenToShortString());
            }
            Slog.w(TAG, sb.toString());
        } else {
            Slog.i(TAG, "Not setting preferred " + intent + "; found third party match " + haveNonSys.flattenToShortString());
        }
    } else {
        Slog.w(TAG, "No potential matches found for " + intent + " while setting preferred " + cn.flattenToShortString());
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) IntentFilter(android.content.IntentFilter) ComponentName(android.content.ComponentName)

Example 73 with ActivityInfo

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

the class PreferredComponent method sameSet.

public boolean sameSet(List<ResolveInfo> query) {
    if (mSetPackages == null) {
        return query == null;
    }
    if (query == null) {
        return false;
    }
    final int NQ = query.size();
    final int NS = mSetPackages.length;
    int numMatch = 0;
    for (int i = 0; i < NQ; i++) {
        ResolveInfo ri = query.get(i);
        ActivityInfo ai = ri.activityInfo;
        boolean good = false;
        for (int j = 0; j < NS; j++) {
            if (mSetPackages[j].equals(ai.packageName) && mSetClasses[j].equals(ai.name)) {
                numMatch++;
                good = true;
                break;
            }
        }
        if (!good)
            return false;
    }
    return numMatch == NS;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo)

Example 74 with ActivityInfo

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

the class PackageManagerService method queryIntentReceiversInternal.

@NonNull
private List<ResolveInfo> queryIntentReceiversInternal(Intent intent, String resolvedType, int flags, int userId) {
    if (!sUserManager.exists(userId))
        return Collections.emptyList();
    flags = updateFlagsForResolve(flags, userId, intent);
    ComponentName comp = intent.getComponent();
    if (comp == null) {
        if (intent.getSelector() != null) {
            intent = intent.getSelector();
            comp = intent.getComponent();
        }
    }
    if (comp != null) {
        List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
        ActivityInfo ai = getReceiverInfo(comp, flags, userId);
        if (ai != null) {
            ResolveInfo ri = new ResolveInfo();
            ri.activityInfo = ai;
            list.add(ri);
        }
        return list;
    }
    // reader
    synchronized (mPackages) {
        String pkgName = intent.getPackage();
        if (pkgName == null) {
            return mReceivers.queryIntent(intent, resolvedType, flags, userId);
        }
        final PackageParser.Package pkg = mPackages.get(pkgName);
        if (pkg != null) {
            return mReceivers.queryIntentForPackage(intent, resolvedType, flags, pkg.receivers, userId);
        }
        return Collections.emptyList();
    }
}
Also used : EphemeralResolveInfo(android.content.pm.EphemeralResolveInfo) ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) PackageParser(android.content.pm.PackageParser) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) NonNull(android.annotation.NonNull)

Example 75 with ActivityInfo

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

the class DevicePolicyManagerService method notifyPendingSystemUpdate.

@Override
public void notifyPendingSystemUpdate(long updateReceivedTime) {
    mContext.enforceCallingOrSelfPermission(permission.NOTIFY_PENDING_SYSTEM_UPDATE, "Only the system update service can broadcast update information");
    if (UserHandle.getCallingUserId() != UserHandle.USER_SYSTEM) {
        Slog.w(LOG_TAG, "Only the system update service in the system user " + "can broadcast update information.");
        return;
    }
    Intent intent = new Intent(DeviceAdminReceiver.ACTION_NOTIFY_PENDING_SYSTEM_UPDATE);
    intent.putExtra(DeviceAdminReceiver.EXTRA_SYSTEM_UPDATE_RECEIVED_TIME, updateReceivedTime);
    synchronized (this) {
        final String deviceOwnerPackage = mOwners.hasDeviceOwner() ? mOwners.getDeviceOwnerComponent().getPackageName() : null;
        if (deviceOwnerPackage == null) {
            return;
        }
        final UserHandle deviceOwnerUser = new UserHandle(mOwners.getDeviceOwnerUserId());
        ActivityInfo[] receivers = null;
        try {
            receivers = mContext.getPackageManager().getPackageInfo(deviceOwnerPackage, PackageManager.GET_RECEIVERS).receivers;
        } catch (NameNotFoundException e) {
            Log.e(LOG_TAG, "Cannot find device owner package", e);
        }
        if (receivers != null) {
            long ident = mInjector.binderClearCallingIdentity();
            try {
                for (int i = 0; i < receivers.length; i++) {
                    if (permission.BIND_DEVICE_ADMIN.equals(receivers[i].permission)) {
                        intent.setComponent(new ComponentName(deviceOwnerPackage, receivers[i].name));
                        mContext.sendBroadcastAsUser(intent, deviceOwnerUser);
                    }
                }
            } finally {
                mInjector.binderRestoreCallingIdentity(ident);
            }
        }
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ComponentName(android.content.ComponentName) ParcelableString(com.android.internal.util.ParcelableString)

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