Blow up the Settings Search Index database if there is a Database downgrade detected

- use the onDowngrade(...) callback for blowing away the Search Index database and
recompute the Index.

Change-Id: I137b22e710dd3205063cf8ce239105b2f1c5278b
diff --git a/src/com/android/settings/search/IndexDatabaseHelper.java b/src/com/android/settings/search/IndexDatabaseHelper.java
index 88ac4e7..e16f6d5 100644
--- a/src/com/android/settings/search/IndexDatabaseHelper.java
+++ b/src/com/android/settings/search/IndexDatabaseHelper.java
@@ -134,16 +134,43 @@
     }
 
     @Override
+    public void onOpen(SQLiteDatabase db) {
+        super.onOpen(db);
+
+        Log.i(TAG, "Using schema version: " + db.getVersion());
+
+        if (!Build.VERSION.INCREMENTAL.equals(getBuildVersion(db))) {
+            Log.w(TAG, "Index needs to be rebuilt as build-version is not the same");
+            // We need to drop the tables and recreate them
+            reconstruct(db);
+        } else {
+            Log.i(TAG, "Index is fine");
+        }
+    }
+
+    @Override
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
         if (oldVersion == 100 || oldVersion == 101 || oldVersion == 102 || oldVersion == 103) {
-            Log.w(TAG, "Detected schema version 100, 101, 102 or 103. " +
-                    "Index needs to be rebuilt for schema version 104");
+            Log.w(TAG, "Detected schema version '" +  oldVersion + "'. " +
+                    "Index needs to be rebuilt for schema version '" + newVersion + "'.");
             // We need to drop the tables and recreate them
-            dropTables(db);
-            bootstrapDB(db);
+            reconstruct(db);
         }
     }
 
+    @Override
+    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+        Log.w(TAG, "Detected schema version '" +  oldVersion + "'. " +
+                "Index needs to be rebuilt for schema version '" + newVersion + "'.");
+        // We need to drop the tables and recreate them
+        reconstruct(db);
+    }
+
+    private void reconstruct(SQLiteDatabase db) {
+        dropTables(db);
+        bootstrapDB(db);
+    }
+
     private String getBuildVersion(SQLiteDatabase db) {
         String version = null;
         Cursor cursor = null;
@@ -168,20 +195,4 @@
         db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_META_INDEX);
         db.execSQL("DROP TABLE IF EXISTS " + Tables.TABLE_PREFS_INDEX);
     }
-
-    @Override
-    public void onOpen(SQLiteDatabase db) {
-        super.onOpen(db);
-
-        Log.i(TAG, "Using schema version: " + db.getVersion());
-
-        if (!Build.VERSION.INCREMENTAL.equals(getBuildVersion(db))) {
-            Log.w(TAG, "Index needs to be rebuilt as build-version is not the same");
-            // We need to drop the tables and recreate them
-            dropTables(db);
-            bootstrapDB(db);
-        } else {
-            Log.i(TAG, "Index is fine");
-        }
-    }
 }