Search in sources :

Example 61 with ResolveInfo

use of android.content.pm.ResolveInfo in project platform_frameworks_base by android.

the class PackageManagerService method findPreferredActivity.

// TODO: handle preferred activities missing while user has amnesia
ResolveInfo findPreferredActivity(Intent intent, String resolvedType, int flags, List<ResolveInfo> query, int priority, boolean always, boolean removeMatches, boolean debug, int userId) {
    if (!sUserManager.exists(userId))
        return null;
    flags = updateFlagsForResolve(flags, userId, intent);
    // writer
    synchronized (mPackages) {
        if (intent.getSelector() != null) {
            intent = intent.getSelector();
        }
        if (DEBUG_PREFERRED)
            intent.addFlags(Intent.FLAG_DEBUG_LOG_RESOLUTION);
        // Try to find a matching persistent preferred activity.
        ResolveInfo pri = findPersistentPreferredActivityLP(intent, resolvedType, flags, query, debug, userId);
        // If a persistent preferred activity matched, use it.
        if (pri != null) {
            return pri;
        }
        PreferredIntentResolver pir = mSettings.mPreferredActivities.get(userId);
        // Get the list of preferred activities that handle the intent
        if (DEBUG_PREFERRED || debug)
            Slog.v(TAG, "Looking for preferred activities...");
        List<PreferredActivity> prefs = pir != null ? pir.queryIntent(intent, resolvedType, (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0, userId) : null;
        if (prefs != null && prefs.size() > 0) {
            boolean changed = false;
            try {
                // First figure out how good the original match set is.
                // We will only allow preferred activities that came
                // from the same match quality.
                int match = 0;
                if (DEBUG_PREFERRED || debug)
                    Slog.v(TAG, "Figuring out best match...");
                final int N = query.size();
                for (int j = 0; j < N; j++) {
                    final ResolveInfo ri = query.get(j);
                    if (DEBUG_PREFERRED || debug)
                        Slog.v(TAG, "Match for " + ri.activityInfo + ": 0x" + Integer.toHexString(match));
                    if (ri.match > match) {
                        match = ri.match;
                    }
                }
                if (DEBUG_PREFERRED || debug)
                    Slog.v(TAG, "Best match: 0x" + Integer.toHexString(match));
                match &= IntentFilter.MATCH_CATEGORY_MASK;
                final int M = prefs.size();
                for (int i = 0; i < M; i++) {
                    final PreferredActivity pa = prefs.get(i);
                    if (DEBUG_PREFERRED || debug) {
                        Slog.v(TAG, "Checking PreferredActivity ds=" + (pa.countDataSchemes() > 0 ? pa.getDataScheme(0) : "<none>") + "\n  component=" + pa.mPref.mComponent);
                        pa.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
                    }
                    if (pa.mPref.mMatch != match) {
                        if (DEBUG_PREFERRED || debug)
                            Slog.v(TAG, "Skipping bad match " + Integer.toHexString(pa.mPref.mMatch));
                        continue;
                    }
                    // looking for, skip it.
                    if (always && !pa.mPref.mAlways) {
                        if (DEBUG_PREFERRED || debug)
                            Slog.v(TAG, "Skipping mAlways=false entry");
                        continue;
                    }
                    final ActivityInfo ai = getActivityInfo(pa.mPref.mComponent, flags | MATCH_DISABLED_COMPONENTS | MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, userId);
                    if (DEBUG_PREFERRED || debug) {
                        Slog.v(TAG, "Found preferred activity:");
                        if (ai != null) {
                            ai.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), "  ");
                        } else {
                            Slog.v(TAG, "  null");
                        }
                    }
                    if (ai == null) {
                        // This previously registered preferred activity
                        // component is no longer known.  Most likely an update
                        // to the app was installed and in the new version this
                        // component no longer exists.  Clean it up by removing
                        // it from the preferred activities list, and skip it.
                        Slog.w(TAG, "Removing dangling preferred activity: " + pa.mPref.mComponent);
                        pir.removeFilter(pa);
                        changed = true;
                        continue;
                    }
                    for (int j = 0; j < N; j++) {
                        final ResolveInfo ri = query.get(j);
                        if (!ri.activityInfo.applicationInfo.packageName.equals(ai.applicationInfo.packageName)) {
                            continue;
                        }
                        if (!ri.activityInfo.name.equals(ai.name)) {
                            continue;
                        }
                        if (removeMatches) {
                            pir.removeFilter(pa);
                            changed = true;
                            if (DEBUG_PREFERRED) {
                                Slog.v(TAG, "Removing match " + pa.mPref.mComponent);
                            }
                            break;
                        }
                        // user their preference, if we're looking for an "always" type entry.
                        if (always && !pa.mPref.sameSet(query)) {
                            Slog.i(TAG, "Result set changed, dropping preferred activity for " + intent + " type " + resolvedType);
                            if (DEBUG_PREFERRED) {
                                Slog.v(TAG, "Removing preferred activity since set changed " + pa.mPref.mComponent);
                            }
                            pir.removeFilter(pa);
                            // Re-add the filter as a "last chosen" entry (!always)
                            PreferredActivity lastChosen = new PreferredActivity(pa, pa.mPref.mMatch, null, pa.mPref.mComponent, false);
                            pir.addFilter(lastChosen);
                            changed = true;
                            return null;
                        }
                        // Yay! Either the set matched or we're looking for the last chosen
                        if (DEBUG_PREFERRED || debug)
                            Slog.v(TAG, "Returning preferred activity: " + ri.activityInfo.packageName + "/" + ri.activityInfo.name);
                        return ri;
                    }
                }
            } finally {
                if (changed) {
                    if (DEBUG_PREFERRED) {
                        Slog.v(TAG, "Preferred activity bookkeeping changed; writing restrictions");
                    }
                    scheduleWritePackageRestrictionsLocked(userId);
                }
            }
        }
    }
    if (DEBUG_PREFERRED || debug)
        Slog.v(TAG, "No preferred activity to return");
    return null;
}
Also used : EphemeralResolveInfo(android.content.pm.EphemeralResolveInfo) ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) LogPrinter(android.util.LogPrinter)

