Skip to content

Commit

Permalink
Fix NPE on media message with no media.
Browse files Browse the repository at this point in the history
Fixes signalapp#3921
// FREEBIE
  • Loading branch information
moxie0 committed Aug 10, 2015
1 parent 65ac2b3 commit 82b74e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/org/thoughtcrime/securesms/components/ThumbnailView.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.bumptech.glide.DrawableTypeRequest;
import com.bumptech.glide.GenericRequestBuilder;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
Expand All @@ -32,11 +31,11 @@
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.jobs.PartProgressEvent;
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri;
import org.thoughtcrime.securesms.mms.RoundedCorners;
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.util.FutureTaskListener;
import org.thoughtcrime.securesms.util.ListenableFutureTask;
import org.thoughtcrime.securesms.mms.RoundedCorners;
import org.thoughtcrime.securesms.util.Util;

import de.greenrobot.event.EventBus;
Expand Down Expand Up @@ -245,7 +244,8 @@ public SlideDeckListener(MasterSecret masterSecret) {
public void onSuccess(final SlideDeck slideDeck) {
if (slideDeck == null) return;

final Slide slide = slideDeck.getThumbnailSlide(getContext());
final Slide slide = slideDeck.getThumbnailSlide();

if (slide != null) {
Util.runOnMain(new Runnable() {
@Override
Expand Down
3 changes: 2 additions & 1 deletion src/org/thoughtcrime/securesms/mms/SlideDeck.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.Pair;

import org.thoughtcrime.securesms.R;
Expand Down Expand Up @@ -89,7 +90,7 @@ public boolean containsMediaSlide() {
return false;
}

public Slide getThumbnailSlide(Context context) {
public @Nullable Slide getThumbnailSlide() {
for (Slide slide : slides) {
if (slide.hasImage()) {
return slide;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader;
import org.thoughtcrime.securesms.mms.Slide;
import org.thoughtcrime.securesms.mms.SlideDeck;
import org.thoughtcrime.securesms.preferences.NotificationPrivacyPreference;
import org.thoughtcrime.securesms.recipients.Recipient;
Expand Down Expand Up @@ -167,12 +168,17 @@ private void setLargeIcon(@Nullable Drawable drawable) {

private boolean hasBigPictureSlide(@Nullable ListenableFutureTask<SlideDeck> slideDeck) {
try {
return masterSecret != null &&
slideDeck != null &&
Build.VERSION.SDK_INT >= 16 &&
slideDeck.get().getThumbnailSlide(context).hasImage() &&
!slideDeck.get().getThumbnailSlide(context).isInProgress() &&
slideDeck.get().getThumbnailSlide(context).getThumbnailUri() != null;
if (masterSecret == null || slideDeck == null || Build.VERSION.SDK_INT < 16) {
return false;
}

Slide thumbnailSlide = slideDeck.get().getThumbnailSlide();

return thumbnailSlide != null &&
thumbnailSlide.hasImage() &&
!thumbnailSlide.isInProgress() &&
thumbnailSlide.getThumbnailUri() != null;

} catch (InterruptedException | ExecutionException e) {
Log.w(TAG, e);
return false;
Expand All @@ -183,7 +189,7 @@ private Bitmap getBigPicture(@NonNull MasterSecret masterSecret,
@NonNull ListenableFutureTask<SlideDeck> slideDeck)
{
try {
Uri uri = slideDeck.get().getThumbnailSlide(context).getThumbnailUri();
Uri uri = slideDeck.get().getThumbnailSlide().getThumbnailUri();

return Glide.with(context)
.load(new DecryptableStreamUriLoader.DecryptableUri(masterSecret, uri))
Expand Down

0 comments on commit 82b74e8

Please sign in to comment.