kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix bad flag parsing on attachment pointers.
rodzic
a4868602b5
commit
bf124b87fa
|
@ -689,7 +689,7 @@ public class ConversationActivity extends PassphraseRequiredActivity
|
|||
Objects.requireNonNull(MediaType.from(BlobProvider.getMimeType(data.getData()))),
|
||||
data.getIntExtra(GiphyActivity.EXTRA_WIDTH, 0),
|
||||
data.getIntExtra(GiphyActivity.EXTRA_HEIGHT, 0),
|
||||
data.getBooleanExtra(GiphyActivity.EXTRA_BORDERLESS, false),
|
||||
false,
|
||||
true);
|
||||
break;
|
||||
case SMS_DEFAULT:
|
||||
|
|
|
@ -164,7 +164,7 @@ public class AttachmentDatabase extends Database {
|
|||
FAST_PREFLIGHT_ID + " TEXT, " +
|
||||
VOICE_NOTE + " INTEGER DEFAULT 0, " +
|
||||
BORDERLESS + " INTEGER DEFAULT 0, " +
|
||||
VIDEO_GIF + " INTEGER DEFAULT 0, " +
|
||||
VIDEO_GIF + " INTEGER DEFAULT 0, " +
|
||||
DATA_RANDOM + " BLOB, " +
|
||||
QUOTE + " INTEGER DEFAULT 0, " +
|
||||
WIDTH + " INTEGER DEFAULT 0, " +
|
||||
|
|
|
@ -29,7 +29,6 @@ public class GiphyActivity extends PassphraseRequiredActivity implements GiphyAc
|
|||
public static final String EXTRA_WIDTH = "extra_width";
|
||||
public static final String EXTRA_HEIGHT = "extra_height";
|
||||
public static final String EXTRA_COLOR = "extra_color";
|
||||
public static final String EXTRA_BORDERLESS = "extra_borderless";
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicDarkToolbarTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
@ -97,7 +96,6 @@ public class GiphyActivity extends PassphraseRequiredActivity implements GiphyAc
|
|||
intent.setData(success.getBlobUri());
|
||||
intent.putExtra(EXTRA_WIDTH, success.getWidth());
|
||||
intent.putExtra(EXTRA_HEIGHT, success.getHeight());
|
||||
intent.putExtra(EXTRA_BORDERLESS, success.getBlobUri());
|
||||
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.net.Uri;
|
|||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||
import org.thoughtcrime.securesms.util.FeatureFlags;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
|
||||
public class GifSlide extends ImageSlide {
|
||||
|
@ -22,7 +23,23 @@ public class GifSlide extends ImageSlide {
|
|||
}
|
||||
|
||||
public GifSlide(Context context, Uri uri, long size, int width, int height, boolean borderless, @Nullable String caption) {
|
||||
super(context, constructAttachmentFromUri(context, uri, MediaUtil.IMAGE_GIF, size, width, height, true, null, caption, null, null, null, false, borderless, true, false));
|
||||
super(context, constructAttachmentFromUri(context,
|
||||
uri,
|
||||
MediaUtil.IMAGE_GIF,
|
||||
size,
|
||||
width,
|
||||
height,
|
||||
true,
|
||||
null,
|
||||
caption,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
borderless,
|
||||
FeatureFlags.mp4GifSendSupport(),
|
||||
false));
|
||||
|
||||
this.borderless = borderless;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,7 @@ import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
|
|||
import org.whispersystems.signalservice.internal.util.StaticCredentialsProvider;
|
||||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
import org.whispersystems.util.Base64;
|
||||
import org.whispersystems.util.FlagUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -1556,18 +1557,22 @@ public class SignalServiceMessageSender {
|
|||
builder.setHeight(attachment.getHeight());
|
||||
}
|
||||
|
||||
int flags = 0;
|
||||
|
||||
if (attachment.getVoiceNote()) {
|
||||
builder.setFlags(AttachmentPointer.Flags.VOICE_MESSAGE_VALUE);
|
||||
flags |= FlagUtil.toBinaryFlag(AttachmentPointer.Flags.VOICE_MESSAGE_VALUE);
|
||||
}
|
||||
|
||||
if (attachment.isBorderless()) {
|
||||
builder.setFlags(AttachmentPointer.Flags.BORDERLESS_VALUE);
|
||||
flags |= FlagUtil.toBinaryFlag(AttachmentPointer.Flags.BORDERLESS_VALUE);
|
||||
}
|
||||
|
||||
if (attachment.isGif()) {
|
||||
builder.setFlags(AttachmentPointer.Flags.GIF_VALUE);
|
||||
flags |= FlagUtil.toBinaryFlag(AttachmentPointer.Flags.GIF_VALUE);
|
||||
}
|
||||
|
||||
builder.setFlags(flags);
|
||||
|
||||
if (attachment.getCaption().isPresent()) {
|
||||
builder.setCaption(attachment.getCaption().get());
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageProt
|
|||
import org.whispersystems.signalservice.internal.serialize.SignalServiceAddressProtobufSerializer;
|
||||
import org.whispersystems.signalservice.internal.serialize.SignalServiceMetadataProtobufSerializer;
|
||||
import org.whispersystems.signalservice.internal.serialize.protos.SignalServiceContentProto;
|
||||
import org.whispersystems.util.FlagUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -976,9 +977,9 @@ public final class SignalServiceContent {
|
|||
pointer.getWidth(), pointer.getHeight(),
|
||||
pointer.hasDigest() ? Optional.of(pointer.getDigest().toByteArray()) : Optional.<byte[]>absent(),
|
||||
pointer.hasFileName() ? Optional.of(pointer.getFileName()) : Optional.<String>absent(),
|
||||
(pointer.getFlags() & SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE) != 0,
|
||||
(pointer.getFlags() & SignalServiceProtos.AttachmentPointer.Flags.BORDERLESS_VALUE) != 0,
|
||||
(pointer.getFlags() & SignalServiceProtos.AttachmentPointer.Flags.GIF_VALUE) != 0,
|
||||
(pointer.getFlags() & FlagUtil.toBinaryFlag(SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE)) != 0,
|
||||
(pointer.getFlags() & FlagUtil.toBinaryFlag(SignalServiceProtos.AttachmentPointer.Flags.BORDERLESS_VALUE)) != 0,
|
||||
(pointer.getFlags() & FlagUtil.toBinaryFlag(SignalServiceProtos.AttachmentPointer.Flags.GIF_VALUE)) != 0,
|
||||
pointer.hasCaption() ? Optional.of(pointer.getCaption()) : Optional.<String>absent(),
|
||||
pointer.hasBlurHash() ? Optional.of(pointer.getBlurHash()) : Optional.<String>absent(),
|
||||
pointer.hasUploadTimestamp() ? pointer.getUploadTimestamp() : 0);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.whispersystems.util;
|
||||
|
||||
public final class FlagUtil {
|
||||
|
||||
private FlagUtil() {}
|
||||
|
||||
/**
|
||||
* Left shift 1 by 'flag' - 1 spaces.
|
||||
*
|
||||
* Examples:
|
||||
* 1 -> 0001
|
||||
* 2 -> 0010
|
||||
* 3 -> 0100
|
||||
* 4 -> 1000
|
||||
*/
|
||||
public static int toBinaryFlag(int flag) {
|
||||
return 1 << (flag - 1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package org.whispersystems.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FlagUtilTest {
|
||||
|
||||
@Test
|
||||
public void given1_whenIConvertToBinaryFlag_thenIExpect1() {
|
||||
int expected = 1;
|
||||
|
||||
int actual = FlagUtil.toBinaryFlag(1);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void given2_whenIConvertToBinaryFlag_thenIExpect2() {
|
||||
int expected = 2;
|
||||
|
||||
int actual = FlagUtil.toBinaryFlag(2);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void given3_whenIConvertToBinaryFlag_thenIExpect4() {
|
||||
int expected = 4;
|
||||
|
||||
int actual = FlagUtil.toBinaryFlag(3);
|
||||
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue