@Override
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    if (isEncryptedConversation && isSingleConversation()) {
      boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
      Recipient primaryRecipient =
          getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
      boolean hasSession = Session.hasSession(this, masterSecret, primaryRecipient);

      getMenuInflater().inflate(R.menu.conversation_button_context, menu);

      if (attachmentManager.isAttachmentPresent()) {
        menu.removeItem(R.id.menu_context_send_encrypted_sms);
        menu.removeItem(R.id.menu_context_send_unencrypted_sms);
      } else {
        menu.removeItem(R.id.menu_context_send_encrypted_mms);
        menu.removeItem(R.id.menu_context_send_unencrypted_mms);
      }

      if (!isPushDestination) {
        menu.removeItem(R.id.menu_context_send_push);
      }

      if (!hasSession) {
        menu.removeItem(R.id.menu_context_send_encrypted_mms);
        menu.removeItem(R.id.menu_context_send_encrypted_sms);
      }
    }
  }
Exemple #2
0
  private void handleSentMessage(Intent intent) {
    long messageId = intent.getLongExtra("message_id", -1);
    int result = intent.getIntExtra("ResultCode", -31337);
    boolean upgraded = intent.getBooleanExtra("upgraded", false);
    boolean push = intent.getBooleanExtra("push", false);

    Log.w("SMSReceiverService", "Intent resultcode: " + result);
    Log.w("SMSReceiverService", "Running sent callback: " + messageId);

    if (result == Activity.RESULT_OK) {
      SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
      Cursor cursor = database.getMessage(messageId);
      SmsDatabase.Reader reader = database.readerFor(cursor);

      database.markAsSent(messageId);

      if (upgraded) database.markAsSecure(messageId);
      if (push) database.markAsPush(messageId);

      SmsMessageRecord record = reader.getNext();

      if (record != null && record.isEndSession()) {
        Log.w("SmsSender", "Ending session...");
        Session.abortSessionFor(context, record.getIndividualRecipient());
        KeyExchangeProcessor.broadcastSecurityUpdateEvent(context, record.getThreadId());
      }

      unregisterForRadioChanges();
    } else if (result == SmsManager.RESULT_ERROR_NO_SERVICE
        || result == SmsManager.RESULT_ERROR_RADIO_OFF) {
      DatabaseFactory.getSmsDatabase(context).markAsOutbox(messageId);
      toastHandler
          .obtainMessage(
              0, context.getString(R.string.SmsReceiver_currently_unable_to_send_your_sms_message))
          .sendToTarget();
      registerForRadioChanges();
    } else {
      long threadId = DatabaseFactory.getSmsDatabase(context).getThreadIdForMessage(messageId);
      Recipients recipients =
          DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);

      DatabaseFactory.getSmsDatabase(context).markAsSentFailed(messageId);
      MessageNotifier.notifyMessageDeliveryFailed(context, recipients, threadId);
      unregisterForRadioChanges();
    }
  }
  private void initializeSecurity() {
    TypedArray drawables = obtainStyledAttributes(SEND_ATTRIBUTES);
    Recipient primaryRecipient =
        getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
    boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
    boolean isSecureDestination =
        isSingleConversation() && Session.hasSession(this, masterSecret, primaryRecipient);

    if (isPushDestination || isSecureDestination) {
      this.isEncryptedConversation = true;
      this.characterCalculator = new EncryptedCharacterCalculator();
    } else {
      this.isEncryptedConversation = false;
      this.characterCalculator = new CharacterCalculator();
    }

    if (isPushDestination) {
      sendButton.setImageDrawable(drawables.getDrawable(0));
      setComposeTextHint(getString(R.string.conversation_activity__type_message_push));
    } else if (isSecureDestination) {
      sendButton.setImageDrawable(drawables.getDrawable(1));
      setComposeTextHint(
          attachmentManager.isAttachmentPresent()
              ? getString(R.string.conversation_activity__type_message_mms_secure)
              : getString(R.string.conversation_activity__type_message_sms_secure));
    } else {
      sendButton.setImageDrawable(drawables.getDrawable(2));
      setComposeTextHint(
          (attachmentManager.isAttachmentPresent() || !recipients.isSingleRecipient())
              ? getString(R.string.conversation_activity__type_message_mms_insecure)
              : getString(R.string.conversation_activity__type_message_sms_insecure));
    }

    drawables.recycle();

    calculateCharactersRemaining();
  }