Removed tabs

This commit is contained in:
Moxie Marlinspike 2012-09-30 19:56:29 -07:00
parent 030b39cd9c
commit 82f8ba3584
35 changed files with 635 additions and 649 deletions

View File

@ -36,14 +36,15 @@ import org.thoughtcrime.securesms.util.MemoryCleaner;
*
* @author Moxie Marlinspike
*/
public class PassphraseCreateActivity extends PassphraseActivity {
private EditText passphraseEdit;
private EditText passphraseRepeatEdit;
private Button okButton;
private Button cancelButton;
private EditText passphraseEdit;
private EditText passphraseRepeatEdit;
private Button okButton;
private Button cancelButton;
public PassphraseCreateActivity() { }
public PassphraseCreateActivity() { }
@Override
public void onCreate(Bundle savedInstanceState) {

View File

@ -177,11 +177,11 @@ public class ReviewIdentitiesActivity extends SherlockListActivity {
boolean valid;
String identityKeyString = cursor.getString(cursor.getColumnIndexOrThrow(IdentityDatabase.IDENTITY_KEY));
String identityName = cursor.getString(cursor.getColumnIndexOrThrow(IdentityDatabase.IDENTITY_NAME));
String identityName = cursor.getString(cursor.getColumnIndexOrThrow(IdentityDatabase.IDENTITY_NAME));
try {
String mac = cursor.getString(cursor.getColumnIndexOrThrow(IdentityDatabase.MAC));
valid = masterCipher.verifyMacFor(identityName + identityKeyString, Base64.decode(mac));
valid = masterCipher.verifyMacFor(identityName + identityKeyString, Base64.decode(mac));
identityKey = new IdentityKey(Base64.decode(identityKeyString), 0);
} catch (InvalidKeyException ike) {
Log.w("ReviewIdentitiesActivity",ike);

View File

@ -86,7 +86,7 @@ public class CanonicalAddressDatabase {
}
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -154,12 +154,12 @@ public class CanonicalAddressDatabase {
}
@Override
public void onCreate(SQLiteDatabase db) {
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}

View File

@ -16,12 +16,13 @@
*/
package org.thoughtcrime.securesms.database;
import java.io.UnsupportedEncodingException;
import android.content.ContentValues;
import android.util.Log;
import ws.com.google.android.mms.pdu.CharacterSets;
import ws.com.google.android.mms.pdu.EncodedStringValue;
import android.content.ContentValues;
import android.util.Log;
import java.io.UnsupportedEncodingException;
public class ContentValuesBuilder {

View File

@ -16,13 +16,13 @@
*/
package org.thoughtcrime.securesms.database;
import java.util.Set;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import java.util.Set;
public abstract class Database {
protected static final String ID_WHERE = "_id = ?";

View File

@ -16,17 +16,18 @@
*/
package org.thoughtcrime.securesms.database;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public class DatabaseFactory {
private static final int INTRODUCED_IDENTITIES_VERSION = 2;
private static final int DATABASE_VERSION = 2;
private static final int INTRODUCED_IDENTITIES_VERSION = 2;
private static final int DATABASE_VERSION = 2;
private static final String DATABASE_NAME = "messages.db";
private static final Object lock = new Object();
@ -146,14 +147,13 @@ public class DatabaseFactory {
db.execSQL(ThreadDatabase.CREATE_TABLE);
db.execSQL(MmsAddressDatabase.CREATE_TABLE);
db.execSQL(IdentityDatabase.CREATE_TABLE);
// db.execSQL(CanonicalAddress.CREATE_TABLE);
// db.execSQL(CanonicalAddress.CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < INTRODUCED_IDENTITIES_VERSION)
db.execSQL(IdentityDatabase.CREATE_TABLE);
db.execSQL(IdentityDatabase.CREATE_TABLE);
}
}
}

View File

@ -16,11 +16,11 @@
*/
package org.thoughtcrime.securesms.database;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import org.thoughtcrime.securesms.crypto.MasterSecret;
public class EncryptingMmsDatabase extends MmsDatabase {
private final MasterSecret masterSecret;
@ -31,7 +31,7 @@ public class EncryptingMmsDatabase extends MmsDatabase {
}
@Override
protected PartDatabase getPartDatabase() {
protected PartDatabase getPartDatabase() {
return DatabaseFactory.getEncryptingPartDatabase(context, masterSecret);
}

View File

@ -16,19 +16,20 @@
*/
package org.thoughtcrime.securesms.database;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.DecryptingPartInputStream;
import org.thoughtcrime.securesms.crypto.EncryptingPartOutputStream;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import ws.com.google.android.mms.pdu.PduPart;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class EncryptingPartDatabase extends PartDatabase {

View File

@ -16,16 +16,16 @@
*/
package org.thoughtcrime.securesms.database;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.telephony.SmsMessage;
import org.thoughtcrime.securesms.crypto.AsymmetricMasterCipher;
import org.thoughtcrime.securesms.crypto.AsymmetricMasterSecret;
import org.thoughtcrime.securesms.crypto.MasterCipher;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.protocol.Prefix;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.telephony.SmsMessage;
public class EncryptingSmsDatabase extends SmsDatabase {
public EncryptingSmsDatabase(Context context, SQLiteOpenHelper databaseHelper) {

View File

@ -16,11 +16,6 @@
*/
package org.thoughtcrime.securesms.database;
import java.io.UnsupportedEncodingException;
import ws.com.google.android.mms.pdu.CharacterSets;
import ws.com.google.android.mms.pdu.EncodedStringValue;
import ws.com.google.android.mms.pdu.PduHeaders;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@ -28,13 +23,19 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import ws.com.google.android.mms.pdu.CharacterSets;
import ws.com.google.android.mms.pdu.EncodedStringValue;
import ws.com.google.android.mms.pdu.PduHeaders;
import java.io.UnsupportedEncodingException;
public class MmsAddressDatabase extends Database {
private static final String TABLE_NAME = "mms_addresses";
private static final String ID = "_id";
private static final String MMS_ID = "mms_id";
private static final String TYPE = "type";
private static final String ADDRESS = "address";
private static final String ADDRESS = "address";
private static final String ADDRESS_CHARSET = "address_charset";
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" + ID + " INTEGER PRIMARY KEY, " +
@ -97,7 +98,7 @@ public class MmsAddressDatabase extends Database {
}
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -120,7 +121,6 @@ public class MmsAddressDatabase extends Database {
}
}
private String toIsoString(byte[] bytes) {
try {
return new String(bytes, CharacterSets.MIMENAME_ISO_8859_1);
@ -129,7 +129,4 @@ public class MmsAddressDatabase extends Database {
return "";
}
}
}

View File

@ -268,11 +268,11 @@ public class MmsDatabase extends Database {
while (cursor.moveToNext()) {
long messageId = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
long outboxType = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX));
PduHeaders headers = getHeadersFromCursor(cursor);
addr.getAddressesForId(messageId, headers);
PduBody body = parts.getParts(messageId, true);
requests[i++] = new SendReq(headers, body, messageId, outboxType);
long outboxType = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX));
PduHeaders headers = getHeadersFromCursor(cursor);
addr.getAddressesForId(messageId, headers);
PduBody body = parts.getParts(messageId, true);
requests[i++] = new SendReq(headers, body, messageId, outboxType);
}
return requests;
@ -342,7 +342,7 @@ public class MmsDatabase extends Database {
ContentValues contentValues = getContentValuesFromHeader(headers);
if (!isSecure) contentValues.put(MESSAGE_BOX, Types.MESSAGE_BOX_OUTBOX);
else contentValues.put(MESSAGE_BOX, Types.MESSAGE_BOX_SECURE_OUTBOX);
else contentValues.put(MESSAGE_BOX, Types.MESSAGE_BOX_SECURE_OUTBOX);
contentValues.put(THREAD_ID, threadId);
contentValues.put(READ, 1);
@ -412,7 +412,6 @@ public class MmsDatabase extends Database {
}
}
public void deleteAllThreads() {
DatabaseFactory.getPartDatabase(context).deleteAllParts();
DatabaseFactory.getMmsAddressDatabase(context).deleteAllAddresses();
@ -448,7 +447,7 @@ public class MmsDatabase extends Database {
return headers;
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -535,9 +534,8 @@ public class MmsDatabase extends Database {
public static final int DOWNLOAD_INITIALIZED = 1;
public static final int DOWNLOAD_NO_CONNECTIVITY = 2;
public static final int DOWNLOAD_CONNECTING = 3;
public static final int DOWNLOAD_SOFT_FAILURE = 4;
public static final int DOWNLOAD_HARD_FAILURE = 5;
public static final int DOWNLOAD_SOFT_FAILURE = 4;
public static final int DOWNLOAD_HARD_FAILURE = 5;
public static boolean isSecureMmsBox(long mailbox) {
return mailbox == Types.MESSAGE_BOX_SECURE_OUTBOX || mailbox == Types.MESSAGE_BOX_SECURE_SENT || mailbox == Types.MESSAGE_BOX_SECURE_INBOX;
@ -574,9 +572,5 @@ public class MmsDatabase extends Database {
public static boolean isHardError(int status) {
return status == DOWNLOAD_HARD_FAILURE;
}
}
}

View File

@ -16,9 +16,6 @@
*/
package org.thoughtcrime.securesms.database;
import java.util.HashSet;
import java.util.Set;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
@ -26,6 +23,9 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.util.Log;
import java.util.HashSet;
import java.util.Set;
public class MmsSmsDatabase extends Database {
public static final String TRANSPORT = "transport_type";

View File

@ -16,14 +16,13 @@
*/
package org.thoughtcrime.securesms.database;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import org.thoughtcrime.securesms.providers.PartProvider;
@ -32,13 +31,15 @@ import ws.com.google.android.mms.MmsException;
import ws.com.google.android.mms.pdu.CharacterSets;
import ws.com.google.android.mms.pdu.PduBody;
import ws.com.google.android.mms.pdu.PduPart;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
public class PartDatabase extends Database {
@ -123,7 +124,7 @@ public class PartDatabase extends Database {
contentValues.put(CONTENT_TYPE, toIsoString(part.getContentType()));
if (toIsoString(part.getContentType()).equals(ContentType.APP_SMIL))
contentValues.put(SEQUENCE, -1);
contentValues.put(SEQUENCE, -1);
} else {
throw new MmsException("There is no content type for this part.");
}
@ -172,7 +173,7 @@ public class PartDatabase extends Database {
int read;
while ((read = fin.read(buffer)) != -1)
baos.write(buffer, 0, read);
baos.write(buffer, 0, read);
part.setData(baos.toByteArray());
fin.close();
@ -189,23 +190,23 @@ public class PartDatabase extends Database {
FileOutputStream fout = getPartOutputStream(dataFile, part);
if (part.getData() != null) {
Log.w("PartDatabase", "Writing part data from buffer");
fout.write(part.getData());
fout.close();
return dataFile;
Log.w("PartDatabase", "Writing part data from buffer");
fout.write(part.getData());
fout.close();
return dataFile;
} else if (part.getDataUri() != null) {
Log.w("PartDatabase", "Writing part dat from URI");
byte[] buf = new byte[512];
InputStream in = context.getContentResolver().openInputStream(part.getDataUri());
int read;
while ((read = in.read(buf)) != -1)
fout.write(buf, 0, read);
Log.w("PartDatabase", "Writing part dat from URI");
byte[] buf = new byte[512];
InputStream in = context.getContentResolver().openInputStream(part.getDataUri());
int read;
while ((read = in.read(buf)) != -1)
fout.write(buf, 0, read);
fout.close();
in.close();
return dataFile;
fout.close();
in.close();
return dataFile;
} else {
throw new MmsException("Part is empty!");
throw new MmsException("Part is empty!");
}
} catch (FileNotFoundException e) {
throw new AssertionError(e);
@ -249,16 +250,16 @@ public class PartDatabase extends Database {
cursor = database.query(TABLE_NAME, new String[]{DATA, ENCRYPTED}, ID_WHERE, new String[] {partId+""}, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
PduPart part = new PduPart();
part.setEncrypted(cursor.getInt(1) == 1);
PduPart part = new PduPart();
part.setEncrypted(cursor.getInt(1) == 1);
return getPartInputStream(new File(cursor.getString(0)), part);
return getPartInputStream(new File(cursor.getString(0)), part);
} else {
throw new FileNotFoundException("No part for id: " + partId);
throw new FileNotFoundException("No part for id: " + partId);
}
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -277,12 +278,12 @@ public class PartDatabase extends Database {
cursor = database.query(TABLE_NAME, null, ID_WHERE, new String[] {partId+""}, null, null, null);
if (cursor != null && cursor.moveToFirst())
return getPart(cursor, includeData);
return getPart(cursor, includeData);
else
return null;
return null;
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -295,14 +296,14 @@ public class PartDatabase extends Database {
cursor = database.query(TABLE_NAME, null, MMS_ID + " = ?", new String[] {mmsId+""}, null, null, null);
while (cursor != null && cursor.moveToNext()) {
PduPart part = getPart(cursor, includeData);
body.addPart(part);
PduPart part = getPart(cursor, includeData);
body.addPart(part);
}
return body;
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -314,11 +315,11 @@ public class PartDatabase extends Database {
cursor = database.query(TABLE_NAME, new String[] {DATA}, MMS_ID + " = ?", new String[] {mmsId+""}, null, null, null);
while (cursor != null && cursor.moveToNext()) {
new File(cursor.getString(0)).delete();
new File(cursor.getString(0)).delete();
}
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
database.delete(TABLE_NAME, MMS_ID + " = ?", new String[] {mmsId+""});
@ -354,7 +355,4 @@ public class PartDatabase extends Database {
return "";
}
}
}

View File

@ -16,14 +16,15 @@
*/
package org.thoughtcrime.securesms.database;
import java.io.UnsupportedEncodingException;
import android.database.Cursor;
import android.util.Log;
import ws.com.google.android.mms.InvalidHeaderValueException;
import ws.com.google.android.mms.pdu.CharacterSets;
import ws.com.google.android.mms.pdu.EncodedStringValue;
import ws.com.google.android.mms.pdu.PduHeaders;
import android.database.Cursor;
import android.util.Log;
import java.io.UnsupportedEncodingException;
public class PduHeadersBuilder {

View File

@ -16,6 +16,10 @@
*/
package org.thoughtcrime.securesms.database;
import android.content.Context;
import org.thoughtcrime.securesms.util.Conversions;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -24,10 +28,6 @@ import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.thoughtcrime.securesms.util.Conversions;
import android.content.Context;
public abstract class Record {
protected final String address;

View File

@ -16,19 +16,19 @@
*/
package org.thoughtcrime.securesms.database;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import android.content.Context;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.InvalidKeyException;
import org.thoughtcrime.securesms.crypto.PublicKey;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.Hex;
import android.content.Context;
import android.util.Log;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
/**
* Represents the current and last public key belonging to the "remote"

View File

@ -16,14 +16,14 @@
*/
package org.thoughtcrime.securesms.database;
import javax.crypto.spec.SecretKeySpec;
import org.thoughtcrime.securesms.crypto.MasterCipher;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.SessionCipher;
import org.thoughtcrime.securesms.util.Conversions;
import org.thoughtcrime.securesms.util.Util;
import javax.crypto.spec.SecretKeySpec;
/**
* Represents the currently negotiated session key for a given
* local key id and remote key id. This is stored encrypted on

View File

@ -208,8 +208,8 @@ public class SessionRecord extends Record {
Log.w("SessionRecord", "No session information found.");
return;
} catch (IOException ioe) {
Log.w("keyrecord", ioe);
// XXX
Log.w("keyrecord", ioe);
// XXX
}
}
}
@ -223,5 +223,4 @@ public class SessionRecord extends Record {
return null;
}
}

View File

@ -117,12 +117,12 @@ public class SmsDatabase extends Database {
try {
cursor = db.rawQuery(sql, sqlArgs);
if (cursor != null && cursor.moveToFirst())
return cursor.getLong(0);
return cursor.getLong(0);
else
return -1;
return -1;
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -134,10 +134,10 @@ public class SmsDatabase extends Database {
cursor = db.query(TABLE_NAME, new String[] {"COUNT(*)"}, THREAD_ID + " = ?", new String[] {threadId+""}, null, null, null);
if (cursor != null && cursor.moveToFirst())
return cursor.getInt(0);
return cursor.getInt(0);
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
return 0;
@ -201,7 +201,7 @@ public class SmsDatabase extends Database {
public long insertMessageSent(String address, long threadId, String body, long date, long type) {
ContentValues contentValues = new ContentValues(6);
// contentValues.put(ADDRESS, NumberUtil.filterNumber(address));
// contentValues.put(ADDRESS, NumberUtil.filterNumber(address));
contentValues.put(ADDRESS, address);
contentValues.put(THREAD_ID, threadId);
contentValues.put(BODY, body);
@ -292,7 +292,7 @@ public class SmsDatabase extends Database {
/*package*/ SQLiteStatement createInsertStatement(SQLiteDatabase database) {
return database.compileStatement("INSERT INTO " + TABLE_NAME + " (" + ADDRESS + ", " + PERSON + ", " + DATE + ", " + PROTOCOL + ", " + READ + ", " + STATUS + ", " + TYPE + ", " + REPLY_PATH_PRESENT + ", " + SUBJECT + ", " + BODY + ", " + SERVICE_CENTER + ", THREAD_ID) " +
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
" VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
}
public static class Types {

View File

@ -54,13 +54,12 @@ public class ThreadDatabase extends Database {
super(context, databaseHelper);
}
private long[] getRecipientIds(Recipients recipients) {
Set<Long> recipientSet = new HashSet<Long>();
List<Recipient> recipientList = recipients.getRecipientsList();
for (Recipient recipient : recipientList) {
// String number = NumberUtil.filterNumber(recipient.getNumber());
// String number = NumberUtil.filterNumber(recipient.getNumber());
String number = recipient.getNumber();
recipientSet.add(Long.valueOf(DatabaseFactory.getAddressDatabase(context).getCanonicalAddress(number)));
}
@ -229,12 +228,12 @@ public class ThreadDatabase extends Database {
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
if (cursor != null && cursor.moveToFirst())
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
else
return -1L;
return -1L;
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -250,12 +249,12 @@ public class ThreadDatabase extends Database {
cursor = db.query(TABLE_NAME, new String[]{ID}, where, recipientsArg, null, null, null);
if (cursor != null && cursor.moveToFirst())
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
return cursor.getLong(cursor.getColumnIndexOrThrow(ID));
else
return createThreadForRecipients(recipientsList, recipientIds.length);
return createThreadForRecipients(recipientsList, recipientIds.length);
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
}
@ -273,22 +272,18 @@ public class ThreadDatabase extends Database {
try {
cursor = mmsSmsDatabase.getConversationSnippet(threadId);
if (cursor != null && cursor.moveToFirst())
updateThread(threadId, count,
cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY)),
cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.DATE)));
else
deleteThread(threadId);
if (cursor != null && cursor.moveToFirst()) {
updateThread(threadId, count,
cursor.getString(cursor.getColumnIndexOrThrow(SmsDatabase.BODY)),
cursor.getLong(cursor.getColumnIndexOrThrow(SmsDatabase.DATE)));
} else {
deleteThread(threadId);
}
} finally {
if (cursor != null)
cursor.close();
cursor.close();
}
notifyConversationListListeners();
}
}

View File

@ -16,14 +16,14 @@
*/
package org.thoughtcrime.securesms.protocol;
import java.nio.ByteBuffer;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.InvalidKeyException;
import org.thoughtcrime.securesms.crypto.InvalidMessageException;
import org.thoughtcrime.securesms.crypto.PublicKey;
import org.thoughtcrime.securesms.util.Conversions;
import android.util.Log;
import java.nio.ByteBuffer;
/**
* Parses and serializes the encrypted message format.

View File

@ -31,6 +31,6 @@ public class Prefix {
public static final String ASYMMETRIC_ENCRYPT = "?TextSecureAsymmetricEncrypt";
public static final String ASYMMETRIC_LOCAL_ENCRYPT = "?TextSecureAsymmetricLocalEncrypt";
public static final String PROCESSED_KEY_EXCHANGE = "?TextSecureKeyExchangd";
public static final String STALE_KEY_EXCHANGE = "?TextSecureKeyExchangs";
public static final String STALE_KEY_EXCHANGE = "?TextSecureKeyExchangs";
}

View File

@ -16,16 +16,6 @@
*/
package org.thoughtcrime.securesms.providers;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.service.KeyCachingService;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentProvider;
@ -41,6 +31,16 @@ import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.service.KeyCachingService;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class PartProvider extends ContentProvider {
private static final String CONTENT_URI_STRING = "content://org.thoughtcrime.provider.securesms/part";
@ -58,7 +58,7 @@ public class PartProvider extends ContentProvider {
private NewKeyReceiver receiver;
@Override
public boolean onCreate() {
public boolean onCreate() {
initializeMasterSecret();
return true;
}
@ -95,14 +95,14 @@ public class PartProvider extends ContentProvider {
case SINGLE_ROW:
Log.w("PartProvider", "Parting out a single row...");
try {
int partId = Integer.parseInt(uri.getPathSegments().get(1));
File tmpFile = copyPartToTemporaryFile(masterSecret, partId);
ParcelFileDescriptor pdf = ParcelFileDescriptor.open(tmpFile, ParcelFileDescriptor.MODE_READ_ONLY);
tmpFile.delete();
return pdf;
int partId = Integer.parseInt(uri.getPathSegments().get(1));
File tmpFile = copyPartToTemporaryFile(masterSecret, partId);
ParcelFileDescriptor pdf = ParcelFileDescriptor.open(tmpFile, ParcelFileDescriptor.MODE_READ_ONLY);
tmpFile.delete();
return pdf;
} catch (IOException ioe) {
Log.w("PartProvider", ioe);
throw new FileNotFoundException("Error opening file");
Log.w("PartProvider", ioe);
throw new FileNotFoundException("Error opening file");
}
}
@ -110,31 +110,30 @@ public class PartProvider extends ContentProvider {
}
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
public int delete(Uri arg0, String arg1, String[] arg2) {
return 0;
}
@Override
public String getType(Uri arg0) {
public String getType(Uri arg0) {
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues arg1) {
public Uri insert(Uri arg0, ContentValues arg1) {
return null;
}
@Override
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) {
public Cursor query(Uri arg0, String[] arg1, String arg2, String[] arg3, String arg4) {
return null;
}
@Override
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
public int update(Uri arg0, ContentValues arg1, String arg2, String[] arg3) {
return 0;
}
private void initializeWithMasterSecret(MasterSecret masterSecret) {
Log.w("PartProvider", "Got master secret: " + masterSecret);
this.masterSecret = masterSecret;
@ -151,12 +150,12 @@ public class PartProvider extends ContentProvider {
private ServiceConnection serviceConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
KeyCachingService keyCachingService = ((KeyCachingService.KeyCachingBinder)service).getService();
MasterSecret masterSecret = keyCachingService.getMasterSecret();
KeyCachingService keyCachingService = ((KeyCachingService.KeyCachingBinder)service).getService();
MasterSecret masterSecret = keyCachingService.getMasterSecret();
initializeWithMasterSecret(masterSecret);
initializeWithMasterSecret(masterSecret);
PartProvider.this.getContext().unbindService(this);
PartProvider.this.getContext().unbindService(this);
}
public void onServiceDisconnected(ComponentName name) {}
@ -164,7 +163,7 @@ public class PartProvider extends ContentProvider {
private class NewKeyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
public void onReceive(Context context, Intent intent) {
Log.w("SendReceiveService", "Got a MasterSecret broadcast...");
initializeWithMasterSecret((MasterSecret)intent.getParcelableExtra("master_secret"));
}

View File

@ -16,13 +16,13 @@
*/
package org.thoughtcrime.securesms.recipients;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
public class RecipientsFormatter {
private static String parseBracketedNumber(String recipient) throws RecipientFormattingException {

View File

@ -16,10 +16,10 @@
*/
package org.thoughtcrime.securesms.util;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
import android.util.Log;
import org.thoughtcrime.securesms.sms.SmsTransportDetails;
public class EncryptedCharacterCalculator extends CharacterCalculator {
private CharacterState calculateSingleRecordCharacters(int charactersSpent) {
@ -32,23 +32,23 @@ public class EncryptedCharacterCalculator extends CharacterCalculator {
int charactersInFirstRecord = SmsTransportDetails.ENCRYPTED_SINGLE_MESSAGE_BODY_MAX_SIZE;
int spillover = charactersSpent - charactersInFirstRecord;
Log.w("EncryptedCharacterCalculator", "Spillover: " + spillover);
// int maxMultiMessageSize = SessionCipher.getMaxBodySizePerMultiMessage(charactersSpent);
// Log.w("EncryptedCharacterCalculator", "Maxmultimessagesize: " + maxMultiMessageSize);
// int spilloverMessagesSpent = spillover / maxMultiMessageSize;
// int maxMultiMessageSize = SessionCipher.getMaxBodySizePerMultiMessage(charactersSpent);
// Log.w("EncryptedCharacterCalculator", "Maxmultimessagesize: " + maxMultiMessageSize);
// int spilloverMessagesSpent = spillover / maxMultiMessageSize;
int spilloverMessagesSpent = spillover / SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES;
Log.w("EncryptedCharacterCalculator", "Spillover messaegs spent: " + spilloverMessagesSpent);
// if ((spillover % maxMultiMessageSize) > 0)
// if ((spillover % maxMultiMessageSize) > 0)
if ((spillover % SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES) > 0)
spilloverMessagesSpent++;
Log.w("EncryptedCharacterCalculator", "Spillover messaegs spent: " + spilloverMessagesSpent);
// int charactersRemaining = (maxMultiMessageSize * spilloverMessagesSpent) - spillover;
// int charactersRemaining = (maxMultiMessageSize * spilloverMessagesSpent) - spillover;
int charactersRemaining = (SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES * spilloverMessagesSpent) - spillover;
Log.w("EncryptedCharacterCalculator", "charactersRemaining: " + charactersRemaining);
// return new CharacterState(spilloverMessagesSpent+1, charactersRemaining, maxMultiMessageSize);
// return new CharacterState(spilloverMessagesSpent+1, charactersRemaining, maxMultiMessageSize);
return new CharacterState(spilloverMessagesSpent+1, charactersRemaining, SmsTransportDetails.MULTI_MESSAGE_MAX_BYTES);
}

View File

@ -78,12 +78,12 @@ public class Hex {
int idx = i + lineOffset;
if (i < lineLength) {
int b = bytes[idx];
appendHexChar(buf, b);
appendHexChar(buf, b);
} else {
buf.append(" ");
buf.append(" ");
}
if ((i % 2) == 1) {
buf.append(' ');
buf.append(' ');
}
}

View File

@ -16,11 +16,11 @@
*/
package org.thoughtcrime.securesms.util;
import android.telephony.PhoneNumberUtils;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.telephony.PhoneNumberUtils;
public class NumberUtil {
private static final Pattern emailPattern = android.util.Patterns.EMAIL_ADDRESS;
@ -44,10 +44,9 @@ public class NumberUtil {
char character = number.charAt(i);
if (Character.isDigit(character) || character == '+')
builder.append(character);
builder.append(character);
}
return builder.toString();
}
}

View File

@ -62,28 +62,28 @@ public class Util {
return splitString;
}
// public static Bitmap loadScaledBitmap(InputStream src, int targetWidth, int targetHeight) {
// return BitmapFactory.decodeStream(src);
//// BitmapFactory.Options options = new BitmapFactory.Options();
//// options.inJustDecodeBounds = true;
//// BitmapFactory.decodeStream(src, null, options);
// public static Bitmap loadScaledBitmap(InputStream src, int targetWidth, int targetHeight) {
// return BitmapFactory.decodeStream(src);
//// BitmapFactory.Options options = new BitmapFactory.Options();
//// options.inJustDecodeBounds = true;
//// BitmapFactory.decodeStream(src, null, options);
////
//// Log.w("Util", "Bitmap Origin Width: " + options.outWidth);
//// Log.w("Util", "Bitmap Origin Height: " + options.outHeight);
//// Log.w("Util", "Bitmap Origin Width: " + options.outWidth);
//// Log.w("Util", "Bitmap Origin Height: " + options.outHeight);
////
//// boolean scaleByHeight =
//// Math.abs(options.outHeight - targetHeight) >=
//// Math.abs(options.outWidth - targetWidth);
//// boolean scaleByHeight =
//// Math.abs(options.outHeight - targetHeight) >=
//// Math.abs(options.outWidth - targetWidth);
////
//// if (options.outHeight * options.outWidth >= targetWidth * targetHeight * 2) {
//// double sampleSize = scaleByHeight ? (double)options.outHeight / (double)targetHeight : (double)options.outWidth / (double)targetWidth;
////// options.inSampleSize = (int)Math.pow(2d, Math.floor(Math.log(sampleSize) / Math.log(2d)));
//// Log.w("Util", "Sampling by: " + options.inSampleSize);
//// }
//// if (options.outHeight * options.outWidth >= targetWidth * targetHeight * 2) {
//// double sampleSize = scaleByHeight ? (double)options.outHeight / (double)targetHeight : (double)options.outWidth / (double)targetWidth;
////// options.inSampleSize = (int)Math.pow(2d, Math.floor(Math.log(sampleSize) / Math.log(2d)));
//// Log.w("Util", "Sampling by: " + options.inSampleSize);
//// }
////
//// options.inJustDecodeBounds = false;
//// options.inJustDecodeBounds = false;
////
//// return BitmapFactory.decodeStream(src, null, options);
// }
//// return BitmapFactory.decodeStream(src, null, options);
// }
}

View File

@ -30,16 +30,17 @@ public class WorkerThread extends Thread {
private Runnable getWork() {
synchronized (workQueue) {
try {
while (workQueue.isEmpty())
workQueue.wait();
while (workQueue.isEmpty())
workQueue.wait();
return workQueue.remove(0);
return workQueue.remove(0);
} catch (InterruptedException ie) {
throw new AssertionError(ie);
throw new AssertionError(ie);
}
}
}
@Override
public void run() {
for (;;)
getWork().run();