From a086a2471cb451786894a01bd1866ad9062ca750 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Wed, 28 Oct 2015 10:36:21 -0700 Subject: [PATCH] Fix crash when creating group with no avatar icon Fixes #4320 // FREEBIE --- .../thoughtcrime/securesms/GroupCreateActivity.java | 12 +++++++++--- .../thoughtcrime/securesms/recipients/Recipient.java | 6 +++--- .../securesms/recipients/RecipientFactory.java | 4 ++-- .../securesms/recipients/RecipientProvider.java | 4 ++-- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/org/thoughtcrime/securesms/GroupCreateActivity.java b/src/org/thoughtcrime/securesms/GroupCreateActivity.java index bf2a981a27..8642c0676f 100644 --- a/src/org/thoughtcrime/securesms/GroupCreateActivity.java +++ b/src/org/thoughtcrime/securesms/GroupCreateActivity.java @@ -26,6 +26,7 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; @@ -460,10 +461,12 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity { return handlePushOperation(groupId, groupName, avatar, memberE164Numbers); } - private Pair handlePushOperation(byte[] groupId, String groupName, byte[] avatar, + private Pair handlePushOperation(byte[] groupId, String groupName, + @Nullable byte[] avatar, Set e164numbers) throws InvalidNumberException { + Attachment avatarAttachment = null; String groupRecipientId = GroupUtil.getEncodedId(groupId); Recipients groupRecipient = RecipientFactory.getRecipientsFromString(this, groupRecipientId, false); @@ -474,8 +477,11 @@ public class GroupCreateActivity extends PassphraseRequiredActionBarActivity { .addAllMembers(e164numbers) .build(); - Uri avatarUri = SingleUseBlobProvider.getInstance().createUri(avatar); - Attachment avatarAttachment = new UriAttachment(avatarUri, ContentType.IMAGE_JPEG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length); + if (avatar != null) { + Uri avatarUri = SingleUseBlobProvider.getInstance().createUri(avatar); + avatarAttachment = new UriAttachment(avatarUri, ContentType.IMAGE_JPEG, AttachmentDatabase.TRANSFER_PROGRESS_DONE, avatar.length); + } + OutgoingGroupMediaMessage outgoingMessage = new OutgoingGroupMediaMessage(groupRecipient, context, avatarAttachment, System.currentTimeMillis()); long threadId = MessageSender.send(this, masterSecret, outgoingMessage, -1, false); diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index 7c8a06a208..024fe539a9 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -43,8 +43,8 @@ public class Recipient { private final long recipientId; - private String number; - private String name; + private @NonNull String number; + private @Nullable String name; private boolean stale; private ContactPhoto contactPhoto; @@ -123,7 +123,7 @@ public class Recipient { notifyListeners(); } - public String getNumber() { + public @NonNull String getNumber() { return number; } diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java b/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java index 19c8255a11..b4db393135 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientFactory.java @@ -58,11 +58,11 @@ public class RecipientFactory { return provider.getRecipients(context, ids, asynchronous); } - public static Recipient getRecipientForId(Context context, long recipientId, boolean asynchronous) { + public @NonNull static Recipient getRecipientForId(Context context, long recipientId, boolean asynchronous) { return provider.getRecipient(context, recipientId, asynchronous); } - public static Recipients getRecipientsForIds(Context context, long[] recipientIds, boolean asynchronous) { + public @NonNull static Recipients getRecipientsForIds(Context context, long[] recipientIds, boolean asynchronous) { return provider.getRecipients(context, recipientIds, asynchronous); } diff --git a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java index c50a011080..cac201fd24 100644 --- a/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java +++ b/src/org/thoughtcrime/securesms/recipients/RecipientProvider.java @@ -70,7 +70,7 @@ public class RecipientProvider { ContactColors.UNKNOWN_COLOR)); }}; - Recipient getRecipient(Context context, long recipientId, boolean asynchronous) { + @NonNull Recipient getRecipient(Context context, long recipientId, boolean asynchronous) { Recipient cachedRecipient = recipientCache.get(recipientId); if (cachedRecipient != null && !cachedRecipient.isStale()) return cachedRecipient; @@ -86,7 +86,7 @@ public class RecipientProvider { return cachedRecipient; } - Recipients getRecipients(Context context, long[] recipientIds, boolean asynchronous) { + @NonNull Recipients getRecipients(Context context, long[] recipientIds, boolean asynchronous) { Recipients cachedRecipients = recipientsCache.get(new RecipientIds(recipientIds)); if (cachedRecipients != null && !cachedRecipients.isStale()) return cachedRecipients;