mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 10:47:46 +00:00
Split into library project and add shared preferences layer of indirection.
This commit is contained in:
parent
2539723410
commit
21eee19380
8
library/AndroidManifest.xml
Normal file
8
library/AndroidManifest.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.whispersystems.textsecure"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.1">
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/>
|
||||
<application />
|
||||
</manifest>
|
92
library/build.xml
Normal file
92
library/build.xml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="library" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties"/>
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties"/>
|
||||
|
||||
<!-- if sdk.dir was not set from one of the property file, then
|
||||
get it from the ANDROID_HOME env var.
|
||||
This must be done before we load project.properties since
|
||||
the proguard config can use sdk.dir -->
|
||||
<property environment="env"/>
|
||||
<condition property="sdk.dir" value="${env.ANDROID_HOME}">
|
||||
<isset property="env.ANDROID_HOME"/>
|
||||
</condition>
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties"/>
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through the ANDROID_HOME environment variable."
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
<!--
|
||||
Import per project custom build rules if present at the root of the project.
|
||||
This is the place to put custom intermediary targets such as:
|
||||
-pre-build
|
||||
-pre-compile
|
||||
-post-compile (This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir})
|
||||
-post-package
|
||||
-post-build
|
||||
-pre-clean
|
||||
-->
|
||||
<import file="custom_rules.xml" optional="true"/>
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml"/>
|
||||
|
||||
</project>
|
30
library/library.iml
Normal file
30
library/library.iml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="LIBRARY_PROJECT" value="true" />
|
||||
<option name="UPDATE_PROPERTY_FILES" value="true" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library" exported="">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/libs/libphonenumber-5.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
|
BIN
library/libs/libphonenumber-5.3.jar
Normal file
BIN
library/libs/libphonenumber-5.3.jar
Normal file
Binary file not shown.
20
library/proguard-project.txt
Normal file
20
library/proguard-project.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
3
library/res/values/strings.xml
Normal file
3
library/res/values/strings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
</resources>
|
@ -1,8 +1,5 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
package org.whispersystems.textsecure.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.i18n.phonenumbers.NumberParseException;
|
||||
@ -10,8 +7,6 @@ import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil.PhoneNumberFormat;
|
||||
import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
@ -54,10 +49,8 @@ public class PhoneNumberFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatNumber(Context context, String number) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String localNumber = preferences.getString(ApplicationPreferencesActivity.LOCAL_NUMBER_PREF, "No Stored Number");
|
||||
number = number.replaceAll("[^0-9+]", "");
|
||||
public static String formatNumber(String number, String localNumber) {
|
||||
number = number.replaceAll("[^0-9+]", "");
|
||||
|
||||
if (number.charAt(0) == '+')
|
||||
return number;
|
@ -89,6 +89,7 @@ import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.EncryptedCharacterCalculator;
|
||||
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -599,9 +600,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
}
|
||||
|
||||
private void initializeIme() {
|
||||
if (PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getBoolean(ApplicationPreferencesActivity.ENTER_PRESENT_PREF, false))
|
||||
{
|
||||
if (TextSecurePreferences.isEnterImeKeyEnabled(this)) {
|
||||
composeText.setInputType(composeText.getInputType() & (~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
|
||||
} else {
|
||||
composeText.setInputType(composeText.getInputType() | (InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE));
|
||||
@ -852,7 +851,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
if (rawText.length() < 1 && !attachmentManager.isAttachmentPresent())
|
||||
throw new InvalidMessageException(getString(R.string.ConversationActivity_message_is_empty_exclamation));
|
||||
|
||||
if (!isEncryptedConversation && Tag.isTaggable(this, rawText))
|
||||
if (!isEncryptedConversation && Tag.isTaggable(rawText))
|
||||
rawText = Tag.getTaggedMessage(rawText);
|
||||
|
||||
return rawText;
|
||||
@ -1002,9 +1001,7 @@ public class ConversationActivity extends PassphraseRequiredSherlockFragmentActi
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||
if (PreferenceManager.getDefaultSharedPreferences(ConversationActivity.this)
|
||||
.getBoolean(ApplicationPreferencesActivity.ENTER_SENDS_PREF, false))
|
||||
{
|
||||
if (TextSecurePreferences.isEnterSendsEnabled(ConversationActivity.this)) {
|
||||
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
|
||||
sendButton.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER));
|
||||
return true;
|
||||
|
@ -30,6 +30,7 @@ import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
/**
|
||||
* Activity for changing a user's local encryption passphrase.
|
||||
@ -67,7 +68,7 @@ public class PassphraseChangeActivity extends PassphraseActivity {
|
||||
this.okButton.setOnClickListener(new OkButtonClickListener());
|
||||
this.cancelButton.setOnClickListener(new CancelButtonClickListener());
|
||||
|
||||
if (isPassphraseDisabled()) {
|
||||
if (TextSecurePreferences.isPasswordDisabled(this)) {
|
||||
this.originalPassphrase.setVisibility(View.GONE);
|
||||
this.originalPassphraseLabel.setVisibility(View.GONE);
|
||||
} else {
|
||||
@ -85,7 +86,7 @@ public class PassphraseChangeActivity extends PassphraseActivity {
|
||||
String passphrase = (newText == null ? "" : newText.toString());
|
||||
String passphraseRepeat = (repeatText == null ? "" : repeatText.toString());
|
||||
|
||||
if (isPassphraseDisabled()) {
|
||||
if (TextSecurePreferences.isPasswordDisabled(this)) {
|
||||
original = MasterSecretUtil.UNENCRYPTED_PASSPHRASE;
|
||||
}
|
||||
|
||||
@ -98,11 +99,7 @@ public class PassphraseChangeActivity extends PassphraseActivity {
|
||||
this.repeatPassphrase.setText("");
|
||||
} else {
|
||||
MasterSecret masterSecret = MasterSecretUtil.changeMasterSecretPassphrase(this, original, passphrase);
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.edit()
|
||||
.putBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false)
|
||||
.commit();
|
||||
TextSecurePreferences.setPasswordDisabled(this, false);
|
||||
|
||||
MemoryCleaner.clean(original);
|
||||
MemoryCleaner.clean(passphrase);
|
||||
@ -117,11 +114,6 @@ public class PassphraseChangeActivity extends PassphraseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPassphraseDisabled() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false);
|
||||
}
|
||||
|
||||
private class CancelButtonClickListener implements OnClickListener {
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
|
@ -24,8 +24,8 @@ 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.PhoneNumberFormatter;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
|
||||
/**
|
||||
* The register account activity. Begins the account registration process.
|
||||
|
@ -32,8 +32,8 @@ import com.actionbarsherlock.app.SherlockActivity;
|
||||
import org.thoughtcrime.securesms.gcm.PushServiceSocket;
|
||||
import org.thoughtcrime.securesms.gcm.RateLimitException;
|
||||
import org.thoughtcrime.securesms.service.RegistrationService;
|
||||
import org.thoughtcrime.securesms.util.PhoneNumberFormatter;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -12,6 +12,7 @@ import android.provider.ContactsContract.RawContacts;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -24,14 +25,10 @@ class ContactIdentityManagerGingerbread extends ContactIdentityManager {
|
||||
|
||||
@Override
|
||||
public Uri getSelfIdentityUri() {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String contactUriString = preferences.getString(ApplicationPreferencesActivity.IDENTITY_PREF, null);
|
||||
String contactUriString = TextSecurePreferences.getIdentityContactUri(context);
|
||||
|
||||
if (hasLocalNumber()) {
|
||||
return getContactUriForNumber(getLocalNumber());
|
||||
} else if (contactUriString != null) {
|
||||
return Uri.parse(contactUriString);
|
||||
}
|
||||
if (hasLocalNumber()) return getContactUriForNumber(getLocalNumber());
|
||||
else if (contactUriString != null) return Uri.parse(contactUriString);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
|
||||
import org.thoughtcrime.securesms.util.Hex;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.WorkerThread;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -309,9 +310,7 @@ public class DecryptingQueue {
|
||||
}
|
||||
|
||||
private void handleKeyExchangeProcessing(String plaintxtBody) {
|
||||
if (PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(ApplicationPreferencesActivity.AUTO_KEY_EXCHANGE_PREF, true))
|
||||
{
|
||||
if (TextSecurePreferences.isAutoRespondKeyExchangeEnabled(context)) {
|
||||
try {
|
||||
Recipient recipient = new Recipient(null, originator, null, null);
|
||||
KeyExchangeMessage keyExchangeMessage = new KeyExchangeMessage(plaintxtBody);
|
||||
|
@ -13,7 +13,7 @@ import android.support.v4.content.AsyncTaskLoader;
|
||||
|
||||
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import org.thoughtcrime.securesms.util.PhoneNumberFormatter;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
|
||||
public class CountryListLoader extends AsyncTaskLoader<ArrayList<Map<String, String>>> {
|
||||
|
||||
|
@ -23,7 +23,9 @@ import android.util.Log;
|
||||
import com.google.thoughtcrimegson.Gson;
|
||||
import com.google.thoughtcrimegson.JsonParseException;
|
||||
import com.google.thoughtcrimegson.annotations.SerializedName;
|
||||
import org.thoughtcrime.securesms.util.PhoneNumberFormatter;
|
||||
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@ -75,7 +77,10 @@ public class NumberFilter {
|
||||
if (bloomFilter == null) return false;
|
||||
else if (number == null || number.length() == 0) return false;
|
||||
|
||||
return new BloomFilter(bloomFilter, hashCount).contains(PhoneNumberFormatter.formatNumber(context, number));
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
|
||||
return new BloomFilter(bloomFilter, hashCount)
|
||||
.contains(PhoneNumberFormatter.formatNumber(number, localNumber));
|
||||
} catch (IOException ioe) {
|
||||
Log.w("NumberFilter", ioe);
|
||||
return false;
|
||||
|
@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.service.RegistrationService;
|
||||
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -76,9 +77,8 @@ public class GcmIntentService extends GCMBaseIntentService {
|
||||
}
|
||||
|
||||
private PushServiceSocket getGcmSocket(Context context) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String localNumber = preferences.getString(ApplicationPreferencesActivity.LOCAL_NUMBER_PREF, null);
|
||||
String password = preferences.getString(ApplicationPreferencesActivity.GCM_PASSWORD_PREF, null);
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
||||
return new PushServiceSocket(context, localNumber, password);
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,12 @@ package org.thoughtcrime.securesms.gcm;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.SmsManager;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.directory.NumberFilter;
|
||||
import org.thoughtcrime.securesms.util.PhoneNumberFormatter;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -20,10 +18,13 @@ public class OptimizingTransport {
|
||||
public static void sendTextMessage(Context context, String destinationAddress, String message,
|
||||
PendingIntent sentIntent, PendingIntent deliveredIntent)
|
||||
{
|
||||
Log.w("OptimzingTransport", "Outgoing message: " + PhoneNumberFormatter.formatNumber(context, destinationAddress));
|
||||
NumberFilter filter = NumberFilter.getInstance(context);
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String canonicalizedDestinationAddress = PhoneNumberFormatter.formatNumber(destinationAddress, localNumber);
|
||||
NumberFilter filter = NumberFilter.getInstance(context);
|
||||
|
||||
if (filter.containsNumber(PhoneNumberFormatter.formatNumber(context, destinationAddress))) {
|
||||
Log.w("OptimzingTransport", "Outgoing message: " + canonicalizedDestinationAddress);
|
||||
|
||||
if (filter.containsNumber(canonicalizedDestinationAddress)) {
|
||||
Log.w("OptimzingTransport", "In the filter, sending GCM...");
|
||||
sendGcmTextMessage(context, destinationAddress, message, sentIntent, deliveredIntent);
|
||||
} else {
|
||||
@ -48,9 +49,8 @@ public class OptimizingTransport {
|
||||
PendingIntent sentIntent, PendingIntent deliveredIntent)
|
||||
{
|
||||
try {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String localNumber = preferences.getString(ApplicationPreferencesActivity.LOCAL_NUMBER_PREF, null);
|
||||
String password = preferences.getString(ApplicationPreferencesActivity.GCM_PASSWORD_PREF, null);
|
||||
String localNumber = TextSecurePreferences.getLocalNumber(context);
|
||||
String password = TextSecurePreferences.getPushServerPassword(context);
|
||||
|
||||
if (localNumber == null || password == null) {
|
||||
Log.w("OptimzingTransport", "No credentials, falling back to SMS...");
|
||||
@ -59,7 +59,7 @@ public class OptimizingTransport {
|
||||
}
|
||||
|
||||
PushServiceSocket pushServiceSocket = new PushServiceSocket(context, localNumber, password);
|
||||
pushServiceSocket.sendMessage(PhoneNumberFormatter.formatNumber(context, recipient), messageText);
|
||||
pushServiceSocket.sendMessage(PhoneNumberFormatter.formatNumber(recipient, localNumber), messageText);
|
||||
sentIntent.send(Activity.RESULT_OK);
|
||||
} catch (IOException ioe) {
|
||||
Log.w("OptimizingTransport", ioe);
|
||||
|
@ -36,6 +36,7 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.service.MmsDownloader;
|
||||
import org.thoughtcrime.securesms.util.Conversions;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@ -47,10 +48,8 @@ public class MmsCommunication {
|
||||
protected static MmsConnectionParameters getLocallyConfiguredMmsConnectionParameters(Context context)
|
||||
throws ApnUnavailableException
|
||||
{
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
if (preferences.getBoolean(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF, false)) {
|
||||
String mmsc = preferences.getString(ApplicationPreferencesActivity.MMSC_HOST_PREF, null);
|
||||
if (TextSecurePreferences.isUseLocalApnsEnabled(context)) {
|
||||
String mmsc = TextSecurePreferences.getMmscUrl(context);
|
||||
|
||||
if (mmsc == null)
|
||||
throw new ApnUnavailableException("Malformed locally configured MMSC.");
|
||||
@ -58,8 +57,8 @@ public class MmsCommunication {
|
||||
if (!mmsc.startsWith("http"))
|
||||
mmsc = "http://" + mmsc;
|
||||
|
||||
String proxy = preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF, null);
|
||||
String port = preferences.getString(ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF, null);
|
||||
String proxy = TextSecurePreferences.getMmscProxy(context);
|
||||
String port = TextSecurePreferences.getMmscProxyPort(context);
|
||||
|
||||
return new MmsConnectionParameters(mmsc, proxy, port);
|
||||
}
|
||||
@ -70,9 +69,7 @@ public class MmsCommunication {
|
||||
protected static MmsConnectionParameters getLocalMmsConnectionParameters(Context context)
|
||||
throws ApnUnavailableException
|
||||
{
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
if (preferences.getBoolean(ApplicationPreferencesActivity.ENABLE_MANUAL_MMS_PREF, false)) {
|
||||
if (TextSecurePreferences.isUseLocalApnsEnabled(context)) {
|
||||
return getLocallyConfiguredMmsConnectionParameters(context);
|
||||
} else {
|
||||
MmsConnectionParameters params = ApnDefaults.getMmsConnectionParameters(context);
|
||||
@ -205,7 +202,7 @@ public class MmsCommunication {
|
||||
}
|
||||
|
||||
public boolean hasProxy() {
|
||||
return proxy != null && proxy.trim().length() != 0;
|
||||
return !Util.isEmpty(proxy);
|
||||
}
|
||||
|
||||
public String getMmsc() {
|
||||
@ -220,7 +217,7 @@ public class MmsCommunication {
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
if (port == null || port.trim().length() == 0)
|
||||
if (Util.isEmpty(port))
|
||||
return 80;
|
||||
|
||||
return Integer.parseInt(port);
|
||||
|
@ -10,9 +10,7 @@ public class Tag {
|
||||
|
||||
public static final String WHITESPACE_TAG = " ";
|
||||
|
||||
public static boolean isTaggable(Context context, String message) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
public static boolean isTaggable(String message) {
|
||||
return message.matches(".*[^\\s].*") &&
|
||||
message.replaceAll("\\s+$", "").length() + WHITESPACE_TAG.length() <= 158;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
/**
|
||||
* Small service that stays running to keep a key cached in memory.
|
||||
@ -117,7 +118,7 @@ public class KeyCachingService extends Service {
|
||||
this.pending = PendingIntent.getService(this, 0, new Intent(PASSPHRASE_EXPIRED_EVENT, null,
|
||||
this, KeyCachingService.class), 0);
|
||||
|
||||
if (isPassphraseDisabled()) {
|
||||
if (TextSecurePreferences.isPasswordDisabled(this)) {
|
||||
try {
|
||||
MasterSecret masterSecret = MasterSecretUtil.getMasterSecret(this, MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
|
||||
setMasterSecret(masterSecret);
|
||||
@ -168,7 +169,7 @@ public class KeyCachingService extends Service {
|
||||
}
|
||||
|
||||
private void handleDisableService() {
|
||||
if (isPassphraseDisabled())
|
||||
if (TextSecurePreferences.isPasswordDisabled(this))
|
||||
stopForeground(true);
|
||||
}
|
||||
|
||||
@ -176,7 +177,7 @@ public class KeyCachingService extends Service {
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean timeoutEnabled = sharedPreferences.getBoolean(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_PREF, false);
|
||||
|
||||
if ((activitiesRunning == 0) && (this.masterSecret != null) && timeoutEnabled && !isPassphraseDisabled()) {
|
||||
if ((activitiesRunning == 0) && (this.masterSecret != null) && timeoutEnabled && !TextSecurePreferences.isPasswordDisabled(this)) {
|
||||
long timeoutMinutes = sharedPreferences.getInt(ApplicationPreferencesActivity.PASSPHRASE_TIMEOUT_INTERVAL_PREF, 60 * 5);
|
||||
long timeoutMillis = timeoutMinutes * 60 * 1000;
|
||||
|
||||
@ -233,7 +234,7 @@ public class KeyCachingService extends Service {
|
||||
}
|
||||
|
||||
private void foregroundService() {
|
||||
if (isPassphraseDisabled()) {
|
||||
if (TextSecurePreferences.isPasswordDisabled(this)) {
|
||||
stopForeground(true);
|
||||
return;
|
||||
}
|
||||
@ -257,11 +258,6 @@ public class KeyCachingService extends Service {
|
||||
sendBroadcast(intent, KEY_PERMISSION);
|
||||
}
|
||||
|
||||
private boolean isPassphraseDisabled() {
|
||||
return PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.getBoolean(ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false);
|
||||
}
|
||||
|
||||
private PendingIntent buildLockIntent() {
|
||||
Intent intent = new Intent(this, KeyCachingService.class);
|
||||
intent.setAction(PASSPHRASE_EXPIRED_EVENT);
|
||||
|
@ -1,15 +1,9 @@
|
||||
package org.thoughtcrime.securesms.transport;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.model.SmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.directory.NumberFilter;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.PhoneNumberFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class UniversalTransport {
|
||||
|
||||
|
@ -0,0 +1,69 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
||||
|
||||
public class TextSecurePreferences {
|
||||
|
||||
public static String getLocalNumber(Context context) {
|
||||
return getStringPreference(context, ApplicationPreferencesActivity.LOCAL_NUMBER_PREF, "No Stored Number");
|
||||
}
|
||||
|
||||
public static String getPushServerPassword(Context context) {
|
||||
return getStringPreference(context, ApplicationPreferencesActivity.GCM_PASSWORD_PREF, null);
|
||||
}
|
||||
|
||||
public static boolean isEnterImeKeyEnabled(Context context) {
|
||||
return getBooleanPreference(context, ApplicationPreferencesActivity.ENTER_PRESENT_PREF, false);
|
||||
}
|
||||
|
||||
public static boolean isEnterSendsEnabled(Context context) {
|
||||
return getBooleanPreference(context, ApplicationPreferencesActivity.ENTER_SENDS_PREF, false);
|
||||
}
|
||||
|
||||
public static boolean isPasswordDisabled(Context context) {
|
||||
return getBooleanPreference(context, ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, false);
|
||||
}
|
||||
|
||||
public static void setPasswordDisabled(Context context, boolean disabled) {
|
||||
setBooleanPreference(context, ApplicationPreferencesActivity.DISABLE_PASSPHRASE_PREF, disabled);
|
||||
}
|
||||
|
||||
public static String getMmscUrl(Context context) {
|
||||
return getStringPreference(context, ApplicationPreferencesActivity.MMSC_HOST_PREF, "");
|
||||
}
|
||||
|
||||
public static String getMmscProxy(Context context) {
|
||||
return getStringPreference(context, ApplicationPreferencesActivity.MMSC_PROXY_HOST_PREF, "");
|
||||
}
|
||||
|
||||
public static String getMmscProxyPort(Context context) {
|
||||
return getStringPreference(context, ApplicationPreferencesActivity.MMSC_PROXY_PORT_PREF, "");
|
||||
}
|
||||
|
||||
public static String getIdentityContactUri(Context context) {
|
||||
return getStringPreference(context, ApplicationPreferencesActivity.IDENTITY_PREF, null);
|
||||
}
|
||||
|
||||
public static boolean isAutoRespondKeyExchangeEnabled(Context context) {
|
||||
return getBooleanPreference(context, ApplicationPreferencesActivity.AUTO_KEY_EXCHANGE_PREF, true);
|
||||
}
|
||||
|
||||
public static boolean isUseLocalApnsEnabled(Context context) {
|
||||
return getBooleanPreference(context, ApplicationPreferencesActivity.USE_LOCAL_MMS_APNS_PREF, false);
|
||||
}
|
||||
|
||||
private static void setBooleanPreference(Context context, String key, boolean value) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(key, value).commit();
|
||||
}
|
||||
|
||||
private static boolean getBooleanPreference(Context context, String key, boolean defaultValue) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
private static String getStringPreference(Context context, String key, String defaultValue) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getString(key, defaultValue);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user