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.
fork-5.53.8
Moxie Marlinspike 2014-02-20 14:49:31 -08:00
rodzic c5821f770a
commit 918f223149
8 zmienionych plików z 66 dodań i 14 usunięć

Wyświetl plik

@ -678,6 +678,8 @@
<string name="preferences__use_the_data_channel_for_communication_with_other_textsecure_users">
Use the data channel for communication with other TextSecure users
</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 -->

Wyświetl plik

@ -16,16 +16,22 @@
android:title="@string/preferences__make_default_sms_app"
android:summary="@string/preferences__make_textsecure_the_default_sms_mms_app" />
<CheckBoxPreference android:defaultValue="false"
android:key="pref_delivery_report_sms"
android:summary="@string/preferences__request_a_delivery_report_for_each_sms_message_you_send"
android:title="@string/preferences__sms_delivery_reports" />
<!--<CheckBoxPreference android:defaultValue="false"-->
<!--android:key="pref_delivery_report_sms"-->
<!--android:summary="@string/preferences__request_a_delivery_report_for_each_sms_message_you_send"-->
<!--android:title="@string/preferences__sms_delivery_reports" />-->
<CheckBoxPreference android:defaultValue="false"
android:key="pref_toggle_push_messaging"
android:title="@string/preferences__use_data_channel"
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 android:title="@string/preferences__notifications">
<CheckBoxPreference android:key="pref_key_enable_notifications"

Wyświetl plik

@ -100,6 +100,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
initializeIdentitySelection();
initializePlatformSpecificOptions();
initializeSmsFallbackOption();
initializePushMessagingToggle();
this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF)
@ -178,8 +179,8 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
}
private void initializePlatformSpecificOptions() {
PreferenceGroup generalCategory = (PreferenceGroup)findPreference("general_category");
Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF);
PreferenceGroup generalCategory = (PreferenceGroup) findPreference("general_category");
Preference defaultPreference = findPreference(KITKAT_DEFAULT_PREF);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
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) {
if (preference.getText() == null) {
preference.setSummary("Not set");
@ -268,6 +292,10 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
dynamicTheme.onResume(this);
} else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) {
dynamicLanguage.onResume(this);
} else if (key.equals(TextSecurePreferences.ALL_MMS_PREF) ||
key.equals(TextSecurePreferences.ALL_SMS_PREF))
{
initializeSmsFallbackOption();
}
}

Wyświetl plik

@ -20,14 +20,12 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.preference.PreferenceManager;
import android.provider.Telephony;
import android.util.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.protocol.WirePrefix;
import org.thoughtcrime.securesms.util.Util;
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.NotificationInd;
@ -52,7 +50,8 @@ public class MmsListener extends BroadcastReceiver {
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))
{
return true;

Wyświetl plik

@ -110,7 +110,8 @@ public class SmsListener extends BroadcastReceiver {
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))
{
return true;
@ -120,8 +121,7 @@ public class SmsListener extends BroadcastReceiver {
}
private boolean isChallenge(Context context, Intent intent) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String messageBody = getSmsMessageBodyFromIntent(intent);
String messageBody = getSmsMessageBodyFromIntent(intent);
if (messageBody == null)
return false;

Wyświetl plik

@ -48,6 +48,12 @@ public class SmsTransport extends BaseTransport {
}
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()) {
deliverSecureMessage(message);
} else {

Wyświetl plik

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

Wyświetl plik

@ -44,6 +44,11 @@ public class TextSecurePreferences {
private static final String IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications";
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) {
return getIntegerPreference(context, LOCAL_REGISTRATION_ID_PREF, 0);
@ -175,7 +180,7 @@ public class TextSecurePreferences {
}
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) {