@Override
 public void onResume() {
   super.onResume();
   dynamicTheme.onResume(this);
   dynamicLanguage.onResume(this);
   getSupportActionBar().setTitle(R.string.GroupCreateActivity_actionbar_title);
   if (!TextSecurePreferences.isPushRegistered(this)) {
     disableWhisperGroupUi(R.string.GroupCreateActivity_you_dont_support_push);
   }
 }
  private Pair<Long, Recipients> handleCreatePushGroup(
      String groupName, byte[] avatar, Set<Recipient> members)
      throws InvalidNumberException, MmsException {
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(this);
    byte[] groupId = groupDatabase.allocateGroupId();
    Set<String> memberE164Numbers = getE164Numbers(members);

    memberE164Numbers.add(TextSecurePreferences.getLocalNumber(this));

    groupDatabase.create(groupId, groupName, new LinkedList<String>(memberE164Numbers), null, null);
    groupDatabase.updateAvatar(groupId, avatar);

    return handlePushOperation(groupId, groupName, avatar, memberE164Numbers);
  }
Esempio n. 3
0
  private void handleMessage(
      MasterSecret masterSecret, TextSecureEnvelope envelope, Optional<Long> smsMessageId) {
    try {
      AxolotlStore axolotlStore = new TextSecureAxolotlStore(context, masterSecret);
      TextSecureAddress localAddress =
          new TextSecureAddress(TextSecurePreferences.getLocalNumber(context));
      TextSecureSMPCipher cipher = new TextSecureSMPCipher(localAddress, axolotlStore);

      TextSecureSMPMessage message = cipher.decrypt(envelope);

      Log.d(TAG, "handleMessage() isSMPMessage: " + message.isSMPMessage());

      if (message.isEndSession())
        handleEndSessionMessage(masterSecret, envelope, message, smsMessageId);
      else if (message.isGroupUpdate())
        handleGroupMessage(masterSecret, envelope, message, smsMessageId);
      else if (message.getAttachments().isPresent())
        handleMediaMessage(masterSecret, envelope, message, smsMessageId);

      // TODO: handleSMPMessage
      else if (message.isSMPMessage()) handleSMPMessage(masterSecret, envelope, message);
      else handleTextMessage(masterSecret, envelope, message, smsMessageId);

      if (envelope.isPreKeyWhisperMessage()) {
        ApplicationContext.getInstance(context).getJobManager().add(new RefreshPreKeysJob(context));
      }
    } catch (InvalidVersionException e) {
      Log.w(TAG, e);
      handleInvalidVersionMessage(masterSecret, envelope, smsMessageId);
    } catch (InvalidMessageException
        | InvalidKeyIdException
        | InvalidKeyException
        | MmsException e) {
      Log.w(TAG, e);
      handleCorruptMessage(masterSecret, envelope, smsMessageId);
    } catch (NoSessionException e) {
      Log.w(TAG, e);
      handleNoSessionMessage(masterSecret, envelope, smsMessageId);
    } catch (LegacyMessageException e) {
      Log.w(TAG, e);
      handleLegacyMessage(masterSecret, envelope, smsMessageId);
    } catch (DuplicateMessageException e) {
      Log.w(TAG, e);
      handleDuplicateMessage(masterSecret, envelope, smsMessageId);
    } catch (UntrustedIdentityException e) {
      Log.w(TAG, e);
      handleUntrustedIdentityMessage(masterSecret, envelope, smsMessageId);
    }
  }
  private Pair<Long, Recipients> handleUpdatePushGroup(
      byte[] groupId, String groupName, byte[] avatar, Set<Recipient> members)
      throws InvalidNumberException, MmsException {
    GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(this);
    Set<String> memberE164Numbers = getE164Numbers(members);
    memberE164Numbers.add(TextSecurePreferences.getLocalNumber(this));

    for (String number : memberE164Numbers) Log.w(TAG, "Updating: " + number);

    groupDatabase.updateMembers(groupId, new LinkedList<String>(memberE164Numbers));
    groupDatabase.updateTitle(groupId, groupName);
    groupDatabase.updateAvatar(groupId, avatar);

    return handlePushOperation(groupId, groupName, avatar, memberE164Numbers);
  }
Esempio n. 5
0
  private Pair<Long, Long> insertStandardMediaMessage(
      MasterSecret masterSecret, TextSecureEnvelope envelope, TextSecureMessage message)
      throws MmsException {
    MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
    String localNumber = TextSecurePreferences.getLocalNumber(context);
    IncomingMediaMessage mediaMessage =
        new IncomingMediaMessage(
            masterSecret,
            envelope.getSource(),
            localNumber,
            message.getTimestamp(),
            Optional.fromNullable(envelope.getRelay()),
            message.getBody(),
            message.getGroupInfo(),
            message.getAttachments());

    return database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);
  }