summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-22 19:51:59 -0700
committerSteve Howard <showard@google.com>2010-09-22 20:04:04 -0700
commit73f5f223477795e10079d25c1eb5f796af1f00a9 (patch)
tree5e2f8f1f29451dcbe7ab8d4e6d4dbeead09b9200 /src
parentece96c7475696d8b447bb8523f4ad83c897002ea (diff)
downloadandroid_packages_providers_DownloadProvider-73f5f223477795e10079d25c1eb5f796af1f00a9.tar.gz
android_packages_providers_DownloadProvider-73f5f223477795e10079d25c1eb5f796af1f00a9.tar.bz2
android_packages_providers_DownloadProvider-73f5f223477795e10079d25c1eb5f796af1f00a9.zip
DB migration to eliminate some null fields in old downloads
The DownloadProvider now ensures that current bytes, total bytes, title and description are never null in the DB. Some new code relies on this assumption for simplicity. That means we need to ensure this invariant is true for pre-existing downloads as well. Change-Id: Iea2289516d2636edf3394678ab08aa9cea31dc69
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/downloads/DownloadProvider.java29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 26065015..2cbf7fbb 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -57,7 +57,7 @@ public final class DownloadProvider extends ContentProvider {
/** Database filename */
private static final String DB_NAME = "downloads.db";
/** Current database version */
- private static final int DB_VERSION = 104;
+ private static final int DB_VERSION = 105;
/** Name of table in the database */
private static final String DB_TABLE = "downloads";
@@ -228,12 +228,38 @@ public final class DownloadProvider extends ContentProvider {
"INTEGER NOT NULL DEFAULT 0");
break;
+ case 105:
+ fillNullValues(db);
+ break;
+
default:
throw new IllegalStateException("Don't know how to upgrade to " + version);
}
}
/**
+ * insert() now ensures these four columns are never null for new downloads, so this method
+ * makes that true for existing columns, so that code can rely on this assumption.
+ */
+ private void fillNullValues(SQLiteDatabase db) {
+ ContentValues values = new ContentValues();
+ values.put(Downloads.Impl.COLUMN_CURRENT_BYTES, 0);
+ fillNullValuesForColumn(db, values);
+ values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, -1);
+ fillNullValuesForColumn(db, values);
+ values.put(Downloads.Impl.COLUMN_TITLE, "");
+ fillNullValuesForColumn(db, values);
+ values.put(Downloads.Impl.COLUMN_DESCRIPTION, "");
+ fillNullValuesForColumn(db, values);
+ }
+
+ private void fillNullValuesForColumn(SQLiteDatabase db, ContentValues values) {
+ String column = values.valueSet().iterator().next().getKey();
+ db.update(DB_TABLE, values, column + " is null", null);
+ values.clear();
+ }
+
+ /**
* Set all existing downloads to the cache partition to be invisible in the downloads UI.
*/
private void makeCacheDownloadsInvisible(SQLiteDatabase db) {
@@ -463,6 +489,7 @@ public final class DownloadProvider extends ContentProvider {
copyStringWithDefault(Downloads.Impl.COLUMN_TITLE, values, filteredValues, "");
copyStringWithDefault(Downloads.Impl.COLUMN_DESCRIPTION, values, filteredValues, "");
filteredValues.put(Downloads.Impl.COLUMN_TOTAL_BYTES, -1);
+ filteredValues.put(Downloads.Impl.COLUMN_CURRENT_BYTES, 0);
if (values.containsKey(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI)) {
copyBoolean(Downloads.Impl.COLUMN_IS_VISIBLE_IN_DOWNLOADS_UI, values, filteredValues);