Skip to content

Camera capture intents lack explicit URI grant flags (lint MissingExplicitUriGrant, AGP 9.5.0) #7017

Open

Description

@AndyScherzinger

Is your feature request related to a problem? Please describe.
Android Gradle Plugin 9.5.0 (c8a8297) added the lint check MissingExplicitUriGrant. On master it reports three new warnings, which is the whole increase from 14 to 17 lint warnings:

Location Intent Missing flags
ChatActivity.kt:3950 MediaStore.ACTION_IMAGE_CAPTURE with EXTRA_OUTPUT FLAG_GRANT_READ_URI_PERMISSION, FLAG_GRANT_WRITE_URI_PERMISSION
ChatActivity.kt:3982 MediaStore.ACTION_VIDEO_CAPTURE with EXTRA_OUTPUT FLAG_GRANT_READ_URI_PERMISSION, FLAG_GRANT_WRITE_URI_PERMISSION
PickImage.kt:144 MediaStore.ACTION_IMAGE_CAPTURE with EXTRA_OUTPUT (FileProvider URI) FLAG_GRANT_READ_URI_PERMISSION, FLAG_GRANT_WRITE_URI_PERMISSION

Lint message: "This intent attaches a URI but is missing FLAG_GRANT_READ_URI_PERMISSION and FLAG_GRANT_WRITE_URI_PERMISSION; the receiving app will not be granted access to the URI on Android 18 and higher."

From Android 18, the system no longer grants URI permissions automatically for send and media capture intents (ACTION_SEND, ACTION_IMAGE_CAPTURE, …) that carry a URI. Without the flags, the camera app can't write the photo or video into the file we hand it, so taking a photo or video from the chat and taking an avatar picture break. See https://goo.gle/implicit-uri-grants.

Describe the solution you'd like
Add addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) to the three intents, test photo and video capture from the chat and the avatar camera capture, and lower the lint baseline in scripts/analysis/lint-results.txt by 3.

Describe alternatives you've considered
Suppressing MissingExplicitUriGrant or keeping the raised baseline only hides a real behaviour change on Android 18.

Additional context
The lint baseline was raised from 14 to 17 in #7015 so CI passes in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions