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

Commit 0b2c2b10 authored by Christopher Tate's avatar Christopher Tate Committed by Android (Google) Code Review
Browse files

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

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


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