Add preference to disable the SMS channel all together.

1) If the SMS fallback preference is disabled, no outgoing
   messages will succeed via the SMS transport.

2) If the SMS fallback preference is disabled, "mirroring" the
   SMS db state when not the default system SMS app is disabled.
This commit is contained in:
Moxie Marlinspike 2014-02-20 14:49:31 -08:00
parent c5821f770a
commit 918f223149
8 changed files with 66 additions and 14 deletions

View File

@ -678,6 +678,8 @@
<string name="preferences__use_the_data_channel_for_communication_with_other_textsecure_users"> <string name="preferences__use_the_data_channel_for_communication_with_other_textsecure_users">
Use the data channel for communication with other TextSecure users Use the data channel for communication with other TextSecure users
</string> </string>
<string name="preferences__allow_sms_fallback">Allow SMS Fallback</string>
<string name="preferences__send_and_receive_sms_messages_when_push_is_not_available">Send and receive SMS messages when push is not available</string>
<!-- **************************************** --> <!-- **************************************** -->
<!-- menus --> <!-- menus -->

View File

@ -16,16 +16,22 @@
android:title="@string/preferences__make_default_sms_app" android:title="@string/preferences__make_default_sms_app"
android:summary="@string/preferences__make_textsecure_the_default_sms_mms_app" /> android:summary="@string/preferences__make_textsecure_the_default_sms_mms_app" />
<CheckBoxPreference android:defaultValue="false" <!--<CheckBoxPreference android:defaultValue="false"-->
android:key="pref_delivery_report_sms" <!--android:key="pref_delivery_report_sms"-->
android:summary="@string/preferences__request_a_delivery_report_for_each_sms_message_you_send" <!--android:summary="@string/preferences__request_a_delivery_report_for_each_sms_message_you_send"-->
android:title="@string/preferences__sms_delivery_reports" /> <!--android:title="@string/preferences__sms_delivery_reports" />-->
<CheckBoxPreference android:defaultValue="false" <CheckBoxPreference android:defaultValue="false"
android:key="pref_toggle_push_messaging" android:key="pref_toggle_push_messaging"
android:title="@string/preferences__use_data_channel" android:title="@string/preferences__use_data_channel"
android:summary="@string/preferences__use_the_data_channel_for_communication_with_other_textsecure_users"/> android:summary="@string/preferences__use_the_data_channel_for_communication_with_other_textsecure_users"/>
<CheckBoxPreference android:defaultValue="true"
android:enabled="false"
android:key="pref_allow_sms_traffic_out"
android:title="@string/preferences__allow_sms_fallback"
android:summary="@string/preferences__send_and_receive_sms_messages_when_push_is_not_available"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/preferences__notifications"> <PreferenceCategory android:title="@string/preferences__notifications">
<CheckBoxPreference android:key="pref_key_enable_notifications" <CheckBoxPreference android:key="pref_key_enable_notifications"

View File

@ -100,6 +100,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
initializeIdentitySelection(); initializeIdentitySelection();
initializePlatformSpecificOptions(); initializePlatformSpecificOptions();
initializeSmsFallbackOption();
initializePushMessagingToggle(); initializePushMessagingToggle();
this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF) this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF)
@ -178,8 +179,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
} }
private void initializePlatformSpecificOptions() { private void initializePlatformSpecificOptions() {
PreferenceGroup generalCategory = (PreferenceGroup)findPreference("general_category"); PreferenceGroup generalCategory = (PreferenceGroup) findPreference("general_category");
Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF); Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
generalCategory.removePreference(findPreference(TextSecurePreferences.ALL_SMS_PREF)); generalCategory.removePreference(findPreference(TextSecurePreferences.ALL_SMS_PREF));
@ -198,6 +199,29 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
} }
} }
private void initializeSmsFallbackOption() {
CheckBoxPreference allowSmsPreference =
(CheckBoxPreference) findPreference(TextSecurePreferences.ALLOW_SMS_FALLBACK_PREF);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (Util.isDefaultSmsProvider(this) || !TextSecurePreferences.isPushRegistered(this)) {
allowSmsPreference.setEnabled(false);
allowSmsPreference.setChecked(true);
} else {
allowSmsPreference.setEnabled(true);
}
} else {
if (TextSecurePreferences.isInterceptAllMmsEnabled(this) ||
TextSecurePreferences.isInterceptAllSmsEnabled(this))
{
allowSmsPreference.setEnabled(false);
allowSmsPreference.setChecked(true);
} else {
allowSmsPreference.setEnabled(true);
}
}
}
private void initializeEditTextSummary(final EditTextPreference preference) { private void initializeEditTextSummary(final EditTextPreference preference) {
if (preference.getText() == null) { if (preference.getText() == null) {
preference.setSummary("Not set"); preference.setSummary("Not set");
@ -268,6 +292,10 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
dynamicTheme.onResume(this); dynamicTheme.onResume(this);
} else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) { } else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) {
dynamicLanguage.onResume(this); dynamicLanguage.onResume(this);
} else if (key.equals(TextSecurePreferences.ALL_MMS_PREF) ||
key.equals(TextSecurePreferences.ALL_SMS_PREF))
{
initializeSmsFallbackOption();
} }
} }

