Messaging: Migrate attachments to MediaStore

* Saving them doesn't work otherwise
* We don't have to care about MediaScanner and DownloadManager
  anymore that way, either

Fixes: https://gitlab.com/LineageOS/issues/android/-/issues/8573
Change-Id: I7a3b1dc6916feff4849bdfa2b8937460c32bc5a2
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
(cherry picked from commit 93bd39838d4a395dd710796b0e71ada1ec1f5ff2)
This commit is contained in:
Michael W
2025-04-04 16:33:58 +00:00
committed by Luca Stefani
parent 906ee2fb94
commit 3c107a2161
2 changed files with 22 additions and 40 deletions
+5 -8
View File
@@ -258,14 +258,12 @@ public class UriUtil {
/**
* Persist a piece of content from the given sourceUri, byte by byte to the
* specified output directory.
* @return the output Uri if the operation succeeded, or null if failed.
* specified targetUri.
*/
@DoesNotRunOnMainThread
public static Uri persistContent(
final Uri sourceUri, final File outputDir, final String contentType) {
public static void persistContent(
final Context context, final Uri sourceUri, final Uri targetUri) {
InputStream inputStream = null;
final Context context = Factory.get().getApplicationContext();
try {
if (UriUtil.isLocalResourceUri(sourceUri)) {
inputStream = context.getContentResolver().openInputStream(sourceUri);
@@ -273,13 +271,12 @@ public class UriUtil {
// The content is remote. Download it.
inputStream = getInputStreamFromRemoteUri(sourceUri);
if (inputStream == null) {
return null;
return;
}
}
return persistContent(inputStream, outputDir, contentType);
copyContent(context, inputStream, targetUri);
} catch (final Exception ex) {
LogUtil.e(LogUtil.BUGLE_TAG, "Error while retrieving media ", ex);
return null;
} finally {
if (inputStream != null) {
try {