Example 62 with ResolveInfo

use of android.content.pm.ResolveInfo in project platform_frameworks_base by android.

the class PackageManagerService method allHavePackage.

/**
     * Return true if the given list is not empty and all of its contents have
     * an activityInfo with the given package name.
     */
private boolean allHavePackage(List<ResolveInfo> list, String packageName) {
    if (ArrayUtils.isEmpty(list)) {
        return false;
    }
    for (int i = 0, N = list.size(); i < N; i++) {
        final ResolveInfo ri = list.get(i);
        final ActivityInfo ai = ri != null ? ri.activityInfo : null;
        if (ai == null || !packageName.equals(ai.packageName)) {
            return false;
        }
    }
    return true;
}
Also used : EphemeralResolveInfo(android.content.pm.EphemeralResolveInfo) ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo)

Example 63 with ResolveInfo

use of android.content.pm.ResolveInfo in project platform_frameworks_base by android.

the class PackageManagerService method getRequiredButNotReallyRequiredVerifierLPr.

@Nullable
private String getRequiredButNotReallyRequiredVerifierLPr() {
    final Intent intent = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION);
    final List<ResolveInfo> matches = queryIntentReceiversInternal(intent, PACKAGE_MIME_TYPE, MATCH_SYSTEM_ONLY | MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, UserHandle.USER_SYSTEM);
    if (matches.size() == 1) {
        return matches.get(0).getComponentInfo().packageName;
    } else if (matches.size() == 0) {
        Log.e(TAG, "There should probably be a verifier, but, none were found");
        return null;
    }
    throw new RuntimeException("There must be exactly one verifier; found " + matches);
}
Also used : EphemeralResolveInfo(android.content.pm.EphemeralResolveInfo) ResolveInfo(android.content.pm.ResolveInfo) Intent(android.content.Intent) Nullable(android.annotation.Nullable)

