Merge "Adding DELETED column to SMS raw table to support message de-duping." into nyc-dev
diff --git a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
index 7e6a4c9..6ff0bff 100644
--- a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
+++ b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
@@ -235,7 +235,7 @@
private static boolean sFakeLowStorageTest = false; // for testing only
static final String DATABASE_NAME = "mmssms.db";
- static final int DATABASE_VERSION = 62;
+ static final int DATABASE_VERSION = 63;
private final Context mContext;
private LowStorageMonitor mLowStorageMonitor;
@@ -901,7 +901,8 @@
"destination_port INTEGER," +
"address TEXT," +
"sub_id INTEGER DEFAULT " + SubscriptionManager.INVALID_SUBSCRIPTION_ID + ", " +
- "pdu TEXT);"); // the raw PDU for this part
+ "pdu TEXT," + // the raw PDU for this part
+ "deleted INTEGER DEFAULT 0);"); // bool to indicate if row is deleted
db.execSQL("CREATE TABLE attachments (" +
"sms_id INTEGER," +
@@ -1399,21 +1400,38 @@
}
// fall through
case 61:
- if (currentVersion <= 61) {
- return;
- }
+ if (currentVersion <= 61) {
+ return;
+ }
- db.beginTransaction();
- try {
- upgradeDatabaseToVersion62(db);
- db.setTransactionSuccessful();
- } catch (Throwable ex) {
- Log.e(TAG, ex.getMessage(), ex);
- break;
- } finally {
- db.endTransaction();
- }
- return;
+ db.beginTransaction();
+ try {
+ upgradeDatabaseToVersion62(db);
+ db.setTransactionSuccessful();
+ } catch (Throwable ex) {
+ Log.e(TAG, ex.getMessage(), ex);
+ break;
+ } finally {
+ db.endTransaction();
+ }
+ // fall through
+ case 62:
+ if (currentVersion <= 62) {
+ return;
+ }
+
+ db.beginTransaction();
+ try {
+ upgradeDatabaseToVersion63(db);
+ db.setTransactionSuccessful();
+ } catch (Throwable ex) {
+ Log.e(TAG, ex.getMessage(), ex);
+ break;
+ } finally {
+ db.endTransaction();
+ }
+
+ return;
}
Log.e(TAG, "Destroying all old data.");
@@ -1687,6 +1705,10 @@
" WHERE INSTR(" + Part._DATA + ", '" + partsDirName + "') > 0");
}
+ private void upgradeDatabaseToVersion63(SQLiteDatabase db) {
+ db.execSQL("ALTER TABLE " + SmsProvider.TABLE_RAW +" ADD COLUMN deleted INTEGER DEFAULT 0");
+ }
+
@Override
public synchronized SQLiteDatabase getWritableDatabase() {
SQLiteDatabase db = super.getWritableDatabase();
diff --git a/src/com/android/providers/telephony/SmsProvider.java b/src/com/android/providers/telephony/SmsProvider.java
index 3fb88c5..4d48786 100644
--- a/src/com/android/providers/telephony/SmsProvider.java
+++ b/src/com/android/providers/telephony/SmsProvider.java
@@ -61,6 +61,9 @@
new String[] { Contacts.Phones.PERSON_ID };
private static final int PERSON_ID_COLUMN = 0;
+ /** Delete any raw messages or message segments marked deleted that are older than an hour. */
+ static final long RAW_MESSAGE_EXPIRE_AGE = (long) (60 * 60 * 1000);
+
/**
* These are the columns that are available when reading SMS
* messages from the ICC. Columns whose names begin with "is_"
@@ -116,6 +119,7 @@
// Generate the body of the query.
int match = sURLMatcher.match(url);
+ SQLiteDatabase db = getDBOpenHelper(match).getReadableDatabase();
switch (match) {
case SMS_ALL:
constructQueryForBox(qb, Sms.MESSAGE_TYPE_ALL, smsTable);
@@ -204,6 +208,8 @@
break;
case SMS_RAW_MESSAGE:
+ // before querying purge old entries with deleted = 1
+ purgeDeletedMessagesInRawTable(db);
qb.setTables("raw");
break;
@@ -254,7 +260,6 @@
orderBy = Sms.DEFAULT_SORT_ORDER;
}
- SQLiteDatabase db = getDBOpenHelper(match).getReadableDatabase();
Cursor ret = qb.query(db, projectionIn, selection, selectionArgs,
null, null, orderBy);
@@ -264,6 +269,15 @@
return ret;
}
+ private void purgeDeletedMessagesInRawTable(SQLiteDatabase db) {
+ long oldTimestamp = System.currentTimeMillis() - RAW_MESSAGE_EXPIRE_AGE;
+ int num = db.delete("raw", "deleted = 1 AND date < " + oldTimestamp, null);
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.d(TAG, "purgeDeletedMessagesInRawTable: num rows older than " + oldTimestamp +
+ " purged: " + num);
+ }
+ }
+
private SQLiteOpenHelper getDBOpenHelper(int match) {
if (match == SMS_RAW_MESSAGE) {
return mDeOpenHelper;
@@ -624,7 +638,7 @@
}
return uri;
} else {
- Log.e(TAG,"insert: failed!");
+ Log.e(TAG, "insert: failed!");
}
return null;
@@ -673,7 +687,20 @@
break;
case SMS_RAW_MESSAGE:
+ ContentValues cv = new ContentValues();
+ cv.put("deleted", 1);
+ count = db.update("raw", cv, where, whereArgs);
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.d(TAG, "delete: num rows marked deleted in raw table: " + count);
+ }
+ notifyIfNotDefault = false;
+ break;
+
+ case SMS_RAW_MESSAGE_PERMANENT_DELETE:
count = db.delete("raw", where, whereArgs);
+ if (Log.isLoggable(TAG, Log.VERBOSE)) {
+ Log.d(TAG, "delete: num rows permanently deleted in raw table: " + count);
+ }
notifyIfNotDefault = false;
break;
@@ -854,6 +881,7 @@
private static final int SMS_FAILED_ID = 25;
private static final int SMS_QUEUED = 26;
private static final int SMS_UNDELIVERED = 27;
+ private static final int SMS_RAW_MESSAGE_PERMANENT_DELETE = 28;
private static final UriMatcher sURLMatcher =
new UriMatcher(UriMatcher.NO_MATCH);
@@ -876,6 +904,7 @@
sURLMatcher.addURI("sms", "conversations", SMS_CONVERSATIONS);
sURLMatcher.addURI("sms", "conversations/*", SMS_CONVERSATIONS_ID);
sURLMatcher.addURI("sms", "raw", SMS_RAW_MESSAGE);
+ sURLMatcher.addURI("sms", "raw/permanentDelete", SMS_RAW_MESSAGE_PERMANENT_DELETE);
sURLMatcher.addURI("sms", "attachments", SMS_ATTACHMENT);
sURLMatcher.addURI("sms", "attachments/#", SMS_ATTACHMENT_ID);
sURLMatcher.addURI("sms", "threadID", SMS_NEW_THREAD_ID);