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

Commit e995ad15 authored by Christopher Tate's avatar Christopher Tate Committed by Android Git Automerger
Browse files

am 0b2c2b10: Merge "Support preferred activities with zero or one scheme in...

am 0b2c2b10: Merge "Support preferred activities with zero or one scheme in the filter" into klp-dev

* commit '0b2c2b10':
  Support preferred activities with zero or one scheme in the filter
parents 2f4fb5ee 0b2c2b10
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);
        }
    }