Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 087044c9 authored by Christopher Tate's avatar Christopher Tate
Browse files

Support preferred activities with zero or one scheme in the filter

Also use the existing full PreferredActivity match machinery instead
of the existing direct comparison now that the intent filters can
be more flexible.

Bug 11482259

Change-Id: Icb649ca60ecfbdb9ee3c256ee512d3f3f989e05f
parent 596e409e
Loading
Loading
Loading
Loading
+20 −26
Original line number Diff line number Diff line
@@ -10011,11 +10011,11 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        if (filter.countDataAuthorities() != 0
                || filter.countDataPaths() != 0
                || filter.countDataSchemes() != 0
                || filter.countDataSchemes() > 1
                || filter.countDataTypes() != 0) {
            throw new IllegalArgumentException(
                    "replacePreferredActivity expects filter to have no data authorities, " +
                    "paths, schemes or types.");
                    "paths, or types; and at most one scheme.");
        }
        synchronized (mPackages) {
            if (mContext.checkCallingOrSelfPermission(
@@ -10032,35 +10032,29 @@ public class PackageManagerService extends IPackageManager.Stub {
            }

            final int callingUserId = UserHandle.getCallingUserId();
            ArrayList<PreferredActivity> removed = null;
            PreferredIntentResolver pir = mSettings.mPreferredActivities.get(callingUserId);
            if (pir != null) {
                Iterator<PreferredActivity> it = pir.filterIterator();
                String action = filter.getAction(0);
                String category = filter.getCategory(0);
                while (it.hasNext()) {
                    PreferredActivity pa = it.next();
                    if ((pa.countActions() == 0) || (pa.countCategories() == 0)
                            || (pa.getAction(0).equals(action)
                                    && pa.getCategory(0).equals(category))) {
                        if (removed == null) {
                            removed = new ArrayList<PreferredActivity>();
                Intent intent = new Intent(filter.getAction(0)).addCategory(filter.getCategory(0));
                if (filter.countDataSchemes() == 1) {
                    Uri.Builder builder = new Uri.Builder();
                    builder.scheme(filter.getDataScheme(0));
                    intent.setData(builder.build());
                }
                List<PreferredActivity> matches = pir.queryIntent(
                        intent, null, true, callingUserId);
                if (DEBUG_PREFERRED) {
                    Slog.i(TAG, matches.size() + " preferred matches for " + intent);
                }
                        removed.add(pa);
                for (int i = 0; i < matches.size(); i++) {
                    PreferredActivity pa = matches.get(i);
                    if (DEBUG_PREFERRED) {
                        Slog.i(TAG, "Removing preferred activity "
                                + pa.mPref.mComponent + ":");
                        filter.dump(new LogPrinter(Log.INFO, TAG), "  ");
                    }
                    }
                }
                if (removed != null) {
                    for (int i=0; i<removed.size(); i++) {
                        PreferredActivity pa = removed.get(i);
                    pir.removeFilter(pa);
                }
            }
            }
            addPreferredActivityInternal(filter, match, set, activity, true, callingUserId);
        }
    }