Fix NPE on media message with no media.

Fixes #3921
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-08-10 09:33:57 -07:00
parent 65ac2b3e18
commit 82b74e8ce7
3 changed files with 18 additions and 11 deletions

View File

@ -21,7 +21,6 @@ import android.widget.ImageView;
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;
@ -32,11 +31,11 @@ import org.thoughtcrime.securesms.R;
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;
@ -245,7 +244,8 @@ public class ThumbnailView extends FrameLayout {
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

View File

@ -18,6 +18,7 @@ package org.thoughtcrime.securesms.mms;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.Pair;
import org.thoughtcrime.securesms.R;
@ -89,7 +90,7 @@ public class SlideDeck {
return false;
}
public Slide getThumbnailSlide(Context context) {
public @Nullable Slide getThumbnailSlide() {
for (Slide slide : slides) {
if (slide.hasImage()) {
return slide;

View File

@ -21,6 +21,7 @@ import com.bumptech.glide.Glide;
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;
@ -167,12 +168,17 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
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;
@ -183,7 +189,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
@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))