mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Move most of Util into library
This commit is contained in:
parent
21eee19380
commit
a200d29514
@ -1,6 +1,4 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
package org.whispersystems.textsecure.util;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Encodes and decodes to and from Base64 notation.</p>
|
* <p>Encodes and decodes to and from Base64 notation.</p>
|
58
library/src/org/whispersystems/textsecure/util/Util.java
Normal file
58
library/src/org/whispersystems/textsecure/util/Util.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package org.whispersystems.textsecure.util;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public static boolean isEmpty(String value) {
|
||||||
|
return value == null || value.trim().length() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEmpty(EditText value) {
|
||||||
|
return value == null || value.getText() == null || isEmpty(value.getText().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isEmpty(CharSequence value) {
|
||||||
|
return value == null || value.length() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showAlertDialog(Context context, String title, String message) {
|
||||||
|
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||||
|
dialog.setTitle(title);
|
||||||
|
dialog.setMessage(message);
|
||||||
|
dialog.setIcon(android.R.drawable.ic_dialog_alert);
|
||||||
|
dialog.setPositiveButton(android.R.string.ok, null);
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getSecret(int size) {
|
||||||
|
try {
|
||||||
|
byte[] secret = new byte[size];
|
||||||
|
SecureRandom.getInstance("SHA1PRNG").nextBytes(secret);
|
||||||
|
return Base64.encodeBytes(secret);
|
||||||
|
} catch (NoSuchAlgorithmException nsae) {
|
||||||
|
throw new AssertionError(nsae);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String readFully(InputStream in) throws IOException {
|
||||||
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
|
byte[] buffer = new byte[4096];
|
||||||
|
int read;
|
||||||
|
|
||||||
|
while ((read = in.read(buffer)) != -1) {
|
||||||
|
bout.write(buffer, 0, read);
|
||||||
|
}
|
||||||
|
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
return new String(bout.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,6 @@ import android.net.Uri;
|
|||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
import android.telephony.PhoneNumberUtils;
|
import android.telephony.PhoneNumberUtils;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -90,7 +89,7 @@ import org.thoughtcrime.securesms.util.EncryptedCharacterCalculator;
|
|||||||
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
||||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -21,7 +21,7 @@ import android.os.Bundle;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.SerializableKey;
|
import org.thoughtcrime.securesms.crypto.SerializableKey;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.Dialogs;
|
import org.thoughtcrime.securesms.util.Dialogs;
|
||||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||||
|
|
||||||
|
@ -16,10 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.thoughtcrime.securesms;
|
package org.thoughtcrime.securesms;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -30,8 +28,8 @@ import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
|
|||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||||
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
import org.thoughtcrime.securesms.util.MemoryCleaner;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
|
||||||
import org.thoughtcrime.securesms.util.VersionTracker;
|
import org.thoughtcrime.securesms.util.VersionTracker;
|
||||||
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activity for creating a user's local encryption passphrase.
|
* Activity for creating a user's local encryption passphrase.
|
||||||
|
@ -24,8 +24,8 @@ import com.google.i18n.phonenumbers.AsYouTypeFormatter;
|
|||||||
import com.google.i18n.phonenumbers.NumberParseException;
|
import com.google.i18n.phonenumbers.NumberParseException;
|
||||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||||
import com.google.i18n.phonenumbers.Phonenumber;
|
import com.google.i18n.phonenumbers.Phonenumber;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
|
||||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||||
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The register account activity. Begins the account registration process.
|
* 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.PushServiceSocket;
|
||||||
import org.thoughtcrime.securesms.gcm.RateLimitException;
|
import org.thoughtcrime.securesms.gcm.RateLimitException;
|
||||||
import org.thoughtcrime.securesms.service.RegistrationService;
|
import org.thoughtcrime.securesms.service.RegistrationService;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
|
||||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||||
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.IdentityKey;
|
import org.thoughtcrime.securesms.crypto.IdentityKey;
|
||||||
import org.thoughtcrime.securesms.crypto.InvalidKeyException;
|
import org.thoughtcrime.securesms.crypto.InvalidKeyException;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.Long;
|
import java.lang.Long;
|
||||||
|
@ -26,7 +26,7 @@ import javax.crypto.spec.SecretKeySpec;
|
|||||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||||
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
|
import org.bouncycastle.crypto.agreement.ECDHBasicAgreement;
|
||||||
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.Conversions;
|
import org.thoughtcrime.securesms.util.Conversions;
|
||||||
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ import org.thoughtcrime.bouncycastle.asn1.ASN1Object;
|
|||||||
import org.thoughtcrime.bouncycastle.asn1.ASN1Sequence;
|
import org.thoughtcrime.bouncycastle.asn1.ASN1Sequence;
|
||||||
import org.thoughtcrime.bouncycastle.asn1.DERInteger;
|
import org.thoughtcrime.bouncycastle.asn1.DERInteger;
|
||||||
import org.thoughtcrime.bouncycastle.asn1.DERSequence;
|
import org.thoughtcrime.bouncycastle.asn1.DERSequence;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.Combiner;
|
import org.thoughtcrime.securesms.util.Combiner;
|
||||||
import org.thoughtcrime.securesms.util.Conversions;
|
import org.thoughtcrime.securesms.util.Conversions;
|
||||||
|
|
||||||
|
@ -17,13 +17,11 @@
|
|||||||
package org.thoughtcrime.securesms.crypto;
|
package org.thoughtcrime.securesms.crypto;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
|
||||||
import org.thoughtcrime.securesms.database.keys.LocalKeyRecord;
|
import org.thoughtcrime.securesms.database.keys.LocalKeyRecord;
|
||||||
import org.thoughtcrime.securesms.protocol.Message;
|
import org.thoughtcrime.securesms.protocol.Message;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.Conversions;
|
import org.thoughtcrime.securesms.util.Conversions;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -33,7 +33,7 @@ import javax.crypto.spec.IvParameterSpec;
|
|||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
|
||||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.Hex;
|
import org.thoughtcrime.securesms.util.Hex;
|
||||||
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
import org.bouncycastle.crypto.AsymmetricCipherKeyPair;
|
||||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
|
@ -31,9 +31,9 @@ import org.thoughtcrime.securesms.crypto.MasterCipher;
|
|||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.database.keys.SessionRecord;
|
import org.thoughtcrime.securesms.database.keys.SessionRecord;
|
||||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
@ -31,7 +31,7 @@ import org.thoughtcrime.securesms.crypto.MasterSecret;
|
|||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ import org.thoughtcrime.securesms.util.InvalidMessageException;
|
|||||||
import org.thoughtcrime.securesms.util.LRUCache;
|
import org.thoughtcrime.securesms.util.LRUCache;
|
||||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||||
import org.thoughtcrime.securesms.util.Trimmer;
|
import org.thoughtcrime.securesms.util.Trimmer;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
@ -133,7 +133,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
DELIVERY_TIME, DELIVERY_REPORT, BODY, PART_COUNT, ADDRESS
|
DELIVERY_TIME, DELIVERY_REPORT, BODY, PART_COUNT, ADDRESS
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final ExecutorService slideResolver = Util.newSingleThreadedLifoExecutor();
|
public static final ExecutorService slideResolver = org.thoughtcrime.securesms.util.Util.newSingleThreadedLifoExecutor();
|
||||||
private static final Map<Long, SoftReference<SlideDeck>> slideCache =
|
private static final Map<Long, SoftReference<SlideDeck>> slideCache =
|
||||||
Collections.synchronizedMap(new LRUCache<Long, SoftReference<SlideDeck>>(20));
|
Collections.synchronizedMap(new LRUCache<Long, SoftReference<SlideDeck>>(20));
|
||||||
|
|
||||||
@ -362,7 +362,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
ContentValues contentValues = getContentValuesFromHeader(headers);
|
ContentValues contentValues = getContentValuesFromHeader(headers);
|
||||||
boolean unread = Util.isDefaultSmsProvider(context) || ((mailbox & Types.SECURE_MESSAGE_BIT) != 0);
|
boolean unread = Util.isDefaultSmsProvider(context) || ((mailbox & Types.SECURE_MESSAGE_BIT) != 0);
|
||||||
|
|
||||||
if (!Util.isEmpty(retrieved.getCc())) {
|
if (!org.thoughtcrime.securesms.util.Util.isEmpty(retrieved.getCc())) {
|
||||||
try {
|
try {
|
||||||
threadId = getThreadIdFor(retrieved);
|
threadId = getThreadIdFor(retrieved);
|
||||||
} catch (RecipientFormattingException e) {
|
} catch (RecipientFormattingException e) {
|
||||||
@ -773,10 +773,10 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
|||||||
byte[]transactionIdBytes = null;
|
byte[]transactionIdBytes = null;
|
||||||
|
|
||||||
if (!Util.isEmpty(contentLocation))
|
if (!Util.isEmpty(contentLocation))
|
||||||
contentLocationBytes = Util.toIsoBytes(contentLocation);
|
contentLocationBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(contentLocation);
|
||||||
|
|
||||||
if (!Util.isEmpty(transactionId))
|
if (!Util.isEmpty(transactionId))
|
||||||
transactionIdBytes = Util.toIsoBytes(transactionId);
|
transactionIdBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(transactionId);
|
||||||
|
|
||||||
|
|
||||||
return new NotificationMmsMessageRecord(context, id, recipients, recipients.getPrimaryRecipient(),
|
return new NotificationMmsMessageRecord(context, id, recipients, recipients.getPrimaryRecipient(),
|
||||||
|
@ -37,7 +37,7 @@ import org.thoughtcrime.securesms.sms.IncomingKeyExchangeMessage;
|
|||||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||||
import org.thoughtcrime.securesms.util.Trimmer;
|
import org.thoughtcrime.securesms.util.Trimmer;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -32,7 +32,7 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
|||||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
import org.thoughtcrime.securesms.util.InvalidMessageException;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -24,7 +24,7 @@ import android.text.style.StyleSpan;
|
|||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.database.SmsDatabase;
|
import org.thoughtcrime.securesms.database.SmsDatabase;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message record model which represents thread heading messages.
|
* The message record model which represents thread heading messages.
|
||||||
|
@ -13,7 +13,7 @@ import org.thoughtcrime.securesms.service.RegistrationService;
|
|||||||
import org.thoughtcrime.securesms.service.SendReceiveService;
|
import org.thoughtcrime.securesms.service.SendReceiveService;
|
||||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -9,7 +9,7 @@ import com.google.thoughtcrimegson.Gson;
|
|||||||
import org.thoughtcrime.securesms.Release;
|
import org.thoughtcrime.securesms.Release;
|
||||||
import org.thoughtcrime.securesms.directory.DirectoryDescriptor;
|
import org.thoughtcrime.securesms.directory.DirectoryDescriptor;
|
||||||
import org.thoughtcrime.securesms.directory.NumberFilter;
|
import org.thoughtcrime.securesms.directory.NumberFilter;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
@ -17,13 +17,11 @@
|
|||||||
package org.thoughtcrime.securesms.mms;
|
package org.thoughtcrime.securesms.mms;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteException;
|
import android.database.sqlite.SQLiteException;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.http.AndroidHttpClient;
|
import android.net.http.AndroidHttpClient;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
@ -32,12 +30,11 @@ import org.apache.http.conn.params.ConnRouteParams;
|
|||||||
import org.apache.http.params.HttpConnectionParams;
|
import org.apache.http.params.HttpConnectionParams;
|
||||||
import org.apache.http.params.HttpParams;
|
import org.apache.http.params.HttpParams;
|
||||||
import org.apache.http.params.HttpProtocolParams;
|
import org.apache.http.params.HttpProtocolParams;
|
||||||
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
|
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.service.MmsDownloader;
|
import org.thoughtcrime.securesms.service.MmsDownloader;
|
||||||
import org.thoughtcrime.securesms.util.Conversions;
|
import org.thoughtcrime.securesms.util.Conversions;
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -28,7 +28,7 @@ import org.apache.http.client.ClientProtocolException;
|
|||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.ByteArrayEntity;
|
import org.apache.http.entity.ByteArrayEntity;
|
||||||
import org.thoughtcrime.securesms.service.MmscProcessor;
|
import org.thoughtcrime.securesms.service.MmscProcessor;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -19,7 +19,7 @@ package org.thoughtcrime.securesms.mms;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.TransportDetails;
|
import org.thoughtcrime.securesms.crypto.TransportDetails;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
public class TextTransport implements TransportDetails {
|
public class TextTransport implements TransportDetails {
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thoughtcrime.securesms.protocol;
|
package org.thoughtcrime.securesms.protocol;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -19,7 +19,7 @@ import org.thoughtcrime.securesms.gcm.GcmIntentService;
|
|||||||
import org.thoughtcrime.securesms.gcm.GcmRegistrationTimeoutException;
|
import org.thoughtcrime.securesms.gcm.GcmRegistrationTimeoutException;
|
||||||
import org.thoughtcrime.securesms.gcm.PushServiceSocket;
|
import org.thoughtcrime.securesms.gcm.PushServiceSocket;
|
||||||
import org.thoughtcrime.securesms.gcm.RateLimitException;
|
import org.thoughtcrime.securesms.gcm.RateLimitException;
|
||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.whispersystems.textsecure.util.Util;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
@ -18,7 +18,7 @@ package org.thoughtcrime.securesms.sms;
|
|||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -5,7 +5,7 @@ import android.util.Log;
|
|||||||
import org.thoughtcrime.securesms.protocol.KeyExchangeWirePrefix;
|
import org.thoughtcrime.securesms.protocol.KeyExchangeWirePrefix;
|
||||||
import org.thoughtcrime.securesms.protocol.SecureMessageWirePrefix;
|
import org.thoughtcrime.securesms.protocol.SecureMessageWirePrefix;
|
||||||
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.thoughtcrime.securesms.util.Conversions;
|
import org.thoughtcrime.securesms.util.Conversions;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -21,7 +21,7 @@ import android.util.Log;
|
|||||||
import org.thoughtcrime.securesms.crypto.SessionCipher;
|
import org.thoughtcrime.securesms.crypto.SessionCipher;
|
||||||
import org.thoughtcrime.securesms.crypto.TransportDetails;
|
import org.thoughtcrime.securesms.crypto.TransportDetails;
|
||||||
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
import org.thoughtcrime.securesms.protocol.WirePrefix;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package org.thoughtcrime.securesms.transport;
|
package org.thoughtcrime.securesms.transport;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.TransportDetails;
|
import org.thoughtcrime.securesms.crypto.TransportDetails;
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.thoughtcrime.securesms.util;
|
package org.thoughtcrime.securesms.util;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
@ -27,12 +25,7 @@ import android.widget.EditText;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.provider.Telephony;
|
import android.provider.Telephony;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -100,18 +93,6 @@ public class Util {
|
|||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEmpty(String value) {
|
|
||||||
return value == null || value.trim().length() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEmpty(EditText value) {
|
|
||||||
return value == null || value.getText() == null || isEmpty(value.getText().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEmpty(CharSequence value) {
|
|
||||||
return value == null || value.length() == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isEmpty(EncodedStringValue[] value) {
|
public static boolean isEmpty(EncodedStringValue[] value) {
|
||||||
return value == null || value.length == 0;
|
return value == null || value.length == 0;
|
||||||
}
|
}
|
||||||
@ -153,38 +134,6 @@ public class Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showAlertDialog(Context context, String title, String message) {
|
|
||||||
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
|
||||||
dialog.setTitle(title);
|
|
||||||
dialog.setMessage(message);
|
|
||||||
dialog.setIcon(android.R.drawable.ic_dialog_alert);
|
|
||||||
dialog.setPositiveButton(android.R.string.ok, null);
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getSecret(int size) {
|
|
||||||
try {
|
|
||||||
byte[] secret = new byte[size];
|
|
||||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(secret);
|
|
||||||
return Base64.encodeBytes(secret);
|
|
||||||
} catch (NoSuchAlgorithmException nsae) {
|
|
||||||
throw new AssertionError(nsae);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readFully(InputStream in) throws IOException {
|
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
|
||||||
byte[] buffer = new byte[4096];
|
|
||||||
int read;
|
|
||||||
|
|
||||||
while ((read = in.read(buffer)) != -1) {
|
|
||||||
bout.write(buffer, 0, read);
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
|
|
||||||
return new String(bout.toByteArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isDefaultSmsProvider(Context context){
|
public static boolean isDefaultSmsProvider(Context context){
|
||||||
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) ||
|
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user