Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file attachment crash #8908

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.activity.result.ActivityResultLauncher
import im.vector.lib.core.utils.compat.getParcelableArrayListExtraCompat
import im.vector.lib.core.utils.compat.getParcelableExtraCompat
import im.vector.lib.core.utils.compat.queryIntentActivitiesCompat
import timber.log.Timber

/**
* Abstract class to provide all types of Pickers.
Expand Down Expand Up @@ -115,6 +116,14 @@ abstract class Picker<T> {
}
}
}
return selectedUriList.onEach { context.grantUriPermission(context.applicationContext.packageName, it, Intent.FLAG_GRANT_READ_URI_PERMISSION) }
selectedUriList.forEach { uri ->
try {
context.grantUriPermission(context.applicationContext.packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
} catch (e: SecurityException) {
// Handle the exception, e.g., log it or notify the user
Timber.w("Picker", "Failed to grant URI permission for $uri: ${e.message}")
Copy link
Member

Choose a reason for hiding this comment

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

If the permission is not granted, I guess the issue will appear later, when the app will try to access the file? What will happen in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use MDM, and having two containers, Personal space and Work space. Space is restricted with certain policies for accessing file in between.

Even though the explicit call grantUriPermission fails, the intent with flag Intent.FLAG_GRANT_READ_URI_PERMISSION succeed.

This ability to share files using intents with FLAG_GRANT_READ_URI_PERMISSION while grantUriPermission fails is likely a result of MDM policies that enforce strict separation between work and personal profiles. These policies are designed to protect user data while still allowing some level of interaction through standard Android intent mechanisms

Copy link
Member

Choose a reason for hiding this comment

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

OK, thanks for the clarification!

}
}
return selectedUriList
}
}
Loading