Don't allow sending SMS unless we're the default.

This commit is contained in:
Greyson Parrelli 2018-12-12 18:15:09 -08:00
parent 3b67382f67
commit b553bb1cb0
2 changed files with 24 additions and 0 deletions

View File

@ -177,6 +177,9 @@
<string name="ConversationActivity_signal_needs_camera_permissions_to_take_photos_or_video">Signal needs Camera permissions to take photos or video</string>
<string name="ConversationActivity_quoted_contact_message">%1$s %2$s</string>
<string name="ConversationActivity_signal_cannot_sent_sms_mms_messages_because_it_is_not_your_default_sms_app">Signal cannot send SMS/MMS messages because it is not your default SMS app. Would you like to change this in your Android settings?</string>
<string name="ConversationActivity_yes">Yes</string>
<string name="ConversationActivity_no">No</string>
<!-- ConversationAdapter -->
<plurals name="ConversationAdapter_n_unread_messages">

View File

@ -22,6 +22,7 @@ import android.annotation.TargetApi;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
@ -1855,6 +1856,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}
private ListenableFuture<Void> sendMediaMessage(final boolean forceSms, String body, SlideDeck slideDeck, List<Contact> contacts, final long expiresIn, final int subscriptionId, final boolean initiating) {
if (!isDefaultSms && (!isSecureText || forceSms)) {
showDefaultSmsPrompt();
SettableFuture<Void> future = new SettableFuture<>();
future.set(null);
return future;
}
OutgoingMediaMessage outgoingMessageCandidate = new OutgoingMediaMessage(recipient, slideDeck, body, System.currentTimeMillis(), subscriptionId, expiresIn, distributionType, inputPanel.getQuote().orNull(), contacts);
final SettableFuture<Void> future = new SettableFuture<>();
@ -1905,6 +1913,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private void sendTextMessage(final boolean forceSms, final long expiresIn, final int subscriptionId, final boolean initiatingConversation)
throws InvalidMessageException
{
if (!isDefaultSms && (!isSecureText || forceSms)) {
showDefaultSmsPrompt();
return;
}
final Context context = getApplicationContext();
final String messageBody = getMessage();
@ -1945,6 +1958,14 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
.execute();
}
private void showDefaultSmsPrompt() {
new AlertDialog.Builder(this)
.setMessage(R.string.ConversationActivity_signal_cannot_sent_sms_mms_messages_because_it_is_not_your_default_sms_app)
.setNegativeButton(R.string.ConversationActivity_no, (dialog, which) -> dialog.dismiss())
.setPositiveButton(R.string.ConversationActivity_yes, (dialog, which) -> handleMakeDefaultSms())
.show();
}
private void updateToggleButtonState() {
if (composeText.getText().length() == 0 && !attachmentManager.isAttachmentPresent()) {
buttonToggle.display(attachButton);