Inserted the Registration activity into initial setup flow.

1) Added push messaging toggle to preferences.

2) Added push messaging registration screen to setup flow.

3) Migrated rest of SharedPreferences accessors to
   TextSecurePreferences.
This commit is contained in:
Moxie Marlinspike 2013-07-11 14:58:40 -07:00
parent 52e5274a2f
commit d7070e7ecf
22 changed files with 427 additions and 141 deletions

View File

@ -65,9 +65,8 @@ public class PushServiceSocket {
makeRequest(REGISTER_GCM_PATH, "PUT", new Gson().toJson(registration));
}
public void unregisterGcmId(String gcmRegistrationId) throws IOException, RateLimitException {
GcmRegistrationId registration = new GcmRegistrationId(gcmRegistrationId);
makeRequest(REGISTER_GCM_PATH, "DELETE", new Gson().toJson(registration));
public void unregisterGcmId() throws IOException, RateLimitException {
makeRequest(REGISTER_GCM_PATH, "DELETE", null);
}
public void sendMessage(String recipient, String messageText)

View File

@ -18,4 +18,13 @@
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:background="?navigation_drawer_background"/>
<TextView android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="?conversation_text_secondary_color"
android:text="Empty message list" />
</android.support.v4.widget.DrawerLayout>

View File

@ -19,7 +19,7 @@
android:layout_width="fill_parent"
android:layout_marginBottom="16dip"
android:layout_marginTop="16dip"
android:text="@string/registration_activity__please_confirm_your_country_code_and_phone_number"/>
android:text="@string/registration_activity__textsecure_can_use_the_data_channel_to_avoid_sms_charges_when_communicating_with_other_textsecure_users"/>
<TextView style="@style/Registration.Label"
android:layout_width="fill_parent"
@ -65,14 +65,28 @@
</LinearLayout>
<Button
android:id="@+id/registerButton"
android:text="@string/registration_activity__register"
android:layout_width="wrap_content"
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginTop="20dip"
android:layout_marginBottom="20dip"/>
android:layout_marginBottom="20dip"
android:layout_gravity="right"
android:orientation="horizontal">
<Button android:id="@+id/skipButton"
android:text="Skip"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button android:id="@+id/registerButton"
android:text="@string/registration_activity__register"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -21,6 +21,9 @@
able to access them.
</string>
<string name="ApplicationPreferencesActivity_disable">Disable</string>
<string name="ApplicationPreferencesActivity_unregistering">Unregistering...</string>
<string name="ApplicationPreferencesActivity_unregistering_for_data_based_communication">Unregistering for data based communication</string>
<string name="ApplicationPreferencesActivity_error_connecting_to_server">Error connecting to server!</string>
<!-- AttachmentTypeSelectorAdapter -->
@ -438,8 +441,9 @@
<string name="receive_key_activity__complete">Complete</string>
<!-- registration_activity -->
<string name="registration_activity__please_confirm_your_country_code_and_phone_number">Please
confirm your country code and phone number.
<string name="registration_activity__textsecure_can_use_the_data_channel_to_avoid_sms_charges_when_communicating_with_other_textsecure_users">
TextSecure can use the data channel to avoid SMS charges when communicating with other
TextSecure users. To enable this feature, please verify your country code and phone number.
</string>
<string name="registration_activity__your_country">YOUR COUNTRY</string>
<string name="registration_activity__your_country_code_and_phone_number">YOUR COUNTRY CODE AND
@ -628,6 +632,10 @@
<string name="preferences__language">Language</string>
<string name="preferences__make_default_sms_app">Set as default SMS app</string>
<string name="preferences__make_textsecure_the_default_sms_mms_app">Make TextSecure the default SMS/MMS application for your system.</string>
<string name="preferences__use_data_channel">Use data channel</string>
<string name="preferences__use_the_data_channel_for_communication_with_other_textsecure_users">
Use the data channel for communication with other TextSecure users
</string>
<!-- **************************************** -->
<!-- menus -->

View File

@ -21,6 +21,11 @@
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"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences__notifications">
<CheckBoxPreference android:key="pref_key_enable_notifications"

View File

@ -18,6 +18,8 @@ package org.thoughtcrime.securesms;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@ -25,6 +27,7 @@ import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
@ -41,6 +44,7 @@ import android.util.Log;
import android.widget.Toast;
import com.actionbarsherlock.view.MenuItem;
import com.google.android.gcm.GCMRegistrar;
import org.thoughtcrime.securesms.contacts.ContactAccessor;
import org.thoughtcrime.securesms.contacts.ContactIdentityManager;
import org.thoughtcrime.securesms.crypto.MasterSecret;
@ -49,8 +53,13 @@ import org.thoughtcrime.securesms.service.KeyCachingService;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.MemoryCleaner;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.Trimmer;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.textsecure.push.PushServiceSocket;
import org.whispersystems.textsecure.push.RateLimitException;
import java.io.IOException;
/**
* The Activity for application preference display and management.
@ -66,6 +75,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
private static final int PICK_IDENTITY_CONTACT = 1;
private static final int ENABLE_PASSPHRASE_ACTIVITY = 2;
<<<<<<< HEAD
public static final String RINGTONE_PREF = "pref_key_ringtone";
public static final String IN_THREAD_NOTIFICATION_PREF = "pref_key_inthread_notifications";
public static final String VIBRATE_PREF = "pref_key_vibrate";
@ -86,6 +96,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
public static final String ENTER_PRESENT_PREF = "pref_enter_key";
private static final String DISPLAY_CATEGORY_PREF = "pref_display_category";
private static final String PUSH_MESSAGING_PREF = "pref_toggle_push_messaging";
private static final String CHANGE_PASSPHRASE_PREF = "pref_change_passphrase";
public static final String DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase";
@ -122,14 +133,16 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
initializeIdentitySelection();
initializePlatformSpecificOptions();
initializePushMessagingToggle();
initializeEditTextSummaries();
this.findPreference(CHANGE_PASSPHRASE_PREF)
this.findPreference(TextSecurePreferences.CHANGE_PASSPHRASE_PREF)
.setOnPreferenceClickListener(new ChangePassphraseClickListener());
this.findPreference(THREAD_TRIM_NOW)
this.findPreference(TextSecurePreferences.THREAD_TRIM_NOW)
.setOnPreferenceClickListener(new TrimNowClickListener());
this.findPreference(THREAD_TRIM_LENGTH)
this.findPreference(TextSecurePreferences.THREAD_TRIM_LENGTH)
.setOnPreferenceChangeListener(new TrimLengthValidationListener());
this.findPreference(DISABLE_PASSPHRASE_PREF)
this.findPreference(TextSecurePreferences.DISABLE_PASSPHRASE_PREF)
.setOnPreferenceChangeListener(new DisablePassphraseClickListener());
this.findPreference(MMS_PREF)
.setOnPreferenceClickListener(new ApnPreferencesClickListener());
@ -219,6 +232,34 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
}
}
private void initializeEditTextSummary(final EditTextPreference preference) {
if (preference.getText() == null) {
preference.setSummary("Not set");
} else {
preference.setSummary(preference.getText());
}
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference pref, Object newValue) {
preference.setSummary(newValue == null ? "Not set" : ((String) newValue));
return true;
}
});
}
private void initializeEditTextSummaries() {
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_HOST_PREF));
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_HOST_PREF));
initializeEditTextSummary((EditTextPreference)this.findPreference(TextSecurePreferences.MMSC_PROXY_PORT_PREF));
}
private void initializePushMessagingToggle() {
CheckBoxPreference preference = (CheckBoxPreference)this.findPreference(PUSH_MESSAGING_PREF);
preference.setChecked(TextSecurePreferences.isPushRegistered(this));
preference.setOnPreferenceChangeListener(new PushMessagingClickListener());
}
private void initializeIdentitySelection() {
ContactIdentityManager identity = ContactIdentityManager.getInstance(this);
@ -230,12 +271,12 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
if (contactUri != null) {
String contactName = ContactAccessor.getInstance().getNameFromContact(this, contactUri);
this.findPreference(IDENTITY_PREF)
this.findPreference(TextSecurePreferences.IDENTITY_PREF)
.setSummary(String.format(getString(R.string.ApplicationPreferencesActivity_currently_s),
contactName));
}
this.findPreference(IDENTITY_PREF)
this.findPreference(TextSecurePreferences.IDENTITY_PREF)
.setOnPreferenceClickListener(new IdentityPreferenceClickListener());
}
}
@ -256,24 +297,84 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
Uri contactUri = data.getData();
if (contactUri != null) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String contactUriString = contactUri.toString();
preferences.edit().putString(IDENTITY_PREF, contactUriString).commit();
TextSecurePreferences.setIdentityContactUri(this, contactUri.toString());
initializeIdentitySelection();
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(THEME_PREF)) {
if (key.equals(TextSecurePreferences.THEME_PREF)) {
dynamicTheme.onResume(this);
} else if (key.equals(LANGUAGE_PREF)) {
} else if (key.equals(TextSecurePreferences.LANGUAGE_PREF)) {
dynamicLanguage.onResume(this);
}
}
private class PushMessagingClickListener implements Preference.OnPreferenceChangeListener {
private static final int SUCCESS = 0;
private static final int NETWORK_ERROR = 1;
@Override
public boolean onPreferenceChange(final Preference preference, Object newValue) {
if (((CheckBoxPreference)preference).isChecked()) {
new AsyncTask<Void, Void, Integer>() {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(ApplicationPreferencesActivity.this,
getString(R.string.ApplicationPreferencesActivity_unregistering),
getString(R.string.ApplicationPreferencesActivity_unregistering_for_data_based_communication),
true, false);
}
@Override
protected void onPostExecute(Integer result) {
if (dialog != null)
dialog.dismiss();
switch (result) {
case NETWORK_ERROR:
Toast.makeText(ApplicationPreferencesActivity.this,
getString(R.string.ApplicationPreferencesActivity_error_connecting_to_server),
Toast.LENGTH_LONG).show();
break;
case SUCCESS:
((CheckBoxPreference)preference).setChecked(false);
break;
}
}
@Override
protected Integer doInBackground(Void... params) {
try {
Context context = ApplicationPreferencesActivity.this;
String localNumber = TextSecurePreferences.getLocalNumber(context);
String pushPassword = TextSecurePreferences.getPushServerPassword(context);
PushServiceSocket socket = new PushServiceSocket(context, localNumber, pushPassword);
socket.unregisterGcmId();
GCMRegistrar.unregister(context);
return SUCCESS;
} catch (IOException e) {
Log.w("ApplicationPreferencesActivity", e);
return NETWORK_ERROR;
} catch (RateLimitException e) {
Log.w("ApplicationPreferencesActivity", e);
return NETWORK_ERROR;
}
}
}.execute();
} else {
startActivity(new Intent(ApplicationPreferencesActivity.this, RegistrationActivity.class));
}
return false;
}
}
private class IdentityPreferenceClickListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
@ -303,9 +404,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
private class TrimNowClickListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
final int threadLengthLimit = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(ApplicationPreferencesActivity.this)
.getString(THREAD_TRIM_LENGTH, "500"));
final int threadLengthLimit = TextSecurePreferences.getThreadTrimLength(ApplicationPreferencesActivity.this);
AlertDialog.Builder builder = new AlertDialog.Builder(ApplicationPreferencesActivity.this);
builder.setTitle(R.string.ApplicationPreferencesActivity_delete_all_old_messages_now);
builder.setMessage(String.format(getString(R.string.ApplicationPreferencesActivity_are_you_sure_you_would_like_to_immediately_trim_all_conversation_threads_to_the_s_most_recent_messages),
@ -343,11 +442,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
PreferenceManager.getDefaultSharedPreferences(ApplicationPreferencesActivity.this)
.edit()
.putBoolean(DISABLE_PASSPHRASE_PREF, true)
.commit();
TextSecurePreferences.setPasswordDisabled(ApplicationPreferencesActivity.this, true);
((CheckBoxPreference)preference).setChecked(true);
Intent intent = new Intent(ApplicationPreferencesActivity.this, KeyCachingService.class);
@ -370,7 +465,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredSherlockPr
private class TrimLengthValidationListener implements Preference.OnPreferenceChangeListener {
public TrimLengthValidationListener() {
EditTextPreference preference = (EditTextPreference)findPreference(THREAD_TRIM_LENGTH);
EditTextPreference preference = (EditTextPreference)findPreference(TextSecurePreferences.THREAD_TRIM_LENGTH);
preference.setSummary(preference.getText() + " " + getString(R.string.ApplicationPreferencesActivity_messages_per_conversation));
}

View File

@ -24,6 +24,7 @@ import com.google.i18n.phonenumbers.AsYouTypeFormatter;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
import org.whispersystems.textsecure.util.Util;
@ -44,6 +45,7 @@ public class RegistrationActivity extends SherlockActivity {
private TextView countryCode;
private TextView number;
private Button createButton;
private Button skipButton;
@Override
public void onCreate(Bundle icicle) {
@ -72,10 +74,12 @@ public class RegistrationActivity extends SherlockActivity {
this.countryCode = (TextView)findViewById(R.id.country_code);
this.number = (TextView)findViewById(R.id.number);
this.createButton = (Button)findViewById(R.id.registerButton);
this.skipButton = (Button)findViewById(R.id.skipButton);
this.countryCode.addTextChangedListener(new CountryCodeChangedListener());
this.number.addTextChangedListener(new NumberChangedListener());
this.createButton.setOnClickListener(new CreateButtonListener());
this.skipButton.setOnClickListener(new CancelButtonListener());
}
private void initializeSpinner() {
@ -144,6 +148,8 @@ public class RegistrationActivity extends SherlockActivity {
public void onClick(View v) {
final RegistrationActivity self = RegistrationActivity.this;
TextSecurePreferences.setPromptedPushRegistration(self, true);
if (Util.isEmpty(countryCode.getText())) {
Toast.makeText(self,
getString(R.string.RegistrationActivity_you_must_specify_your_country_code),
@ -256,4 +262,19 @@ public class RegistrationActivity extends SherlockActivity {
}
}
private class CancelButtonListener implements View.OnClickListener {
@Override
public void onClick(View v) {
TextSecurePreferences.setPromptedPushRegistration(RegistrationActivity.this, true);
Intent nextIntent = getIntent().getParcelableExtra("next_intent");
if (nextIntent == null) {
nextIntent = new Intent(RegistrationActivity.this, RoutingActivity.class);
}
startActivity(nextIntent);
finish();
}
}
}

View File

@ -10,6 +10,7 @@ import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.service.ApplicationMigrationService;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
public class RoutingActivity extends PassphraseRequiredSherlockActivity {
@ -18,6 +19,7 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
private static final int STATE_IMPORT_DATABASE = 3;
private static final int STATE_CONVERSATION_OR_LIST = 4;
private static final int STATE_UPGRADE_DATABASE = 5;
private static final int STATE_PROMPT_PUSH_REGISTRATION = 6;
private MasterSecret masterSecret = null;
private boolean isVisible = false;
@ -65,19 +67,16 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
}
private void routeApplicationState() {
Intent intent = new Intent(this, RegistrationActivity.class);
startActivity(intent);
return;
//
// int state = getApplicationState();
//
// switch (state) {
// case STATE_CREATE_PASSPHRASE: handleCreatePassphrase(); break;
// case STATE_PROMPT_PASSPHRASE: handlePromptPassphrase(); break;
// case STATE_IMPORT_DATABASE: handleImportDatabase(); break;
// case STATE_CONVERSATION_OR_LIST: handleDisplayConversationOrList(); break;
// case STATE_UPGRADE_DATABASE: handleUpgradeDatabase(); break;
// }
int state = getApplicationState();
switch (state) {
case STATE_CREATE_PASSPHRASE: handleCreatePassphrase(); break;
case STATE_PROMPT_PASSPHRASE: handlePromptPassphrase(); break;
case STATE_IMPORT_DATABASE: handleImportDatabase(); break;
case STATE_CONVERSATION_OR_LIST: handleDisplayConversationOrList(); break;
case STATE_UPGRADE_DATABASE: handleUpgradeDatabase(); break;
case STATE_PROMPT_PUSH_REGISTRATION: handlePushRegistration(); break;
}
}
private void handleCreatePassphrase() {
@ -93,7 +92,7 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
private void handleImportDatabase() {
Intent intent = new Intent(this, DatabaseMigrationActivity.class);
intent.putExtra("master_secret", masterSecret);
intent.putExtra("next_intent", getConversationListIntent());
intent.putExtra("next_intent", getPushRegistrationIntent());
startActivity(intent);
finish();
@ -102,17 +101,21 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
private void handleUpgradeDatabase() {
Intent intent = new Intent(this, DatabaseUpgradeActivity.class);
intent.putExtra("master_secret", masterSecret);
intent.putExtra("next_intent", getConversationListIntent());
intent.putExtra("next_intent", TextSecurePreferences.hasPromptedPushRegistration(this) ?
getConversationListIntent() : getPushRegistrationIntent());
startActivity(intent);
finish();
}
private void handleDisplayConversationOrList() {
// Intent intent = new Intent(this, RegistrationActivity.class);
// startActivity(intent);
// finish();
private void handlePushRegistration() {
Intent intent = new Intent(this, RegistrationActivity.class);
intent.putExtra("next_intent", getConversationListIntent());
startActivity(intent);
finish();
}
private void handleDisplayConversationOrList() {
ConversationParameters parameters = getConversationParameters();
Intent intent;
@ -146,6 +149,10 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
return intent;
}
private Intent getPushRegistrationIntent() {
return new Intent(this, RegistrationActivity.class);
}
private int getApplicationState() {
if (!MasterSecretUtil.isPassphraseInitialized(this))
return STATE_CREATE_PASSPHRASE;
@ -159,6 +166,9 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
if (DatabaseUpgradeActivity.isUpdate(this))
return STATE_UPGRADE_DATABASE;
if (!TextSecurePreferences.hasPromptedPushRegistration(this))
return STATE_PROMPT_PUSH_REGISTRATION;
return STATE_CONVERSATION_OR_LIST;
}

View File

@ -2,13 +2,10 @@ package org.thoughtcrime.securesms.gcm;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
import com.google.android.gcm.GCMBaseIntentService;
import com.google.thoughtcrimegson.Gson;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.service.RegistrationService;
import org.thoughtcrime.securesms.service.SendReceiveService;
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
@ -27,8 +24,7 @@ public class GcmIntentService extends GCMBaseIntentService {
@Override
protected void onRegistered(Context context, String registrationId) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (!preferences.getBoolean(ApplicationPreferencesActivity.REGISTERED_GCM_PREF, false)) {
if (!TextSecurePreferences.isPushRegistered(context)) {
Intent intent = new Intent(RegistrationService.GCM_REGISTRATION_EVENT);
intent.putExtra(RegistrationService.GCM_REGISTRATION_ID, registrationId);
sendBroadcast(intent);
@ -46,7 +42,7 @@ public class GcmIntentService extends GCMBaseIntentService {
@Override
protected void onUnregistered(Context context, String registrationId) {
try {
getGcmSocket(context).unregisterGcmId(registrationId);
getGcmSocket(context).unregisterGcmId();
} catch (IOException ioe) {
Log.w("GcmIntentService", ioe);
} catch (RateLimitException e) {

View File

@ -48,6 +48,7 @@ import org.thoughtcrime.securesms.database.MmsSmsDatabase;
import org.thoughtcrime.securesms.database.model.MessageRecord;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.io.IOException;
import java.util.List;
@ -97,9 +98,7 @@ public class MessageNotifier {
public static void updateNotification(Context context, MasterSecret masterSecret) {
if (!PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(ApplicationPreferencesActivity.NOTIFICATION_PREF, true))
{
if (!TextSecurePreferences.isNotificationsEnabled(context)) {
return;
}
@ -107,9 +106,7 @@ public class MessageNotifier {
}
public static void updateNotification(Context context, MasterSecret masterSecret, long threadId) {
if (!PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(ApplicationPreferencesActivity.NOTIFICATION_PREF, true))
{
if (!TextSecurePreferences.isNotificationsEnabled(context)) {
return;
}
@ -236,7 +233,7 @@ public class MessageNotifier {
return;
}
String ringtone = sp.getString(ApplicationPreferencesActivity.RINGTONE_PREF, null);
String ringtone = TextSecurePreferences.getNotificationRingtone(context);
if (ringtone == null)
return;
@ -302,13 +299,11 @@ public class MessageNotifier {
NotificationCompat.Builder builder,
boolean signal)
{
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
String ringtone = sp.getString(ApplicationPreferencesActivity.RINGTONE_PREF, null);
boolean vibrate = sp.getBoolean(ApplicationPreferencesActivity.VIBRATE_PREF, true);
String ledColor = sp.getString(ApplicationPreferencesActivity.LED_COLOR_PREF, "green");
String ledBlinkPattern = sp.getString(ApplicationPreferencesActivity.LED_BLINK_PREF, "500,2000");
String ledBlinkPatternCustom = sp.getString(ApplicationPreferencesActivity.LED_BLINK_PREF_CUSTOM, "500,2000");
String ringtone = TextSecurePreferences.getNotificationRingtone(context);
boolean vibrate = TextSecurePreferences.isNotificationVibrateEnabled(context);
String ledColor = TextSecurePreferences.getNotificationLedColor(context);
String ledBlinkPattern = TextSecurePreferences.getNotificationLedPattern(context);
String ledBlinkPatternCustom = TextSecurePreferences.getNotificationLedPatternCustom(context);
String[] blinkPatternArray = parseBlinkPattern(ledBlinkPattern, ledBlinkPatternCustom);
builder.setSound(TextUtils.isEmpty(ringtone) || !signal ? null : Uri.parse(ringtone));

View File

@ -33,6 +33,7 @@ import android.widget.Toast;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
/**
* List preference for LED blink pattern notification.
@ -66,13 +67,13 @@ public class LedBlinkPatternListPreference extends ListPreference implements OnS
super.onDialogClosed(positiveResult);
if (positiveResult) {
String blinkPattern = PreferenceManager.getDefaultSharedPreferences(context).getString(ApplicationPreferencesActivity.LED_BLINK_PREF, "500,2000");
String blinkPattern = TextSecurePreferences.getNotificationLedPattern(context);
if (blinkPattern.equals("custom")) showDialog();
}
}
private void initializeSeekBarValues() {
String patternString = PreferenceManager.getDefaultSharedPreferences(context).getString(ApplicationPreferencesActivity.LED_BLINK_PREF_CUSTOM, "500,2000");
String patternString = TextSecurePreferences.getNotificationLedPatternCustom(context);
String[] patternArray = patternString.split(",");
seekBarOn.setProgress(Integer.parseInt(patternArray[0]));
seekBarOff.setProgress(Integer.parseInt(patternArray[1]));
@ -152,8 +153,7 @@ public class LedBlinkPatternListPreference extends ListPreference implements OnS
String pattern = seekBarOnLabel.getText() + "," + seekBarOffLabel.getText();
dialogInProgress = false;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.edit().putString(ApplicationPreferencesActivity.LED_BLINK_PREF_CUSTOM, pattern).commit();
TextSecurePreferences.setNotificationLedPatternCustom(context, pattern);
Toast.makeText(context, "Custom LED blink pattern set!", Toast.LENGTH_LONG).show();
}

View File

@ -30,6 +30,7 @@ import android.widget.TextView;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
/**
* Dialog preference for encryption passphrase timeout.
@ -79,14 +80,14 @@ public class PassphraseTimeoutPreference extends DialogPreference {
interval = Math.max(seekBar.getProgress(), 1) * 60;
}
this.getSharedPreferences().edit().putInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, interval).commit();
TextSecurePreferences.setPassphraseTimeoutInterval(getContext(), interval);
}
super.onClick(dialog, which);
}
private void initializeDefaults() {
int timeout = this.getSharedPreferences().getInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, 60 * 5);
int timeout = TextSecurePreferences.getPassphraseTimeoutInterval(getContext());
if (timeout > 60) {
scaleSpinner.setSelection(1);

View File

@ -174,11 +174,10 @@ public class KeyCachingService extends Service {
}
private void startTimeoutIfAppropriate() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean timeoutEnabled = sharedPreferences.getBoolean(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_PREF, false);
boolean timeoutEnabled = TextSecurePreferences.isPassphraseTimeoutEnabled(this);
if ((activitiesRunning == 0) && (this.masterSecret != null) && timeoutEnabled && !TextSecurePreferences.isPasswordDisabled(this)) {
long timeoutMinutes = sharedPreferences.getInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, 60 * 5);
long timeoutMinutes = TextSecurePreferences.getPassphraseTimeoutInterval(this);
long timeoutMillis = timeoutMinutes * 60 * 1000;
Log.w("KeyCachingService", "Starting timeout: " + timeoutMillis);

View File

@ -27,6 +27,7 @@ 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 ws.com.google.android.mms.pdu.GenericPdu;
import ws.com.google.android.mms.pdu.NotificationInd;
@ -52,8 +53,7 @@ public class MmsListener extends BroadcastReceiver {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ||
PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(ApplicationPreferencesActivity.ALL_MMS_PERF, true))
TextSecurePreferences.isInterceptAllMmsEnabled(context))
{
return true;
}

View File

@ -18,6 +18,7 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.gcm.GcmIntentService;
import org.thoughtcrime.securesms.gcm.GcmRegistrationTimeoutException;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.push.PushServiceSocket;
import org.whispersystems.textsecure.push.RateLimitException;
import org.whispersystems.textsecure.util.Util;
@ -296,23 +297,18 @@ public class RegistrationService extends Service {
}
private void markAsVerifying(boolean verifying) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = preferences.edit();
TextSecurePreferences.setVerifying(this, verifying);
editor.putBoolean(ApplicationPreferencesActivity.VERIFYING_STATE_PREF, verifying);
editor.putBoolean(ApplicationPreferencesActivity.REGISTERED_GCM_PREF, false);
editor.commit();
if (verifying) {
TextSecurePreferences.setPushRegistered(this, false);
}
}
private void markAsVerified(String number, String password) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Editor editor = preferences.edit();
editor.putBoolean(ApplicationPreferencesActivity.VERIFYING_STATE_PREF, false);
editor.putBoolean(ApplicationPreferencesActivity.REGISTERED_GCM_PREF, true);
editor.putString(ApplicationPreferencesActivity.LOCAL_NUMBER_PREF, number);
editor.putString(ApplicationPreferencesActivity.GCM_PASSWORD_PREF, password);
editor.commit();
TextSecurePreferences.setVerifying(this, false);
TextSecurePreferences.setPushRegistered(this, true);
TextSecurePreferences.setLocalNumber(this, number);
TextSecurePreferences.setPushServerPassword(this, password);
}
private void setState(RegistrationState state) {

View File

@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.protocol.WirePrefix;
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.util.ArrayList;
@ -127,7 +128,7 @@ public class SmsListener extends BroadcastReceiver {
return false;
if (messageBody.matches("Your TextSecure verification code: [0-9]{3,4}-[0-9]{3,4}") &&
preferences.getBoolean(ApplicationPreferencesActivity.VERIFYING_STATE_PREF, false))
TextSecurePreferences.isVerifying(context))
{
return true;
}

View File

@ -39,6 +39,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.sms.IncomingKeyExchangeMessage;
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
import org.thoughtcrime.securesms.sms.MultipartSmsMessageHandler;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.util.List;
@ -95,10 +96,7 @@ public class SmsReceiver {
private Pair<Long, Long> storeKeyExchangeMessage(MasterSecret masterSecret,
IncomingKeyExchangeMessage message)
{
if (masterSecret != null &&
PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(ApplicationPreferencesActivity.AUTO_KEY_EXCHANGE_PREF, true))
{
if (masterSecret != null && TextSecurePreferences.isAutoRespondKeyExchangeEnabled(context)) {
try {
Recipient recipient = new Recipient(null, message.getSender(), null, null);
KeyExchangeMessage keyExchangeMessage = new KeyExchangeMessage(message.getMessageBody());

View File

@ -4,11 +4,9 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.telephony.SmsManager;
import android.util.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.SessionCipher;
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
@ -18,6 +16,7 @@ import org.thoughtcrime.securesms.service.SmsDeliveryListener;
import org.thoughtcrime.securesms.sms.MultipartSmsMessageHandler;
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.util.ArrayList;
@ -126,9 +125,7 @@ public class SmsTransport {
}
private ArrayList<PendingIntent> constructDeliveredIntents(long messageId, long type, ArrayList<String> messages) {
if (!PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(ApplicationPreferencesActivity.SMS_DELIVERY_REPORT_PREF, false))
{
if (!TextSecurePreferences.isSmsDeliveryReportsEnabled(context)) {
return null;
}

View File

@ -4,10 +4,6 @@ import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import java.util.Locale;
@ -54,8 +50,7 @@ public class DynamicLanguage {
}
private static Locale getSelectedLocale(Activity activity) {
String language = PreferenceManager.getDefaultSharedPreferences(activity)
.getString(ApplicationPreferencesActivity.LANGUAGE_PREF, DEFAULT);
String language = TextSecurePreferences.getLanguage(activity);
if (language.equals(DEFAULT)) return Locale.getDefault();
else return new Locale(language);

View File

@ -37,8 +37,7 @@ public class DynamicTheme {
}
private static int getSelectedTheme(Activity activity) {
String theme = PreferenceManager.getDefaultSharedPreferences(activity)
.getString(ApplicationPreferencesActivity.THEME_PREF, "light");
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals("light")) {
if (activity instanceof ConversationListActivity) return R.style.TextSecure_LightTheme_NavigationDrawer;

View File

@ -2,57 +2,196 @@ package org.thoughtcrime.securesms.util;
import android.content.Context;
import android.preference.PreferenceManager;
import android.util.Log;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.RoutingActivity;
public class TextSecurePreferences {
public static final String IDENTITY_PREF = "pref_choose_identity";
public static final String CHANGE_PASSPHRASE_PREF = "pref_change_passphrase";
public static final String DISABLE_PASSPHRASE_PREF = "pref_disable_passphrase";
public static final String THEME_PREF = "pref_theme";
public static final String LANGUAGE_PREF = "pref_language";
public static final String MMSC_HOST_PREF = "pref_apn_mmsc_host";
public static final String MMSC_PROXY_HOST_PREF = "pref_apn_mms_proxy";
public static final String MMSC_PROXY_PORT_PREF = "pref_apn_mms_proxy_port";
public static final String THREAD_TRIM_LENGTH = "pref_trim_length";
public static final String THREAD_TRIM_NOW = "pref_trim_now";
public static final String USE_LOCAL_MMS_APNS_PREF = "pref_use_local_apns";
private static final String RINGTONE_PREF = "pref_key_ringtone";
private static final String VIBRATE_PREF = "pref_key_vibrate";
private static final String NOTIFICATION_PREF = "pref_key_enable_notifications";
private static final String LED_COLOR_PREF = "pref_led_color";
private static final String LED_BLINK_PREF = "pref_led_blink";
private static final String LED_BLINK_PREF_CUSTOM = "pref_led_blink_custom";
private static final String ALL_MMS_PERF = "pref_all_mms";
private static final String PASSPHRASE_TIMEOUT_INTERVAL_PREF = "pref_timeout_interval";
private static final String PASSPHRASE_TIMEOUT_PREF = "pref_timeout_passphrase";
private static final String AUTO_KEY_EXCHANGE_PREF = "pref_auto_complete_key_exchange";
private static final String ENTER_SENDS_PREF = "pref_enter_sends";
private static final String ENTER_PRESENT_PREF = "pref_enter_key";
private static final String SMS_DELIVERY_REPORT_PREF = "pref_delivery_report_sms";
private static final String THREAD_TRIM_ENABLED = "pref_trim_threads";
private static final String LOCAL_NUMBER_PREF = "pref_local_number";
private static final String VERIFYING_STATE_PREF = "pref_verifying";
private static final String REGISTERED_GCM_PREF = "pref_gcm_registered";
private static final String GCM_PASSWORD_PREF = "pref_gcm_password";
private static final String PROMPTED_PUSH_REGISTRATION_PREF = "pref_prompted_push_registration";
public static String getLocalNumber(Context context) {
return getStringPreference(context, ApplicationPreferencesActivity.LOCAL_NUMBER_PREF, "No Stored Number");
return getStringPreference(context, LOCAL_NUMBER_PREF, "No Stored Number");
}
public static void setLocalNumber(Context context, String localNumber) {
setStringPreference(context, LOCAL_NUMBER_PREF, localNumber);
}
public static String getPushServerPassword(Context context) {
return getStringPreference(context, ApplicationPreferencesActivity.GCM_PASSWORD_PREF, null);
return getStringPreference(context, GCM_PASSWORD_PREF, null);
}
public static void setPushServerPassword(Context context, String password) {
setStringPreference(context, GCM_PASSWORD_PREF, password);
}
public static boolean isEnterImeKeyEnabled(Context context) {
return getBooleanPreference(context, ApplicationPreferencesActivity.ENTER_PRESENT_PREF, false);
return getBooleanPreference(context, ENTER_PRESENT_PREF, false);
}
public static boolean isEnterSendsEnabled(Context context) {
return getBooleanPreference(context, ApplicationPreferencesActivity.ENTER_SENDS_PREF, false);
return getBooleanPreference(context, ENTER_SENDS_PREF, false);
}
public static boolean isPasswordDisabled(Context context) {
return getBooleanPreference(context, ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false);
return getBooleanPreference(context, DISABLE_PASSPHRASE_PREF, false);
}
public static void setPasswordDisabled(Context context, boolean disabled) {
setBooleanPreference(context, ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, disabled);
setBooleanPreference(context, DISABLE_PASSPHRASE_PREF, disabled);
}
public static String getMmscUrl(Context context) {
return getStringPreference(context, ApplicationPreferencesActivity.MMSC_HOST_PREF, "");
return getStringPreference(context, MMSC_HOST_PREF, "");
}
public static String getMmscProxy(Context context) {
return getStringPreference(context, ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF, "");
return getStringPreference(context, MMSC_PROXY_HOST_PREF, "");
}
public static String getMmscProxyPort(Context context) {
return getStringPreference(context, ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF, "");
return getStringPreference(context, MMSC_PROXY_PORT_PREF, "");
}
public static String getIdentityContactUri(Context context) {
return getStringPreference(context, ApplicationPreferencesActivity.IDENTITY_PREF, null);
return getStringPreference(context, IDENTITY_PREF, null);
}
public static void setIdentityContactUri(Context context, String identityUri) {
setStringPreference(context, IDENTITY_PREF, identityUri);
}
public static boolean isAutoRespondKeyExchangeEnabled(Context context) {
return getBooleanPreference(context, ApplicationPreferencesActivity.AUTO_KEY_EXCHANGE_PREF, true);
return getBooleanPreference(context, AUTO_KEY_EXCHANGE_PREF, true);
}
public static boolean isUseLocalApnsEnabled(Context context) {
return getBooleanPreference(context, ApplicationPreferencesActivity.USE_LOCAL_MMS_APNS_PREF, false);
return getBooleanPreference(context, USE_LOCAL_MMS_APNS_PREF, false);
}
public static String getTheme(Context context) {
return getStringPreference(context, THEME_PREF, "light");
}
public static boolean isVerifying(Context context) {
return getBooleanPreference(context, VERIFYING_STATE_PREF, false);
}
public static void setVerifying(Context context, boolean verifying) {
setBooleanPreference(context, VERIFYING_STATE_PREF, verifying);
}
public static boolean isPushRegistered(Context context) {
return getBooleanPreference(context, REGISTERED_GCM_PREF, false);
}
public static void setPushRegistered(Context context, boolean registered) {
Log.w("TextSecurePreferences", "Setting push registered: " + registered);
setBooleanPreference(context, REGISTERED_GCM_PREF, registered);
}
public static boolean isPassphraseTimeoutEnabled(Context context) {
return getBooleanPreference(context, PASSPHRASE_TIMEOUT_PREF, false);
}
public static int getPassphraseTimeoutInterval(Context context) {
return getIntegerPreference(context, PASSPHRASE_TIMEOUT_INTERVAL_PREF, 5 * 60);
}
public static void setPassphraseTimeoutInterval(Context context, int interval) {
setIntegerPrefrence(context, PASSPHRASE_TIMEOUT_INTERVAL_PREF, interval);
}
public static String getLanguage(Context context) {
return getStringPreference(context, LANGUAGE_PREF, "zz");
}
public static void setLanguage(Context context, String language) {
setStringPreference(context, LANGUAGE_PREF, language);
}
public static boolean isSmsDeliveryReportsEnabled(Context context) {
return getBooleanPreference(context, SMS_DELIVERY_REPORT_PREF, false);
}
public static boolean hasPromptedPushRegistration(Context context) {
return getBooleanPreference(context, PROMPTED_PUSH_REGISTRATION_PREF, false);
}
public static void setPromptedPushRegistration(Context context, boolean value) {
setBooleanPreference(context, PROMPTED_PUSH_REGISTRATION_PREF, value);
}
public static boolean isInterceptAllMmsEnabled(Context context) {
return getBooleanPreference(context, ALL_MMS_PERF, true);
}
public static boolean isNotificationsEnabled(Context context) {
return getBooleanPreference(context, NOTIFICATION_PREF, true);
}
public static String getNotificationRingtone(Context context) {
return getStringPreference(context, RINGTONE_PREF, null);
}
public static boolean isNotificationVibrateEnabled(Context context) {
return getBooleanPreference(context, VIBRATE_PREF, true);
}
public static String getNotificationLedColor(Context context) {
return getStringPreference(context, LED_COLOR_PREF, "green");
}
public static String getNotificationLedPattern(Context context) {
return getStringPreference(context, LED_BLINK_PREF, "500,2000");
}
public static String getNotificationLedPatternCustom(Context context) {
return getStringPreference(context, LED_BLINK_PREF_CUSTOM, "500,2000");
}
public static void setNotificationLedPatternCustom(Context context, String pattern) {
setStringPreference(context, LED_BLINK_PREF_CUSTOM, pattern);
}
public static boolean isThreadLengthTrimmingEnabled(Context context) {
return getBooleanPreference(context, THREAD_TRIM_ENABLED, false);
}
public static int getThreadTrimLength(Context context) {
return Integer.parseInt(getStringPreference(context, THREAD_TRIM_LENGTH, "500"));
}
private static void setBooleanPreference(Context context, String key, boolean value) {
@ -63,7 +202,20 @@ public class TextSecurePreferences {
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, defaultValue);
}
public static void setStringPreference(Context context, String key, String value) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(key, value).commit();
}
private static String getStringPreference(Context context, String key, String defaultValue) {
return PreferenceManager.getDefaultSharedPreferences(context).getString(key, defaultValue);
}
private static int getIntegerPreference(Context context, String key, int defaultValue) {
return PreferenceManager.getDefaultSharedPreferences(context).getInt(key, defaultValue);
}
private static void setIntegerPrefrence(Context context, String key, int value) {
PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(key, value).commit();
}
}

View File

@ -2,12 +2,9 @@ package org.thoughtcrime.securesms.util;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.widget.Toast;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.ThreadDatabase;
@ -18,9 +15,8 @@ public class Trimmer {
}
public static void trimThread(final Context context, final long threadId) {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean trimmingEnabled = preferences.getBoolean(ApplicationPreferencesActivity.THREAD_TRIM_ENABLED, false);
final int threadLengthLimit = Integer.parseInt(preferences.getString(ApplicationPreferencesActivity.THREAD_TRIM_LENGTH, "500"));
boolean trimmingEnabled = TextSecurePreferences.isThreadLengthTrimmingEnabled(context);
final int threadLengthLimit = TextSecurePreferences.getThreadTrimLength(context);
if (!trimmingEnabled)
return;