Example 64 with ResolveInfo

use of android.content.pm.ResolveInfo in project platform_frameworks_base by android.

the class PackageManagerShellCommand method runQueryIntentActivities.

private int runQueryIntentActivities() {
    Intent intent;
    try {
        intent = parseIntentAndUser();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    try {
        List<ResolveInfo> result = mInterface.queryIntentActivities(intent, null, 0, mTargetUser).getList();
        PrintWriter pw = getOutPrintWriter();
        if (result == null || result.size() <= 0) {
            pw.println("No activities found");
        } else {
            if (!mComponents) {
                pw.print(result.size());
                pw.println(" activities found:");
                PrintWriterPrinter pr = new PrintWriterPrinter(pw);
                for (int i = 0; i < result.size(); i++) {
                    pw.print("  Activity #");
                    pw.print(i);
                    pw.println(":");
                    printResolveInfo(pr, "    ", result.get(i), mBrief, mComponents);
                }
            } else {
                PrintWriterPrinter pr = new PrintWriterPrinter(pw);
                for (int i = 0; i < result.size(); i++) {
                    printResolveInfo(pr, "", result.get(i), mBrief, mComponents);
                }
            }
        }
    } catch (RemoteException e) {
        throw new RuntimeException("Failed calling service", e);
    }
    return 0;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PrintWriterPrinter(android.util.PrintWriterPrinter) Intent(android.content.Intent) URISyntaxException(java.net.URISyntaxException) RemoteException(android.os.RemoteException) PrintWriter(java.io.PrintWriter)

Example 65 with ResolveInfo

use of android.content.pm.ResolveInfo in project platform_frameworks_base by android.

the class PackageManagerService method setHomeActivity.

@Override
public void setHomeActivity(ComponentName comp, int userId) {
    ArrayList<ResolveInfo> homeActivities = new ArrayList<>();
    getHomeActivitiesAsUser(homeActivities, userId);
    boolean found = false;
    final int size = homeActivities.size();
    final ComponentName[] set = new ComponentName[size];
    for (int i = 0; i < size; i++) {
        final ResolveInfo candidate = homeActivities.get(i);
        final ActivityInfo info = candidate.activityInfo;
        final ComponentName activityName = new ComponentName(info.packageName, info.name);
        set[i] = activityName;
        if (!found && activityName.equals(comp)) {
            found = true;
        }
    }
    if (!found) {
        throw new IllegalArgumentException("Component " + comp + " cannot be home on user " + userId);
    }
    replacePreferredActivity(getHomeFilter(), IntentFilter.MATCH_CATEGORY_EMPTY, set, comp, userId);
}
Also used : EphemeralResolveInfo(android.content.pm.EphemeralResolveInfo) ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName)

Aggregations

ResolveInfo (android.content.pm.ResolveInfo)1211 Intent (android.content.Intent)760 PackageManager (android.content.pm.PackageManager)470 ComponentName (android.content.ComponentName)375 ActivityInfo (android.content.pm.ActivityInfo)209 ArrayList (java.util.ArrayList)205 PendingIntent (android.app.PendingIntent)159 RemoteException (android.os.RemoteException)137 ServiceInfo (android.content.pm.ServiceInfo)120 ApplicationInfo (android.content.pm.ApplicationInfo)73 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)58 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)53 Bundle (android.os.Bundle)47 HashMap (java.util.HashMap)46 IOException (java.io.IOException)43 HashSet (java.util.HashSet)43 Point (android.graphics.Point)42 ActivityNotFoundException (android.content.ActivityNotFoundException)38 PackageInfo (android.content.pm.PackageInfo)37 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)33