From f5f561253d56f2091cb006db11eef895f3392134 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 17:11:19 -0300 Subject: [PATCH 1/9] Add UploadWorker info logs --- .../src/main/java/org/wordpress/android/util/UploadWorker.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/util/UploadWorker.kt b/WordPress/src/main/java/org/wordpress/android/util/UploadWorker.kt index b1a67b644a10..de72c5a5f861 100644 --- a/WordPress/src/main/java/org/wordpress/android/util/UploadWorker.kt +++ b/WordPress/src/main/java/org/wordpress/android/util/UploadWorker.kt @@ -33,6 +33,7 @@ class UploadWorker( } override fun doWork(): Result { + AppLog.i(AppLog.T.MAIN, "UploadWorker started") runBlocking { val job = when (val localSiteId = inputData.getInt(WordPress.LOCAL_SITE_ID, UPLOAD_FROM_ALL_SITES)) { UPLOAD_FROM_ALL_SITES -> uploadStarter.queueUploadFromAllSites() @@ -40,6 +41,7 @@ class UploadWorker( } job?.join() } + AppLog.i(AppLog.T.MAIN, "UploadWorker finished") return Result.success() } From 741572f1c9932f9b0de8b149f050c4043e088d20 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 18:00:10 -0300 Subject: [PATCH 2/9] Add SOURCE_FOR_LOGGING in UploadService --- .../org/wordpress/android/ui/uploads/UploadService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java index 1e635849462d..bdf8ed1857d5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java @@ -66,6 +66,7 @@ public class UploadService extends Service { private static final String KEY_UPLOAD_MEDIA_FROM_EDITOR = "mediaFromEditor"; private static final String KEY_LOCAL_POST_ID = "localPostId"; private static final String KEY_SHOULD_TRACK_ANALYTICS = "shouldTrackPostAnalytics"; + private static final String KEY_SOURCE_FOR_LOGGING = "sourceForLogging"; private static @Nullable UploadService sInstance; @@ -150,6 +151,13 @@ public int onStartCommand(Intent intent, int flags, int startId) { return START_NOT_STICKY; } + if (intent.hasExtra(KEY_SOURCE_FOR_LOGGING)) { + String sourceForLogging = intent.getStringExtra(KEY_SOURCE_FOR_LOGGING); + if (sourceForLogging != null && !sourceForLogging.isEmpty()) { + AppLog.i(T.MAIN, "UploadService > Started from " + sourceForLogging); + } + } + if (intent.hasExtra(KEY_MEDIA_LIST)) { unpackMediaIntent(intent); } From 0dea702e1f311f2dce39239a93908b841906c23d Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 18:02:03 -0300 Subject: [PATCH 3/9] Add sourceForLogging to getRetryUploadServiceIntent --- .../java/org/wordpress/android/ui/posts/PostListAction.kt | 3 ++- .../org/wordpress/android/ui/uploads/PostUploadNotifier.java | 2 +- .../java/org/wordpress/android/ui/uploads/UploadService.java | 3 ++- .../org/wordpress/android/ui/uploads/UploadServiceFacade.kt | 4 ++-- .../java/org/wordpress/android/ui/uploads/UploadStarter.kt | 3 ++- .../java/org/wordpress/android/ui/uploads/UploadUtils.java | 3 ++- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListAction.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListAction.kt index b93f80c78d63..6954fe44dca5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListAction.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostListAction.kt @@ -89,7 +89,8 @@ fun handlePostListAction( val intent = UploadService.getRetryUploadServiceIntent( activity, action.post, - action.trackAnalytics + action.trackAnalytics, + "PostListAction.RetryUpload" ) activity.startService(intent) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java index c85f5ce3fc2c..a0d102e5fb73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java @@ -531,7 +531,7 @@ void updateNotificationErrorForPost(@NonNull PostModel post, @NonNull SiteModel // Add RETRY action - only available on Aztec if (AppPrefs.isAztecEditorEnabled()) { Intent publishIntent = UploadService.getRetryUploadServiceIntent(mContext, post, - PostUtils.isFirstTimePublish(post)); + PostUtils.isFirstTimePublish(post), "error notification retry action"); PendingIntent actionPendingIntent = PendingIntent.getService(mContext, 0, publishIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE); notificationBuilder.addAction(0, mContext.getString(R.string.retry), diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java index bdf8ed1857d5..2c3665bf8e8e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java @@ -344,11 +344,12 @@ private boolean isThisPostTotallyNewOrFailed(PostImmutableModel post) { } public static Intent getRetryUploadServiceIntent(Context context, @NonNull PostImmutableModel post, - boolean trackAnalytics) { + boolean trackAnalytics, String sourceForLogging) { Intent intent = new Intent(context, UploadService.class); intent.putExtra(KEY_LOCAL_POST_ID, post.getId()); intent.putExtra(KEY_SHOULD_TRACK_ANALYTICS, trackAnalytics); intent.putExtra(KEY_SHOULD_RETRY, true); + intent.putExtra(KEY_SOURCE_FOR_LOGGING, sourceForLogging); return intent; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt index 50802556799a..79a75feceb65 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt @@ -14,8 +14,8 @@ import javax.inject.Inject * contain any static methods. */ class UploadServiceFacade @Inject constructor(private val appContext: Context) { - fun uploadPost(context: Context, post: PostModel, trackAnalytics: Boolean) { - val intent = UploadService.getRetryUploadServiceIntent(context, post, trackAnalytics) + fun uploadPost(context: Context, post: PostModel, trackAnalytics: Boolean, sourceForLogging: String = "") { + val intent = UploadService.getRetryUploadServiceIntent(context, post, trackAnalytics, sourceForLogging) context.startService(intent) } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadStarter.kt b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadStarter.kt index ceca1428fc62..4a21923a967c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadStarter.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadStarter.kt @@ -175,7 +175,8 @@ class UploadStarter @Inject constructor( uploadServiceFacade.uploadPost( context = context, post = post, - trackAnalytics = false + trackAnalytics = false, + sourceForLogging = "UploadStarter#upload" ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java index 595a1066d476..114a3bfdeb7b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java @@ -490,7 +490,8 @@ public static void onPostUploadedSnackbarHandler(final Activity activity, View s @Override public void onClick(View view) { Intent intent = UploadService.getRetryUploadServiceIntent( - activity, post, false); + activity, post, false, + "error snack bar retry action"); activity.startService(intent); } }, sequencer); From 907ee8bf21b674f346c4f05654fc0ce334ecba11 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 18:03:22 -0300 Subject: [PATCH 4/9] Add sourceForLogging to getPublishPostServiceIntent --- .../org/wordpress/android/ui/uploads/PostUploadNotifier.java | 3 ++- .../java/org/wordpress/android/ui/uploads/UploadService.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java index a0d102e5fb73..3ee200256f90 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java @@ -370,7 +370,8 @@ void updateNotificationSuccessForPost(@NonNull PostImmutableModel post, @NonNull // add draft Publish action for drafts if (PostStatus.fromPost(post) == PostStatus.DRAFT || PostStatus.fromPost(post) == PostStatus.PENDING) { - Intent publishIntent = UploadService.getPublishPostServiceIntent(mContext, post, isFirstTimePublish); + Intent publishIntent = UploadService.getPublishPostServiceIntent(mContext, post, + isFirstTimePublish, "draft success notification publish action"); PendingIntent pendingIntent = PendingIntent.getService(mContext, 0, publishIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE); notificationBuilder.addAction(R.drawable.ic_posts_white_24dp, mContext.getString(R.string.button_publish), diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java index 2c3665bf8e8e..a3ef64ea3a6f 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java @@ -362,11 +362,12 @@ public static Intent getRetryUploadServiceIntent(Context context, @NonNull PostI * UploadUtils.publishPost(..) instead. */ public static Intent getPublishPostServiceIntent(Context context, @NonNull PostImmutableModel post, - boolean trackAnalytics) { + boolean trackAnalytics, String sourceForLogging) { Intent intent = new Intent(context, UploadService.class); intent.putExtra(KEY_LOCAL_POST_ID, post.getId()); intent.putExtra(KEY_SHOULD_TRACK_ANALYTICS, trackAnalytics); intent.putExtra(KEY_CHANGE_STATUS_TO_PUBLISH, true); + intent.putExtra(KEY_SOURCE_FOR_LOGGING, sourceForLogging); return intent; } From 51c6f7bbe65cc612d0938a5c66f20e6a7ee9c46b Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 18:07:17 -0300 Subject: [PATCH 5/9] Add sourceForLogging to getUploadMediaServiceIntent --- .../ui/uploads/PostUploadNotifier.java | 5 ++- .../android/ui/uploads/UploadService.java | 3 +- .../android/ui/uploads/UploadUtils.java | 41 ++++++++++--------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java index 3ee200256f90..a205977aa93c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java @@ -532,7 +532,7 @@ void updateNotificationErrorForPost(@NonNull PostModel post, @NonNull SiteModel // Add RETRY action - only available on Aztec if (AppPrefs.isAztecEditorEnabled()) { Intent publishIntent = UploadService.getRetryUploadServiceIntent(mContext, post, - PostUtils.isFirstTimePublish(post), "error notification retry action"); + PostUtils.isFirstTimePublish(post), "post error notification retry action"); PendingIntent actionPendingIntent = PendingIntent.getService(mContext, 0, publishIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE); notificationBuilder.addAction(0, mContext.getString(R.string.retry), @@ -625,7 +625,8 @@ void updateNotificationErrorForMedia(@NonNull List mediaList, @NonNu if (mediaList != null && !mediaList.isEmpty()) { ArrayList mediaListToRetry = new ArrayList<>(); mediaListToRetry.addAll(mediaList); - Intent publishIntent = UploadService.getUploadMediaServiceIntent(mContext, mediaListToRetry, true); + Intent publishIntent = UploadService.getUploadMediaServiceIntent(mContext, mediaListToRetry, + true, "media error notification retry action"); PendingIntent actionPendingIntent = PendingIntent.getService(mContext, 1, publishIntent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE); notificationBuilder.addAction(0, mContext.getString(R.string.retry), diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java index a3ef64ea3a6f..65e217f2c5e3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java @@ -372,10 +372,11 @@ public static Intent getPublishPostServiceIntent(Context context, @NonNull PostI } public static Intent getUploadMediaServiceIntent(Context context, @NonNull ArrayList mediaList, - boolean isRetry) { + boolean isRetry, String sourceForLogging) { Intent intent = new Intent(context, UploadService.class); intent.putExtra(UploadService.KEY_MEDIA_LIST, mediaList); intent.putExtra(KEY_SHOULD_RETRY, isRetry); + intent.putExtra(KEY_SOURCE_FOR_LOGGING, sourceForLogging); return intent; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java index 114a3bfdeb7b..dcf7aeb3cb63 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java @@ -486,15 +486,15 @@ public static void onPostUploadedSnackbarHandler(final Activity activity, View s // RETRY only available for Aztec if (AppPrefs.isAztecEditorEnabled()) { UploadUtils.showSnackbarError(snackbarAttachView, errorMessage, R.string.retry, - new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = UploadService.getRetryUploadServiceIntent( - activity, post, false, - "error snack bar retry action"); - activity.startService(intent); - } - }, sequencer); + new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = UploadService.getRetryUploadServiceIntent( + activity, post, false, + "post error snack bar retry action"); + activity.startService(intent); + } + }, sequencer); } else { UploadUtils.showSnackbarError(snackbarAttachView, errorMessage, sequencer); } @@ -568,17 +568,18 @@ public static void onMediaUploadedSnackbarHandler(final Activity activity, View // RETRY only available for Aztec if (mediaList != null && !mediaList.isEmpty()) { UploadUtils.showSnackbarError(snackbarAttachView, messageForUser, R.string.retry, - new View.OnClickListener() { - @Override - public void onClick(View view) { - ArrayList mediaListToRetry = new ArrayList<>(); - mediaListToRetry.addAll(mediaList); - Intent retryIntent = UploadService - .getUploadMediaServiceIntent(activity, - mediaListToRetry, true); - activity.startService(retryIntent); - } - }, sequencer); + new View.OnClickListener() { + @Override + public void onClick(View view) { + ArrayList mediaListToRetry = new ArrayList<>(); + mediaListToRetry.addAll(mediaList); + Intent retryIntent = UploadService + .getUploadMediaServiceIntent(activity, + mediaListToRetry, true, + "media error snack bar retry action"); + activity.startService(retryIntent); + } + }, sequencer); } else { UploadUtils.showSnackbarError(snackbarAttachView, messageForUser, sequencer); } From 713da809576e03a2633ef85d836cf28c80b0319f Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 18:16:16 -0300 Subject: [PATCH 6/9] Add sourceForLogging to uploadPost --- .../wordpress/android/ui/posts/PreviewStateHelper.kt | 10 ++++++++-- .../android/ui/posts/editor/StorePostViewModel.kt | 5 ++++- .../ui/stories/media/StoryMediaSaveUploadBridge.kt | 5 ++++- .../wordpress/android/ui/uploads/UploadService.java | 4 +++- .../android/ui/uploads/UploadServiceFacade.kt | 4 ++-- .../org/wordpress/android/ui/uploads/UploadUtils.java | 2 +- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PreviewStateHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/PreviewStateHelper.kt index 3dbe54e94316..ec1717593884 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PreviewStateHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PreviewStateHelper.kt @@ -56,7 +56,10 @@ class PreviewStateHelper @Inject constructor() { PostInfoType.PostNoInfo ) if (!UploadService.isPostUploadingOrQueued(post)) { - UploadService.uploadPost(activity, post.id, false) + UploadService.uploadPost( + activity, post.id, false, + "PreviewStateHelper#startUploading, isRemoteAutoSave: true" + ) } else { AppLog.d( AppLog.T.POSTS, @@ -69,7 +72,10 @@ class PreviewStateHelper @Inject constructor() { PostInfoType.PostNoInfo ) if (!UploadService.isPostUploadingOrQueued(post)) { - UploadService.uploadPost(activity, post.id, false) + UploadService.uploadPost( + activity, post.id, false, + "PreviewStateHelper#startUploading, isRemoteAutoSave: false" + ) } else { AppLog.d( AppLog.T.POSTS, diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/StorePostViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/StorePostViewModel.kt index 23871ef6a7f8..5aa35762de68 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/StorePostViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/editor/StorePostViewModel.kt @@ -85,7 +85,10 @@ class StorePostViewModel editPostRepository.getPost(), requireNotNull(siteStore.getSiteByLocalId(editPostRepository.localSiteId)) ) - uploadService.uploadPost(context, editPostRepository.id, isFirstTimePublish) + uploadService.uploadPost( + context, editPostRepository.id, isFirstTimePublish, + "StorePostViewModel#savePostOnline" + ) SAVED_ONLINE } else { SAVED_LOCALLY diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt index 16dd93c4d5a8..cc84f6fad6d1 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/media/StoryMediaSaveUploadBridge.kt @@ -216,7 +216,10 @@ class StoryMediaSaveUploadBridge @Inject constructor( editPostRepository.getPost(), site ) - uploadService.uploadPost(appContext, editPostRepository.id, true) + uploadService.uploadPost( + appContext, editPostRepository.id, true, + "StoryMediaSaveUploadBridge#addNewMediaItemsInStoryFramesToPostAsync" + ) // SAVED_ONLINE storiesTrackerHelper.trackStoryPostSavedEvent(uriList.size, site, false) } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java index 65e217f2c5e3..0b468068dfc4 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java @@ -384,11 +384,13 @@ public static Intent getUploadMediaServiceIntent(Context context, @NonNull Array * Adds a post to the queue. * @param postId * @param isFirstTimePublish true when its status changes from local draft or remote draft to published. + * @param sourceForLogging the source of the request for logging purposes. */ - public static void uploadPost(Context context, int postId, boolean isFirstTimePublish) { + public static void uploadPost(Context context, int postId, boolean isFirstTimePublish, String sourceForLogging) { Intent intent = new Intent(context, UploadService.class); intent.putExtra(KEY_LOCAL_POST_ID, postId); intent.putExtra(KEY_SHOULD_TRACK_ANALYTICS, isFirstTimePublish); + intent.putExtra(KEY_SOURCE_FOR_LOGGING, sourceForLogging); context.startService(intent); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt index 79a75feceb65..73bc908f1ed5 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt @@ -19,8 +19,8 @@ class UploadServiceFacade @Inject constructor(private val appContext: Context) { context.startService(intent) } - fun uploadPost(context: Context, postId: Int, isFirstTimePublish: Boolean) = - UploadService.uploadPost(context, postId, isFirstTimePublish) + fun uploadPost(context: Context, postId: Int, isFirstTimePublish: Boolean, sourceForLogging: String = "") = + UploadService.uploadPost(context, postId, isFirstTimePublish, sourceForLogging) fun isPostUploadingOrQueued(post: PostImmutableModel) = UploadService.isPostUploadingOrQueued(post) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java index dcf7aeb3cb63..7b10bc0a0bf7 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadUtils.java @@ -456,7 +456,7 @@ public static void publishPost(Activity activity, final PostModel post, SiteMode dispatcher.dispatch(PostActionBuilder.newUpdatePostAction(post)); if (NetworkUtils.isNetworkAvailable(activity)) { - UploadService.uploadPost(activity, post.getId(), isFirstTimePublish); + UploadService.uploadPost(activity, post.getId(), isFirstTimePublish, "UploadUtils#publishPost"); if (onPublishingCallback != null) { onPublishingCallback.onPublishing(isFirstTimePublish); } From 7f00a84ff6878c752348a86178658c04d783e0f4 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 18:20:56 -0300 Subject: [PATCH 7/9] Add sourceForLogging to uploadMedia --- .../wordpress/android/ui/media/MediaBrowserActivity.java | 2 +- .../java/org/wordpress/android/ui/mysite/MySiteFragment.kt | 4 +++- .../org/wordpress/android/ui/posts/FeaturedImageHelper.kt | 2 +- .../org/wordpress/android/ui/uploads/UploadService.java | 7 ++++--- .../wordpress/android/ui/uploads/UploadServiceFacade.kt | 4 ++-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java index 2095350c6ef1..b5d349130163 100755 --- a/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/media/MediaBrowserActivity.java @@ -1094,7 +1094,7 @@ private void addMediaToUploadService(@NonNull ArrayList mediaModels) return; } - UploadService.uploadMedia(this, mediaModels); + UploadService.uploadMedia(this, mediaModels, "MediaBrowserActivity#addMediaToUploadService"); AppRatingDialog.INSTANCE.incrementInteractions(APP_REVIEWS_EVENT_INCREMENTED_BY_UPLOADING_MEDIA); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt index 3a9d04129a03..8b62f911ca6d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/mysite/MySiteFragment.kt @@ -420,7 +420,9 @@ class MySiteFragment : Fragment(R.layout.my_site_fragment), ) showSnackbar(SnackbarMessageHolder(UiString.UiStringText(message))) } - viewModel.onMediaUpload.observeEvent(viewLifecycleOwner) { UploadService.uploadMedia(requireActivity(), it) } + viewModel.onMediaUpload.observeEvent(viewLifecycleOwner) { + UploadService.uploadMedia(requireActivity(), it, "MySiteFragment onMediaUpload") + } dialogViewModel.onInteraction.observeEvent(viewLifecycleOwner) { viewModel.onDialogInteraction(it) } viewModel.onUploadedItem.observeEvent(viewLifecycleOwner) { handleUploadedItem(it) } viewModel.onOpenJetpackInstallFullPluginOnboarding.observeEvent(viewLifecycleOwner) { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/FeaturedImageHelper.kt b/WordPress/src/main/java/org/wordpress/android/ui/posts/FeaturedImageHelper.kt index e456736aac4f..60b94145871b 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/FeaturedImageHelper.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/FeaturedImageHelper.kt @@ -75,7 +75,7 @@ class FeaturedImageHelper @Inject constructor( private fun startUploadService(media: MediaModel) { val mediaList = ArrayList() mediaList.add(media) - uploadServiceFacade.uploadMedia(mediaList) + uploadServiceFacade.uploadMedia(mediaList, "FeaturedImageHelper#startUploadService") } fun queueFeaturedImageForUpload( diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java index 0b468068dfc4..ceb5a6aa6106 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java @@ -394,20 +394,21 @@ public static void uploadPost(Context context, int postId, boolean isFirstTimePu context.startService(intent); } - public static void uploadMedia(Context context, @NonNull MediaModel media) { + public static void uploadMedia(Context context, @NonNull MediaModel media, String sourceForLogging) { ArrayList list = new ArrayList<>(); list.add(media); - uploadMedia(context, list); + uploadMedia(context, list, sourceForLogging); } - public static void uploadMedia(Context context, @NonNull ArrayList mediaList) { + public static void uploadMedia(Context context, @NonNull ArrayList mediaList, String sourceForLogging) { if (context == null) { return; } Intent intent = new Intent(context, UploadService.class); intent.putExtra(UploadService.KEY_MEDIA_LIST, mediaList); + intent.putExtra(KEY_SOURCE_FOR_LOGGING, sourceForLogging); context.startService(intent); } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt index 73bc908f1ed5..c35571c28a25 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadServiceFacade.kt @@ -31,8 +31,8 @@ class UploadServiceFacade @Inject constructor(private val appContext: Context) { fun cancelFinalNotificationForMedia(site: SiteModel) = UploadService.cancelFinalNotificationForMedia(appContext, site) - fun uploadMedia(mediaList: ArrayList) = - UploadService.uploadMedia(appContext, mediaList) + fun uploadMedia(mediaList: ArrayList, sourceForLogging: String = "") = + UploadService.uploadMedia(appContext, mediaList, sourceForLogging) fun getPendingOrInProgressFeaturedImageUploadForPost(post: PostImmutableModel): MediaModel? = UploadService.getPendingOrInProgressFeaturedImageUploadForPost(post) From 6d8ca465e51ecf4791a30e1ddcfc12f343541530 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 8 Dec 2023 18:22:42 -0300 Subject: [PATCH 8/9] Add sourceForLogging to uploadMediaFromEditor This one has a hardcoded value since, as the name implies, it is called from a few places but only from the Editor, which should be enough for the "source" identification. --- .../java/org/wordpress/android/ui/uploads/UploadService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java index ceb5a6aa6106..d4225e5ae061 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/uploads/UploadService.java @@ -420,6 +420,7 @@ public static void uploadMediaFromEditor(Context context, @NonNull ArrayList Date: Fri, 8 Dec 2023 19:37:46 -0300 Subject: [PATCH 9/9] Fix broken unit tests --- .../ui/posts/FeaturedImageHelperTest.kt | 4 +- .../ui/posts/editor/StorePostViewModelTest.kt | 3 +- .../ui/uploads/UploadStarterConcurrentTest.kt | 3 +- .../ui/uploads/UploadStarterMutexTest.kt | 2 +- .../android/ui/uploads/UploadStarterTest.kt | 42 ++++++++++++------- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/WordPress/src/test/java/org/wordpress/android/ui/posts/FeaturedImageHelperTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/posts/FeaturedImageHelperTest.kt index 5cb236479216..f3197b9ce7d9 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/posts/FeaturedImageHelperTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/posts/FeaturedImageHelperTest.kt @@ -120,7 +120,7 @@ class FeaturedImageHelperTest { // Act val mediaModel = featuredImageHelper.retryFeaturedImageUpload(mock(), mock()) // Assert - verify(uploadServiceFacade).uploadMedia(argThat { this[0] == mediaModel }) + verify(uploadServiceFacade).uploadMedia(argThat { this[0] == mediaModel }, any()) } @Test @@ -189,7 +189,7 @@ class FeaturedImageHelperTest { // Act featuredImageHelper.queueFeaturedImageForUpload(0, createSiteModel(), mock(), "") // Assert - verify(uploadServiceFacade).uploadMedia(argThat { this[0] == mediaModel }) + verify(uploadServiceFacade).uploadMedia(argThat { this[0] == mediaModel }, any()) } @Test diff --git a/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/StorePostViewModelTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/StorePostViewModelTest.kt index 5696c4d3e3dc..c4ca4d62a19b 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/StorePostViewModelTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/posts/editor/StorePostViewModelTest.kt @@ -8,6 +8,7 @@ import org.junit.Before import org.junit.Test import org.mockito.Mock import org.mockito.kotlin.any +import org.mockito.kotlin.eq import org.mockito.kotlin.verify import org.mockito.kotlin.verifyNoInteractions import org.mockito.kotlin.whenever @@ -249,7 +250,7 @@ class StorePostViewModelTest : BaseUnitTest() { verify(savePostToDbUseCase).savePostToDb(postRepository, site) assertThat(result).isEqualTo(SAVED_ONLINE) verify(postUtils).trackSavePostAnalytics(postModel, site) - verify(uploadService).uploadPost(context, postId, isFirstTimePublish) + verify(uploadService).uploadPost(eq(context), eq(postId), eq(isFirstTimePublish), any()) } @Test diff --git a/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterConcurrentTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterConcurrentTest.kt index 950b5aac3cef..c115224c6240 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterConcurrentTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterConcurrentTest.kt @@ -61,7 +61,8 @@ class UploadStarterConcurrentTest : BaseUnitTest() { verify(uploadServiceFacade, times(draftPosts.size)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any() ) } diff --git a/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterMutexTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterMutexTest.kt index 611e018567a2..7cb9128885d7 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterMutexTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterMutexTest.kt @@ -113,7 +113,7 @@ class UploadStarterMutexTest : BaseUnitTest() { .thenReturn(UploadActionUseCase.UploadAction.UPLOAD) // throw IllegalStateException when uploading post (emulate trying to start background service) - whenever(uploadServiceFacade.uploadPost(any(), any(), any())) + whenever(uploadServiceFacade.uploadPost(any(), any(), any(), any())) .thenThrow(IllegalStateException("FAKE: Not allowed to start service intent")) // ACT diff --git a/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterTest.kt b/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterTest.kt index dc8550d3e1ec..33293974af56 100644 --- a/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterTest.kt +++ b/WordPress/src/test/java/org/wordpress/android/ui/uploads/UploadStarterTest.kt @@ -143,7 +143,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(draftPosts.size + draftPages.size)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -166,7 +167,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(0)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -188,7 +190,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(draftPosts.size + draftPages.size)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -211,7 +214,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(expectedUploadPostExecutions)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -241,7 +245,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(expectedUploadPostExecutions)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -283,7 +288,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(expectedUploadPostsAndPages.size)).uploadPost( context = any(), post = argWhere { expectedUploadPostsAndPages.contains(it) }, - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) verify( uploadServiceFacade, @@ -315,7 +321,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, never()).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -333,7 +340,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, never()).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -351,7 +359,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(1)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -373,7 +382,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, never()).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -395,7 +405,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, times(1)).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -416,7 +427,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, never()).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -436,7 +448,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, never()).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) } @@ -463,7 +476,8 @@ class UploadStarterTest : BaseUnitTest() { verify(uploadServiceFacade, never()).uploadPost( context = any(), post = any(), - trackAnalytics = any() + trackAnalytics = any(), + sourceForLogging = any(), ) }