View File

@ -20,14 +20,12 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.preference.PreferenceManager;
import android.provider.Telephony; import android.provider.Telephony;
import android.util.Log; import android.util.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.protocol.WirePrefix; import org.thoughtcrime.securesms.protocol.WirePrefix;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Util;
import ws.com.google.android.mms.pdu.GenericPdu; import ws.com.google.android.mms.pdu.GenericPdu;
import ws.com.google.android.mms.pdu.NotificationInd; import ws.com.google.android.mms.pdu.NotificationInd;
@ -52,7 +50,8 @@ public class MmsListener extends BroadcastReceiver {
return false; return false;
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT || if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
TextSecurePreferences.isSmsFallbackEnabled(context)) ||
TextSecurePreferences.isInterceptAllMmsEnabled(context)) TextSecurePreferences.isInterceptAllMmsEnabled(context))
{ {
return true; return true;

View File

@ -110,7 +110,8 @@ public class SmsListener extends BroadcastReceiver {
return false; return false;
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT || if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT &&
TextSecurePreferences.isSmsFallbackEnabled(context)) ||
TextSecurePreferences.isInterceptAllSmsEnabled(context)) TextSecurePreferences.isInterceptAllSmsEnabled(context))
{ {
return true; return true;
@ -120,8 +121,7 @@ public class SmsListener extends BroadcastReceiver {
} }
private boolean isChallenge(Context context, Intent intent) { private boolean isChallenge(Context context, Intent intent) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String messageBody = getSmsMessageBodyFromIntent(intent);
String messageBody = getSmsMessageBodyFromIntent(intent);
if (messageBody == null) if (messageBody == null)
return false; return false;

View File

@ -48,6 +48,12 @@ public class SmsTransport extends BaseTransport {
} }
public void deliver(SmsMessageRecord message) throws UndeliverableMessageException { public void deliver(SmsMessageRecord message) throws UndeliverableMessageException {
if (TextSecurePreferences.isPushRegistered(context) &&
!TextSecurePreferences.isSmsFallbackEnabled(context))
{
throw new UndeliverableMessageException("SMS Transport is not enabled!");
}
if (message.isSecure() || message.isKeyExchange() || message.isEndSession()) { if (message.isSecure() || message.isKeyExchange() || message.isEndSession()) {
deliverSecureMessage(message); deliverSecureMessage(message);
} else { } else {

View File

@ -214,6 +214,12 @@ public class UniversalTransport {
return false; return false;
} }
if (TextSecurePreferences.isPushRegistered(context) &&
!TextSecurePreferences.isSmsFallbackEnabled(context))
{
return false;
}
Directory directory = Directory.getInstance(context); Directory directory = Directory.getInstance(context);
return directory.isSmsFallbackSupported(destination); return directory.isSmsFallbackSupported(destination);
} }

View File

@ -44,6 +44,11 @@ public class TextSecurePreferences {
private static final String IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications"; private static final String IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications";
private static final String LOCAL_REGISTRATION_ID_PREF = "pref_local_registration_id"; private static final String LOCAL_REGISTRATION_ID_PREF = "pref_local_registration_id";
public static final String ALLOW_SMS_FALLBACK_PREF = "pref_allow_sms_traffic_out";
public static boolean isSmsFallbackEnabled(Context context) {
return getBooleanPreference(context, ALLOW_SMS_FALLBACK_PREF, true);
}
public static int getLocalRegistrationId(Context context) { public static int getLocalRegistrationId(Context context) {
return getIntegerPreference(context, LOCAL_REGISTRATION_ID_PREF, 0); return getIntegerPreference(context, LOCAL_REGISTRATION_ID_PREF, 0);
@ -175,7 +180,7 @@ public class TextSecurePreferences {
} }
public static boolean isSmsDeliveryReportsEnabled(Context context) { public static boolean isSmsDeliveryReportsEnabled(Context context) {
return getBooleanPreference(context, SMS_DELIVERY_REPORT_PREF, false); return getBooleanPreference(context, SMS_DELIVERY_REPORT_PREF, true);
} }
public static boolean hasPromptedPushRegistration(Context context) { public static boolean hasPromptedPushRegistration(Context context) {