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

Commit 3062c27f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make sanitizeMediaMetadata optimization more robust" into main

parents 8b056660 bb058358
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -1266,19 +1266,8 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
                return null;
            }

            // Check if there are URIs to sanitize
            boolean hasUris = false;
            for (String key : ART_URIS) {
                if (metadata.containsKey(key)) {
                    hasUris = true;
                    break;
                }
            }
            if (!hasUris) {
                return metadata;
            }

            MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder(metadata);
            // Find all URIs that need to be sanitized
            List<String> urisToSanitize = new ArrayList<>();
            for (String key : ART_URIS) {
                String uriString = metadata.getString(key);
                if (TextUtils.isEmpty(uriString)) {
@@ -1295,8 +1284,19 @@ public class MediaSessionRecord extends MediaSessionRecordImpl implements IBinde
                            Intent.FLAG_GRANT_READ_URI_PERMISSION,
                            ContentProvider.getUserIdFromUri(uri, getUserId()));
                } catch (SecurityException e) {
                    metadataBuilder.putString(key, null);
                    urisToSanitize.add(key);
                }
            }

            // Avoid creating a Builder (and copying the metadata) if there are no URIs to
            // sanitize.
            if (urisToSanitize.isEmpty()) {
                return metadata;
            }

            MediaMetadata.Builder metadataBuilder = new MediaMetadata.Builder(metadata);
            for (String key : urisToSanitize) {
                metadataBuilder.putString(key, null);
            }
            MediaMetadata sanitizedMetadata = metadataBuilder.build();
            // sanitizedMetadata.size() guarantees that the underlying bundle is unparceled