From 7482ba3a829e91d0e9b09716243725521e4ee4ef Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 7 Dec 2023 19:48:13 +0100 Subject: [PATCH 1/3] EditPostActivity - Filter Uris to alllow only images and videos --- .../android/ui/posts/EditPostActivity.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java index 417b3d86b900..0ddb3ce21436 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostActivity.java @@ -483,7 +483,7 @@ private void newPostSetup() { private void newPostFromShareAction() { Intent intent = getIntent(); - if (isMediaTypeIntent(intent)) { + if (isMediaTypeIntent(intent, null)) { newPostSetup(); setPostMediaFromShareAction(); } else { @@ -2687,30 +2687,44 @@ private void setPostMediaFromShareAction() { // Check for shared media if (intent.hasExtra(Intent.EXTRA_STREAM)) { String action = intent.getAction(); - ArrayList sharedUris; + ArrayList sharedUris = new ArrayList<>(); if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { - sharedUris = intent.getParcelableArrayListExtra((Intent.EXTRA_STREAM)); + ArrayList potentialUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); + if (potentialUris != null) { + for (Uri uri : potentialUris) { + if (isMediaTypeIntent(intent, uri)) { + sharedUris.add(uri); + } + } + } } else { // For a single media share, we only allow images and video types - if (isMediaTypeIntent(intent)) { - sharedUris = new ArrayList<>(); + if (isMediaTypeIntent(intent, null)) { sharedUris.add(intent.getParcelableExtra(Intent.EXTRA_STREAM)); - } else { - sharedUris = null; } } - if (sharedUris != null) { + if (!sharedUris.isEmpty()) { // removing this from the intent so it doesn't insert the media items again on each Activity re-creation getIntent().removeExtra(Intent.EXTRA_STREAM); + mEditorMedia.addNewMediaItemsToEditorAsync(sharedUris, false); } } } - private boolean isMediaTypeIntent(Intent intent) { - String type = intent.getType(); + private boolean isMediaTypeIntent(@NonNull Intent intent, @Nullable Uri uri) { + String type = null; + + if (uri != null) { + String extension = MimeTypeMap.getFileExtensionFromUrl(String.valueOf(uri)); + if (extension != null) { + type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); + } + } else { + type = intent.getType(); + } return type != null && (type.startsWith("image") || type.startsWith("video")); } From c5f7c68271b4c5c34d94e37bd4c9f2568d008613 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 7 Dec 2023 19:49:21 +0100 Subject: [PATCH 2/3] ShareIntentReceiverActivity - Filter media types to allow only images and videos --- .../android/ui/ShareIntentReceiverActivity.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java index 28e219c6a5cf..2542f11dc0ab 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/ShareIntentReceiverActivity.java @@ -97,14 +97,23 @@ private void downloadExternalMedia() { if (Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction())) { ArrayList externalUris = getIntent().getParcelableArrayListExtra((Intent.EXTRA_STREAM)); for (Uri uri : externalUris) { - mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, uri)); + if (isAllowedMediaType(uri)) { + mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, uri)); + } } } else if (Intent.ACTION_SEND.equals(getIntent().getAction())) { Uri externalUri = getIntent().getParcelableExtra(Intent.EXTRA_STREAM); - mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, externalUri)); + if (isAllowedMediaType(externalUri)) { + mLocalMediaUris.add(MediaUtils.downloadExternalMedia(this, externalUri)); + } } } + private boolean isAllowedMediaType(@NonNull Uri uri) { + String filePath = MediaUtils.getRealPathFromURI(this, uri); + return MediaUtils.isValidImage(filePath) || MediaUtils.isVideo(filePath); + } + private void initShareFragment() { ShareIntentReceiverFragment shareIntentReceiverFragment = ShareIntentReceiverFragment .newInstance(!isSharingText(), loadLastUsedBlogLocalId()); From 9db5727f496b565112b4afee789d7d2a6f0d07bb Mon Sep 17 00:00:00 2001 From: Gerardo Date: Tue, 12 Dec 2023 11:10:32 +0100 Subject: [PATCH 3/3] Update Release notes --- RELEASE-NOTES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index ead6cab69f11..a645e1f85cb0 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -2,7 +2,7 @@ 24.0 ----- - +* [*] Filter media types when sharing files to the editor [https://github.com/wordpress-mobile/WordPress-Android/pull/19754] 23.9 -----