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

Commit 8f3b9053 authored by William Loh's avatar William Loh Committed by Android (Google) Code Review
Browse files

Merge "Limit length and number of MIME types you can set"

parents 76725a05 b0d5aea9
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -5801,6 +5801,11 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            final Computer snapshot = snapshotComputer();
            enforceOwnerRights(snapshot, packageName, Binder.getCallingUid());
            mimeTypes = CollectionUtils.emptyIfNull(mimeTypes);
            for (String mimeType : mimeTypes) {
                if (mimeType.length() > 255) {
                    throw new IllegalArgumentException("MIME type length exceeds 255 characters");
                }
            }
            final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
            Set<String> existingMimeTypes = packageState.getMimeGroups().get(mimeGroup);
            if (existingMimeTypes == null) {
@@ -5811,6 +5816,10 @@ public class PackageManagerService implements PackageSender, TestUtilityService
                    && existingMimeTypes.containsAll(mimeTypes)) {
                return;
            }
            if (mimeTypes.size() > 500) {
                throw new IllegalStateException("Max limit on MIME types for MIME group "
                        + mimeGroup + " exceeded for package " + packageName);
            }

            ArraySet<String> mimeTypesSet = new ArraySet<>(mimeTypes);
            commitPackageStateMutation(null, packageName, packageStateWrite -> {
+3 −0
Original line number Diff line number Diff line
@@ -545,6 +545,9 @@ public class PackageImpl implements ParsedPackage, AndroidPackage,
        for (int i = component.getIntents().size() - 1; i >= 0; i--) {
            IntentFilter filter = component.getIntents().get(i).getIntentFilter();
            for (int groupIndex = filter.countMimeGroups() - 1; groupIndex >= 0; groupIndex--) {
                if (mimeGroups != null && mimeGroups.size() > 500) {
                    throw new IllegalStateException("Max limit on number of MIME Groups reached");
                }
                mimeGroups = ArrayUtils.add(mimeGroups, filter.getMimeGroup(groupIndex));
            }
        }