Search in sources :

Example 71 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class ThreadDatabase method getAttachmentUriFor.

@Nullable
private Uri getAttachmentUriFor(MessageRecord record) {
    if (!record.isMms() || record.isMmsNotification() || record.isGroupAction())
        return null;
    SlideDeck slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
    Slide thumbnail = slideDeck.getThumbnailSlide();
    return thumbnail != null ? thumbnail.getThumbnailUri() : null;
}
Also used : MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Slide(org.thoughtcrime.securesms.mms.Slide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) Nullable(android.support.annotation.Nullable)

Example 72 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class GroupMessageProcessor method process.

@Nullable
public static Long process(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceDataMessage message, boolean outgoing) {
    if (!message.getGroupInfo().isPresent() || message.getGroupInfo().get().getGroupId() == null) {
        Log.w(TAG, "Received group message with no id! Ignoring...");
        return null;
    }
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    SignalServiceGroup group = message.getGroupInfo().get();
    byte[] id = group.getGroupId();
    GroupRecord record = database.getGroup(id);
    if (record != null && group.getType() == Type.UPDATE) {
        return handleGroupUpdate(context, masterSecret, envelope, group, record, outgoing);
    } else if (record == null && group.getType() == Type.UPDATE) {
        return handleGroupCreate(context, masterSecret, envelope, group, outgoing);
    } else if (record != null && group.getType() == Type.QUIT) {
        return handleGroupLeave(context, masterSecret, envelope, group, record, outgoing);
    } else if (record != null && group.getType() == Type.REQUEST_INFO) {
        return handleGroupInfoRequest(context, envelope, group, record);
    } else {
        Log.w(TAG, "Received unknown type, ignoring...");
        return null;
    }
}
Also used : GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) SignalServiceGroup(org.whispersystems.signalservice.api.messages.SignalServiceGroup) GroupRecord(org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord) Nullable(android.support.annotation.Nullable)

Example 73 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class GroupMessageProcessor method handleGroupUpdate.

@Nullable
private static Long handleGroupUpdate(@NonNull Context context, @NonNull MasterSecretUnion masterSecret, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceGroup group, @NonNull GroupRecord groupRecord, boolean outgoing) {
    GroupDatabase database = DatabaseFactory.getGroupDatabase(context);
    byte[] id = group.getGroupId();
    Set<String> recordMembers = new HashSet<>(groupRecord.getMembers());
    Set<String> messageMembers = new HashSet<>(group.getMembers().get());
    Set<String> addedMembers = new HashSet<>(messageMembers);
    addedMembers.removeAll(recordMembers);
    Set<String> missingMembers = new HashSet<>(recordMembers);
    missingMembers.removeAll(messageMembers);
    GroupContext.Builder builder = createGroupContext(group);
    builder.setType(GroupContext.Type.UPDATE);
    if (addedMembers.size() > 0) {
        Set<String> unionMembers = new HashSet<>(recordMembers);
        unionMembers.addAll(messageMembers);
        database.updateMembers(id, new LinkedList<>(unionMembers));
        builder.clearMembers().addAllMembers(addedMembers);
    } else {
        builder.clearMembers();
    }
    if (missingMembers.size() > 0) {
    // TODO We should tell added and missing about each-other.
    }
    if (group.getName().isPresent() || group.getAvatar().isPresent()) {
        SignalServiceAttachment avatar = group.getAvatar().orNull();
        database.update(id, group.getName().orNull(), avatar != null ? avatar.asPointer() : null);
    }
    if (group.getName().isPresent() && group.getName().get().equals(groupRecord.getTitle())) {
        builder.clearName();
    }
    if (!groupRecord.isActive())
        database.setActive(id, true);
    return storeMessage(context, masterSecret, envelope, group, builder.build(), outgoing);
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) GroupDatabase(org.thoughtcrime.securesms.database.GroupDatabase) ByteString(com.google.protobuf.ByteString) GroupContext(org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext) HashSet(java.util.HashSet) Nullable(android.support.annotation.Nullable)

Example 74 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class IncomingLollipopMmsConnection method retrieve.

@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized RetrieveConf retrieve(@NonNull String contentLocation, byte[] transactionId, int subscriptionId) throws MmsException {
    beginTransaction();
    try {
        MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
        Log.w(TAG, "downloading multimedia from " + contentLocation + " to " + pointer.getUri());
        SmsManager smsManager;
        if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
            smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
        } else {
            smsManager = SmsManager.getDefault();
        }
        smsManager.downloadMultimediaMessage(getContext(), contentLocation, pointer.getUri(), null, getPendingIntent());
        waitForResult();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Util.copy(pointer.getInputStream(), baos);
        pointer.close();
        Log.w(TAG, baos.size() + "-byte response: " + Hex.dump(baos.toByteArray()));
        return (RetrieveConf) new PduParser(baos.toByteArray()).parse();
    } catch (IOException | TimeoutException e) {
        Log.w(TAG, e);
        throw new MmsException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) PduParser(ws.com.google.android.mms.pdu.PduParser) MmsException(ws.com.google.android.mms.MmsException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) RetrieveConf(ws.com.google.android.mms.pdu.RetrieveConf) SmsManager(android.telephony.SmsManager) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(android.support.annotation.Nullable)

Example 75 with Nullable

use of android.support.annotation.Nullable in project Signal-Android by WhisperSystems.

the class OutgoingLollipopMmsConnection method send.

@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
@Nullable
public synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId) throws UndeliverableMessageException {
    beginTransaction();
    try {
        MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
        Util.copy(new ByteArrayInputStream(pduBytes), pointer.getOutputStream());
        SmsManager smsManager;
        if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
            smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
        } else {
            smsManager = SmsManager.getDefault();
        }
        smsManager.sendMultimediaMessage(getContext(), pointer.getUri(), null, null, getPendingIntent());
        waitForResult();
        Log.w(TAG, "MMS broadcast received and processed.");
        pointer.close();
        if (response == null) {
            throw new UndeliverableMessageException("Null response.");
        }
        return (SendConf) new PduParser(response).parse();
    } catch (IOException | TimeoutException e) {
        throw new UndeliverableMessageException(e);
    } finally {
        endTransaction();
    }
}
Also used : MmsBodyProvider(org.thoughtcrime.securesms.providers.MmsBodyProvider) SendConf(ws.com.google.android.mms.pdu.SendConf) PduParser(ws.com.google.android.mms.pdu.PduParser) ByteArrayInputStream(java.io.ByteArrayInputStream) UndeliverableMessageException(org.thoughtcrime.securesms.transport.UndeliverableMessageException) IOException(java.io.IOException) SmsManager(android.telephony.SmsManager) TimeoutException(java.util.concurrent.TimeoutException) TargetApi(android.annotation.TargetApi) Nullable(android.support.annotation.Nullable)

Aggregations

Nullable (android.support.annotation.Nullable)582 View (android.view.View)315 TextView (android.widget.TextView)163 RecyclerView (android.support.v7.widget.RecyclerView)85 BindView (butterknife.BindView)57 ImageView (android.widget.ImageView)52 ArrayList (java.util.ArrayList)43 IOException (java.io.IOException)36 Bundle (android.os.Bundle)35 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)35 Intent (android.content.Intent)32 ViewGroup (android.view.ViewGroup)32 Cursor (android.database.Cursor)29 Uri (android.net.Uri)27 File (java.io.File)24 AdapterView (android.widget.AdapterView)22 List (java.util.List)20 NonNull (android.support.annotation.NonNull)19 Context (android.content.Context)15 Bitmap (android.graphics.Bitmap)15