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
Add MIME type to PersistentBlobProvider #4689
Add MIME type to PersistentBlobProvider #4689
Conversation
a713bbb
to
764ca7f
Compare
Rebased on 3.5.1 (6a18824) |
I don't 100% understand the rationale behind this change yet, but at first look we don't use shared preferences for things like that. Shared prefs should be for actual preferences, or for managing state that there is exactly one of (registered or not, registered phone number, etc...) We don't want to use them to emulate a database. |
@moxie0 , given the name, "Shared Preferences," I would agree, so I was surprised by the following from Saving Key-Value Sets | Android Developers:
That's exactly what is needed here, so I went with it given that it's a recommendation from the platform team. I totally understand if you still don't want to use it for this purpose. Since submitting this PR, I've also seen that attachment content type is stored encrypted in the database, so that's another concern that needs to be addressed. The rationale is this: without MIME type in Since I can add a new database table for |
@unrulygnu In this case I think it's a little too dynamic for shared prefs. If I had exactly 10 of something, with 10 consistent key names, I'd consider using shared prefs for that. If what we're mostly concerned about is the file extension, why don't we encode the mime type into the file extension of the file on disk that PersistentBlobProvider manages? |
Thanks for the feedback, especially today, you're awesome! I will look into this. One last question: does the attachment's content type being encrypted in the database suggest that this data (and its relationship with the URI) should be secured? Or are we ok tagging the encrypted blob with its actual content type in plaintext? Updating the PR now with a rebase. Will update within the next day or two with a better solution. Thanks again! |
764ca7f
to
debe3cf
Compare
In the AttachmentDatabase? I think only the content is encrypted there, which is mostly our policy with local storage. I have no problem with tagging the encrypted blob with its content type. |
No,
Thanks again for the clarification. I'm on it. |
ad56be5
to
afea41c
Compare
@moxie0 : updated the PR, removing the use of SharedPreferences, and instead using the file extension of the blob file to reference the blob's type. Note that the use of Problem types in issue #4536 were audio and video. Tested draft saves, sending, saving attachments, and forwarding with several subtypes of each, as well as images. All worked well on a Nexus 5. There's an unrelated regression I discovered in testing which I believe may have been introduced by bcd0895, where blob files are not being deleted when attachment send is complete. I will document this in a separate issue. Please let me know what you think. |
private static final String BLOB_DIRECTORY = "captures"; | ||
private static final String DEFAULT_EXTENSION = "blob"; | ||
private static final int MATCH = 1; | ||
private static final UriMatcher MATCHER = new UriMatcher(UriMatcher.NO_MATCH) {{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alignment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and pushed. Sorry for the obvious mistake.
afea41c
to
a59f0c4
Compare
I will get started on this tonight. |
a59f0c4
to
85474e4
Compare
@moxie0: Sorry for the delay. Persistent blob files of all types now save with just a generic Drafts with persistent blobs created before this change will use the previous URI format, as well as the previously hardcoded Tested with video and audio shared from third party apps via Let me know what you think, and whether you need any further edits or squashing. |
I'd like to encode the mime type into the file extension, not the path. I also don't want us to have some legacy URI support around forever, so let's keep the path the same and just leave those be. |
@moxie0: I know your hands are probably full, and my recent intermittence is probably making things harder. Here's a summary of the commit/review history:
Then would you like me to revert the recent commits and go back to the previous solution, using the blobs' file extensions, despite your reservations about iterating through the file list? Note that the number of persistent blob files should be very few at any given time since they exist only while the media message is in draft state. Or are you suggesting that we append a file extension to the numeric ID in the Content URI, breaking the Android Content URI convention? In my opinion, this feels less great than iterating through the persistent blob files. While I was trying to keep the impact of this PR to a minimum -- especially considering the simplicity of Having spent a lot of time on Please let me know how you'd like to proceed. |
Yes, I'd like the extension to be in the URI. I don't want to have a legacy URI format. |
85474e4
to
baa1013
Compare
@moxie0: Removed the MIME Type from the URI path, appending relevant file extension to the ID (last path segment) instead, as you directed. As I mentioned in my previous comment, this approach breaks the Android Content URI convention, which may cause problems later, such as using Tested with media shared from third party apps, as well as quick camera. Attachments save with the correct extension after sending. What do you think? |
baa1013
to
c13b3a8
Compare
Just rebased on current master (72064d8), no conflicts. |
public static final Uri CONTENT_URI = Uri.parse(URI_STRING); | ||
public static final String AUTHORITY = "org.thoughtcrime.securesms"; | ||
public static final String EXPECTED_PATH = "capture/*/*"; | ||
private static final String BLOB_DIRECTORY = "captures"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for a constant if it's only used in one place, and is designed not to be accessible from anywhere else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to string literal in 7e4eb1d.
Hmm, breaking |
We did this:
At your direction, I've delivered several approaches on fixing #4536. Although the most obvious approach we haven't tried yet is storing in the database, my previous opinion still stands:
Please let me know how you'd like to proceed. |
This reverts commit b6434c6d3891f117178984b82281ea692d245cd3. See signalapp#4689 (comment)
c13b3a8
to
7e4eb1d
Compare
lol, ok sorry for the back and forth. let's try it your way then |
… type" This reverts commit 81e5310. See signalapp#4689 (comment)
Updated, tested. Note again that the issue this PR fixes concerns video/audio shared from third party apps to Signal via Also note that per your previous directive, existing drafts with persistent blobs will be lost when users update Signal with this PR applied, due to the change in persistent blob URI:
Please let me know if you want me to squash the commits or need anything else. Thanks! |
in 3.13.0 |
Fixes signalapp/Signal-Android#4536 Closes signalapp/Signal-Android#4689 Upstream commit: signalapp/Signal-Android@a2f4785
Fixes signalapp/Signal-Android#4536 Closes signalapp/Signal-Android#4689 Upstream commit: signalapp/Signal-Android@a2f4785
Fixes #4536
See #4536 (comment) for long-winded details.