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 NPE in UploadService #10388

Merged
merged 1 commit into from
Aug 20, 2019
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 @@ -385,7 +385,8 @@ public static void uploadMediaFromEditor(Context context, @NonNull ArrayList<Med
* waiting for media to finish uploading counts as 'waiting to be uploaded' until the media uploads complete.
*/
public static boolean isPostUploadingOrQueued(PostModel post) {
if (sInstance == null || post == null) {
UploadService instance = sInstance;
if (instance == null || post == null) {
return false;
}

Expand All @@ -395,7 +396,7 @@ public static boolean isPostUploadingOrQueued(PostModel post) {
}
mkevins marked this conversation as resolved.
Show resolved Hide resolved

// Then check the list of posts waiting for media to complete
return sInstance.mUploadStore.isPendingPost(post);
return instance.mUploadStore.isPendingPost(post);
}

public static boolean isPostQueued(PostModel post) {
Expand Down Expand Up @@ -495,12 +496,13 @@ public static boolean hasPendingOrInProgressPostUploads() {
}

public static float getMediaUploadProgressForPost(PostModel postModel) {
if (postModel == null || sInstance == null) {
UploadService instance = sInstance;
if (postModel == null || instance == null) {
// If the UploadService isn't running, there's no progress for this post
return 0;
}

Set<MediaModel> pendingMediaList = sInstance.mUploadStore.getUploadingMediaForPost(postModel);
Set<MediaModel> pendingMediaList = instance.mUploadStore.getUploadingMediaForPost(postModel);

if (pendingMediaList.size() == 0) {
return 1;
Expand All @@ -516,12 +518,13 @@ public static float getMediaUploadProgressForPost(PostModel postModel) {
}

public static float getUploadProgressForMedia(MediaModel mediaModel) {
if (mediaModel == null || sInstance == null) {
UploadService instance = sInstance;
if (mediaModel == null || instance == null) {
// If the UploadService isn't running, there's no progress for this media
return 0;
}

float uploadProgress = sInstance.mUploadStore.getUploadProgressForMedia(mediaModel);
float uploadProgress = instance.mUploadStore.getUploadProgressForMedia(mediaModel);

// If this is a video and video optimization is enabled, include the optimization progress in the outcome
if (mediaModel.isVideo() && WPMediaUtils.isVideoOptimizationEnabled()) {
Expand All @@ -533,10 +536,11 @@ public static float getUploadProgressForMedia(MediaModel mediaModel) {

public static @NonNull
Set<MediaModel> getPendingMediaForPost(PostModel postModel) {
if (postModel == null || sInstance == null) {
UploadService instance = sInstance;
if (postModel == null || instance == null) {
return Collections.emptySet();
}
return sInstance.mUploadStore.getUploadingMediaForPost(postModel);
return instance.mUploadStore.getUploadingMediaForPost(postModel);
}

public static boolean isPendingOrInProgressMediaUpload(@NonNull MediaModel media) {
Expand Down