mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-25 12:08:36 +00:00
Split out Util functions.
This commit is contained in:
@@ -26,7 +26,7 @@ import android.util.Log;
|
||||
import org.thoughtcrime.securesms.mms.ApnUnavailableException;
|
||||
import org.thoughtcrime.securesms.mms.MmsConnection.Apn;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
@@ -23,11 +23,11 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.VisibleForTesting;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -201,7 +201,7 @@ public class CanonicalAddressDatabase {
|
||||
return false;
|
||||
|
||||
final String networkNumber = PhoneNumberUtils.extractNetworkPortion(number);
|
||||
if (Util.isEmpty(networkNumber))
|
||||
if (TextUtils.isEmpty(networkNumber))
|
||||
return false;
|
||||
if (networkNumber.length() < 3)
|
||||
return false;
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteDatabase.CursorFactory;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.DatabaseUpgradeActivity;
|
||||
@@ -30,10 +31,10 @@ import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.whispersystems.textsecure.util.Base64;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -290,7 +291,7 @@ public class DatabaseFactory {
|
||||
long snippetType = threadCursor.getLong(threadCursor.getColumnIndexOrThrow("snippet_type"));
|
||||
long id = threadCursor.getLong(threadCursor.getColumnIndexOrThrow("_id"));
|
||||
|
||||
if (!Util.isEmpty(snippet)) {
|
||||
if (!TextUtils.isEmpty(snippet)) {
|
||||
snippet = masterCipher.decryptBody(snippet);
|
||||
}
|
||||
|
||||
@@ -379,7 +380,7 @@ public class DatabaseFactory {
|
||||
}
|
||||
}
|
||||
|
||||
if (!Util.isEmpty(body)) {
|
||||
if (!TextUtils.isEmpty(body)) {
|
||||
body = masterCipher.encryptBody(body);
|
||||
db.execSQL("UPDATE mms SET body = ?, part_count = ? WHERE _id = ?",
|
||||
new String[] {body, partCount+"", mmsId+""});
|
||||
@@ -666,7 +667,7 @@ public class DatabaseFactory {
|
||||
long mmsId = cursor.getLong(cursor.getColumnIndexOrThrow("mms_id"));
|
||||
String address = cursor.getString(cursor.getColumnIndexOrThrow("address"));
|
||||
|
||||
if (!Util.isEmpty(address)) {
|
||||
if (!TextUtils.isEmpty(address)) {
|
||||
db.execSQL("UPDATE mms SET address = ? WHERE _id = ?", new String[]{address, mmsId+""});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureAttachmentPointer;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -200,7 +200,7 @@ public class GroupDatabase extends Database {
|
||||
return Util.split(cursor.getString(cursor.getColumnIndexOrThrow(MEMBERS)), ",");
|
||||
}
|
||||
|
||||
return new LinkedList<String>();
|
||||
return new LinkedList<>();
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
|
||||
@@ -26,11 +26,11 @@ import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.whispersystems.libaxolotl.IdentityKey;
|
||||
import org.whispersystems.libaxolotl.InvalidKeyException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.whispersystems.textsecure.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -23,17 +23,13 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.net.Uri;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.model.DisplayRecord;
|
||||
@@ -41,6 +37,8 @@ import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.NotificationMmsMessageRecord;
|
||||
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMediaMessage;
|
||||
import org.thoughtcrime.securesms.mms.PartParser;
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||
import org.thoughtcrime.securesms.mms.TextSlide;
|
||||
@@ -48,12 +46,15 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.LRUCache;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.Trimmer;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.lang.ref.SoftReference;
|
||||
@@ -481,9 +482,9 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
PduBody body = getPartsAsBody(partDatabase.getParts(messageId, true));
|
||||
|
||||
try {
|
||||
if (!Util.isEmpty(messageText) && Types.isSymmetricEncryption(outboxType)) {
|
||||
if (!TextUtils.isEmpty(messageText) && Types.isSymmetricEncryption(outboxType)) {
|
||||
body.addPart(new TextSlide(context, masterCipher.decryptBody(messageText)).getPart());
|
||||
} else if (!Util.isEmpty(messageText)) {
|
||||
} else if (!TextUtils.isEmpty(messageText)) {
|
||||
body.addPart(new TextSlide(context, messageText).getPart());
|
||||
}
|
||||
} catch (InvalidMessageException e) {
|
||||
@@ -708,7 +709,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
String messageText = PartParser.getMessageText(body);
|
||||
body = PartParser.getNonTextParts(body);
|
||||
|
||||
if (!Util.isEmpty(messageText)) {
|
||||
if (!TextUtils.isEmpty(messageText)) {
|
||||
contentValues.put(BODY, new MasterCipher(masterSecret).encryptBody(messageText));
|
||||
}
|
||||
}
|
||||
@@ -808,8 +809,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
|
||||
public Cursor getCarrierMmsInformation(String apn) {
|
||||
Uri uri = Uri.withAppendedPath(Uri.parse("content://telephony/carriers"), "current");
|
||||
String selection = Util.isEmpty(apn) ? null : "apn = ?";
|
||||
String[] selectionArgs = Util.isEmpty(apn) ? null : new String[] {apn.trim()};
|
||||
String selection = TextUtils.isEmpty(apn) ? null : "apn = ?";
|
||||
String[] selectionArgs = TextUtils.isEmpty(apn) ? null : new String[] {apn.trim()};
|
||||
|
||||
try {
|
||||
return context.getContentResolver().query(uri, null, selection, selectionArgs, null);
|
||||
@@ -981,10 +982,10 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
byte[]contentLocationBytes = null;
|
||||
byte[]transactionIdBytes = null;
|
||||
|
||||
if (!Util.isEmpty(contentLocation))
|
||||
if (!TextUtils.isEmpty(contentLocation))
|
||||
contentLocationBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(contentLocation);
|
||||
|
||||
if (!Util.isEmpty(transactionId))
|
||||
if (!TextUtils.isEmpty(transactionId))
|
||||
transactionIdBytes = org.thoughtcrime.securesms.util.Util.toIsoBytes(transactionId);
|
||||
|
||||
|
||||
@@ -1016,7 +1017,7 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
|
||||
private Recipients getRecipientsFor(String address) {
|
||||
try {
|
||||
if (Util.isEmpty(address) || address.equals("insert-address-token")) {
|
||||
if (TextUtils.isEmpty(address) || address.equals("insert-address-token")) {
|
||||
return new Recipients(Recipient.getUnknownRecipient(context));
|
||||
}
|
||||
|
||||
@@ -1038,9 +1039,9 @@ public class MmsDatabase extends Database implements MmsSmsColumns {
|
||||
String body = cursor.getString(cursor.getColumnIndexOrThrow(MmsDatabase.BODY));
|
||||
long box = cursor.getLong(cursor.getColumnIndexOrThrow(MmsDatabase.MESSAGE_BOX));
|
||||
|
||||
if (!Util.isEmpty(body) && masterCipher != null && Types.isSymmetricEncryption(box)) {
|
||||
if (!TextUtils.isEmpty(body) && masterCipher != null && Types.isSymmetricEncryption(box)) {
|
||||
return new DisplayRecord.Body(masterCipher.decryptBody(body), true);
|
||||
} else if (!Util.isEmpty(body) && masterCipher == null && Types.isSymmetricEncryption(box)) {
|
||||
} else if (!TextUtils.isEmpty(body) && masterCipher == null && Types.isSymmetricEncryption(box)) {
|
||||
return new DisplayRecord.Body(body, false);
|
||||
} else {
|
||||
return new DisplayRecord.Body(body == null ? "" : body, true);
|
||||
|
||||
@@ -6,8 +6,8 @@ import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Base64;
|
||||
import org.whispersystems.textsecure.api.messages.TextSecureEnvelope;
|
||||
import org.whispersystems.textsecure.util.Base64;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.database.sqlite.SQLiteStatement;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
@@ -37,11 +38,8 @@ import org.thoughtcrime.securesms.sms.IncomingKeyExchangeMessage;
|
||||
import org.thoughtcrime.securesms.sms.IncomingTextMessage;
|
||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage;
|
||||
import org.thoughtcrime.securesms.util.Trimmer;
|
||||
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.thoughtcrime.securesms.util.Util.canonicalizeNumber;
|
||||
@@ -401,7 +399,7 @@ public class SmsDatabase extends Database implements MmsSmsColumns {
|
||||
values.put(PROTOCOL, message.getProtocol());
|
||||
values.put(READ, unread ? 0 : 1);
|
||||
|
||||
if (!Util.isEmpty(message.getPseudoSubject()))
|
||||
if (!TextUtils.isEmpty(message.getPseudoSubject()))
|
||||
values.put(SUBJECT, message.getPseudoSubject());
|
||||
|
||||
values.put(REPLY_PATH_PRESENT, message.isReplyPathPresent());
|
||||
|
||||
@@ -10,8 +10,8 @@ import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
import android.util.Log;
|
||||
|
||||
import org.whispersystems.textsecure.push.ContactTokenDetails;
|
||||
import org.whispersystems.textsecure.util.InvalidNumberException;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
import org.whispersystems.textsecure.api.util.InvalidNumberException;
|
||||
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -21,8 +21,10 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.database.model.DisplayRecord;
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.database.model.ThreadRecord;
|
||||
@@ -30,8 +32,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.whispersystems.libaxolotl.InvalidMessageException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
@@ -451,9 +451,9 @@ public class ThreadDatabase extends Database {
|
||||
long type = cursor.getLong(cursor.getColumnIndexOrThrow(ThreadDatabase.SNIPPET_TYPE));
|
||||
String body = cursor.getString(cursor.getColumnIndexOrThrow(SNIPPET));
|
||||
|
||||
if (!Util.isEmpty(body) && masterCipher != null && MmsSmsColumns.Types.isSymmetricEncryption(type)) {
|
||||
if (!TextUtils.isEmpty(body) && masterCipher != null && MmsSmsColumns.Types.isSymmetricEncryption(type)) {
|
||||
return new DisplayRecord.Body(masterCipher.decryptBody(body), true);
|
||||
} else if (!Util.isEmpty(body) && masterCipher == null && MmsSmsColumns.Types.isSymmetricEncryption(type)) {
|
||||
} else if (!TextUtils.isEmpty(body) && masterCipher == null && MmsSmsColumns.Types.isSymmetricEncryption(type)) {
|
||||
return new DisplayRecord.Body(body, false);
|
||||
} else {
|
||||
return new DisplayRecord.Body(body, true);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.database;
|
||||
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
@@ -198,7 +199,7 @@ public class XmlBackup {
|
||||
}
|
||||
|
||||
private String escapeXML(String s) {
|
||||
if (Util.isEmpty(s)) return s;
|
||||
if (TextUtils.isEmpty(s)) return s;
|
||||
|
||||
Matcher matcher = PATTERN.matcher( s.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
|
||||
@@ -13,7 +13,7 @@ import android.support.v4.content.AsyncTaskLoader;
|
||||
|
||||
|
||||
import com.google.i18n.phonenumbers.PhoneNumberUtil;
|
||||
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
|
||||
import org.whispersystems.textsecure.api.util.PhoneNumberFormatter;
|
||||
|
||||
public class CountryListLoader extends AsyncTaskLoader<ArrayList<Map<String, String>>> {
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ import org.thoughtcrime.securesms.database.SmsDatabase;
|
||||
import org.thoughtcrime.securesms.protocol.Tag;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
/**
|
||||
* The message record model which represents standard SMS messages.
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.thoughtcrime.securesms.database.model;
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.StyleSpan;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
@@ -26,7 +27,6 @@ import org.thoughtcrime.securesms.database.MmsSmsColumns;
|
||||
import org.thoughtcrime.securesms.database.SmsDatabase;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.whispersystems.textsecure.util.Util;
|
||||
|
||||
/**
|
||||
* The message record model which represents thread heading messages.
|
||||
@@ -73,7 +73,7 @@ public class ThreadRecord extends DisplayRecord {
|
||||
} else if (MmsSmsColumns.Types.isLegacyType(type)) {
|
||||
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
|
||||
} else {
|
||||
if (Util.isEmpty(getBody().getBody())) {
|
||||
if (TextUtils.isEmpty(getBody().getBody())) {
|
||||
return new SpannableString(context.getString(R.string.MessageNotifier_no_subject));
|
||||
} else {
|
||||
return new SpannableString(getBody().getBody());
|
||||
|
||||
Reference in New Issue
Block a user