Skip to content

Conversation

@RitikaPahwa4444
Copy link
Collaborator

Description (required)

Fixes #6357

What changes did you make and why?

Handled java.lang.SecurityException for a multi upload by taking persistable permission for all the URIs.

Tests performed (required)

Tested prodDebug on moto g34 5G with API level 34.

Screenshots (for UI changes only)

Need help? See https://support.google.com/android/answer/9075928


Note: Please ensure that you have read CONTRIBUTING.md if this is your first pull request.

@RitikaPahwa4444 RitikaPahwa4444 marked this pull request as draft August 16, 2025 19:41
@RitikaPahwa4444
Copy link
Collaborator Author

RitikaPahwa4444 commented Aug 17, 2025

Called the function for other upload methods as well. Cases to be tested:

  • Document picker
  • Secure photo picker
  • Custom selector (not required)
  • In-app camera upload (not required)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a SecurityException that occurs during multi-file uploads by properly managing persistable URI permissions for multiple selected files. The issue was that the app wasn't taking persistable permissions for all URIs when multiple files were selected, causing security exceptions during upload processing.

  • Enhanced URI permission handling to support multiple selected files in clip data
  • Added proper cleanup of persistable URI permissions after successful uploads
  • Updated permission flags to only request read permissions instead of read/write

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
FilePicker.kt Enhanced takePersistableUriPermissions to handle multiple URIs from clip data and added permission taking for gallery selections
UploadWorker.kt Added cleanup logic to release persistable URI permissions after successful uploads

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions
Copy link

✅ Generated APK variants!

showSuccessNotification(contribution)
if (appContext.contentResolver.persistedUriPermissions.any {
it.uri == contribution.contentUri }) {
appContext.contentResolver.releasePersistableUriPermission(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@misaochan misaochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't reproduce the crash but LGTM. Seems like CI has been failing prior to this PR anyway.

@misaochan misaochan merged commit a892aa6 into main Aug 19, 2025
1 of 2 checks passed
@RitikaPahwa4444
Copy link
Collaborator Author

Thanks @misaochan for reviewing the code. @nicolas-raoul was testing these changes and would be able to confirm if they helped fix the crash he'd been experiencing.

Seems like CI has been failing prior to this PR anyway.

Unfortunately, the CI has been failing since 2023 if I remember correctly 😞 The instrumented tests need a major overhaul as things have changed significantly in the last two years. We have an issue for the same to begin in an incremental way, let me look into this once the update for this month goes out.

@sivaraam
Copy link
Member

Unfortunately, the CI has been failing since 2023 if I remember correctly 😞 The instrumented tests need a major overhaul as things have changed significantly in the last two years. We have an issue for the same to begin in an incremental way, let me look into this once the update for this month goes out.

Indeed. The CI failing since long time has always been a bummer. Would it possibly be fine to disable the instrumentation tests alone until we get around to properly fixing it? That way I think we could at least ensure the unit tests pass successfully 🤔

@RitikaPahwa4444
Copy link
Collaborator Author

Thank you, @sivaraam, it sounds even simpler to disable all the instrumented tests instead of looking for the failing ones. I'll pick this up after this month's release. Issue to track this: #6269.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java.lang.SecurityException for ACTION_OPEN_DOCUMENT

4 participants