diff --git a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java
index 0ad2001d7a..a59bc5fd58 100644
--- a/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java
+++ b/library/src/org/whispersystems/textsecure/push/PushServiceSocket.java
@@ -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)
diff --git a/res/layout/conversation_list_activity.xml b/res/layout/conversation_list_activity.xml
index 73fbafc8bf..ec9f405dd6 100644
--- a/res/layout/conversation_list_activity.xml
+++ b/res/layout/conversation_list_activity.xml
@@ -18,4 +18,13 @@
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:background="?navigation_drawer_background"/>
+
+
+
\ No newline at end of file
diff --git a/res/layout/registration_activity.xml b/res/layout/registration_activity.xml
index 86c736688c..a0a6a9a76a 100644
--- a/res/layout/registration_activity.xml
+++ b/res/layout/registration_activity.xml
@@ -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"/>
-
+
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 01dd14b6a5..18d7660256 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -21,6 +21,9 @@
able to access them.
Disable
+ Unregistering...
+ Unregistering for data based communication
+ Error connecting to server!
@@ -438,8 +441,9 @@
Complete
- Please
- confirm your country code and phone number.
+
+ 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.
YOUR COUNTRY
YOUR COUNTRY CODE AND
@@ -628,6 +632,10 @@
Language
Set as default SMS app
Make TextSecure the default SMS/MMS application for your system.
+ Use data channel
+
+ Use the data channel for communication with other TextSecure users
+
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 2df2f68339..ff48af2d16 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -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" />
+
+
() {
+ 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));
}
diff --git a/src/org/thoughtcrime/securesms/RegistrationActivity.java b/src/org/thoughtcrime/securesms/RegistrationActivity.java
index 37c4da0f1f..7ca3e08ebf 100644
--- a/src/org/thoughtcrime/securesms/RegistrationActivity.java
+++ b/src/org/thoughtcrime/securesms/RegistrationActivity.java
@@ -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();
+ }
+ }
}
diff --git a/src/org/thoughtcrime/securesms/RoutingActivity.java b/src/org/thoughtcrime/securesms/RoutingActivity.java
index d8ab5a93e5..0b49223d52 100644
--- a/src/org/thoughtcrime/securesms/RoutingActivity.java
+++ b/src/org/thoughtcrime/securesms/RoutingActivity.java
@@ -10,14 +10,16 @@ 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 {
- private static final int STATE_CREATE_PASSPHRASE = 1;
- private static final int STATE_PROMPT_PASSPHRASE = 2;
- 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_CREATE_PASSPHRASE = 1;
+ private static final int STATE_PROMPT_PASSPHRASE = 2;
+ 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;
}
diff --git a/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java b/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java
index 01e6e35964..edcd07cb48 100644
--- a/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java
+++ b/src/org/thoughtcrime/securesms/gcm/GcmIntentService.java
@@ -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) {
diff --git a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java
index d196364241..ce9872e786 100644
--- a/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java
+++ b/src/org/thoughtcrime/securesms/notifications/MessageNotifier.java
@@ -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));
diff --git a/src/org/thoughtcrime/securesms/preferences/LedBlinkPatternListPreference.java b/src/org/thoughtcrime/securesms/preferences/LedBlinkPatternListPreference.java
index a1088be580..69eb286eea 100644
--- a/src/org/thoughtcrime/securesms/preferences/LedBlinkPatternListPreference.java
+++ b/src/org/thoughtcrime/securesms/preferences/LedBlinkPatternListPreference.java
@@ -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();
}
diff --git a/src/org/thoughtcrime/securesms/preferences/PassphraseTimeoutPreference.java b/src/org/thoughtcrime/securesms/preferences/PassphraseTimeoutPreference.java
index 2bc8b0b49e..d1865bfce5 100644
--- a/src/org/thoughtcrime/securesms/preferences/PassphraseTimeoutPreference.java
+++ b/src/org/thoughtcrime/securesms/preferences/PassphraseTimeoutPreference.java
@@ -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);
diff --git a/src/org/thoughtcrime/securesms/service/KeyCachingService.java b/src/org/thoughtcrime/securesms/service/KeyCachingService.java
index fef8f495c0..0445d3ca81 100644
--- a/src/org/thoughtcrime/securesms/service/KeyCachingService.java
+++ b/src/org/thoughtcrime/securesms/service/KeyCachingService.java
@@ -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);
diff --git a/src/org/thoughtcrime/securesms/service/MmsListener.java b/src/org/thoughtcrime/securesms/service/MmsListener.java
index c5a8efc9c5..5a95bcb4b6 100644
--- a/src/org/thoughtcrime/securesms/service/MmsListener.java
+++ b/src/org/thoughtcrime/securesms/service/MmsListener.java
@@ -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;
}
diff --git a/src/org/thoughtcrime/securesms/service/RegistrationService.java b/src/org/thoughtcrime/securesms/service/RegistrationService.java
index 35a360552f..ff9fab248e 100644
--- a/src/org/thoughtcrime/securesms/service/RegistrationService.java
+++ b/src/org/thoughtcrime/securesms/service/RegistrationService.java
@@ -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) {
diff --git a/src/org/thoughtcrime/securesms/service/SmsListener.java b/src/org/thoughtcrime/securesms/service/SmsListener.java
index 35ff7a4277..21f0f7aa09 100644
--- a/src/org/thoughtcrime/securesms/service/SmsListener.java
+++ b/src/org/thoughtcrime/securesms/service/SmsListener.java
@@ -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;
}
diff --git a/src/org/thoughtcrime/securesms/service/SmsReceiver.java b/src/org/thoughtcrime/securesms/service/SmsReceiver.java
index 5bddd57aa5..7b0fadd518 100644
--- a/src/org/thoughtcrime/securesms/service/SmsReceiver.java
+++ b/src/org/thoughtcrime/securesms/service/SmsReceiver.java
@@ -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 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());
diff --git a/src/org/thoughtcrime/securesms/transport/SmsTransport.java b/src/org/thoughtcrime/securesms/transport/SmsTransport.java
index eb2fb14a8c..b0caf789e7 100644
--- a/src/org/thoughtcrime/securesms/transport/SmsTransport.java
+++ b/src/org/thoughtcrime/securesms/transport/SmsTransport.java
@@ -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 constructDeliveredIntents(long messageId, long type, ArrayList messages) {
- if (!PreferenceManager.getDefaultSharedPreferences(context)
- .getBoolean(ApplicationPreferencesActivity.SMS_DELIVERY_REPORT_PREF, false))
- {
+ if (!TextSecurePreferences.isSmsDeliveryReportsEnabled(context)) {
return null;
}
diff --git a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java
index 6c70f829b4..b93e5f5c1f 100644
--- a/src/org/thoughtcrime/securesms/util/DynamicLanguage.java
+++ b/src/org/thoughtcrime/securesms/util/DynamicLanguage.java
@@ -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);
diff --git a/src/org/thoughtcrime/securesms/util/DynamicTheme.java b/src/org/thoughtcrime/securesms/util/DynamicTheme.java
index 85a6999db5..52897f83d9 100644
--- a/src/org/thoughtcrime/securesms/util/DynamicTheme.java
+++ b/src/org/thoughtcrime/securesms/util/DynamicTheme.java
@@ -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;
diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
index 2bf8a51db2..8aa1fb3ed4 100644
--- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
+++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java
@@ -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();
+ }
+
}
diff --git a/src/org/thoughtcrime/securesms/util/Trimmer.java b/src/org/thoughtcrime/securesms/util/Trimmer.java
index 4dd3128376..235b75d8c0 100644
--- a/src/org/thoughtcrime/securesms/util/Trimmer.java
+++ b/src/org/thoughtcrime/securesms/util/Trimmer.java
@@ -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;