OSDN Git Service

NoMan: Fix notification sqlite log schema
authorChristoph Studer <chstuder@google.com>
Mon, 4 Aug 2014 12:31:25 +0000 (14:31 +0200)
committerChristoph Studer <chstuder@google.com>
Mon, 4 Aug 2014 14:18:29 +0000 (16:18 +0200)
The 'log' table creation SQLite code had syntax errors
and left the table in a weird state.

This CL fixes the creation syntax and drops old tables
since they might be in an inconsistent state.

Bug: 16726344
Change-Id: I241d08c9e30cedf27ca37bfaf349975077de222d

services/core/java/com/android/server/notification/NotificationUsageStats.java

index 9b56464..4a7a971 100644 (file)
@@ -468,7 +468,7 @@ public class NotificationUsageStats {
         private static final int MSG_DISMISS = 4;
 
         private static final String DB_NAME = "notification_log.db";
-        private static final int DB_VERSION = 3;
+        private static final int DB_VERSION = 4;
 
         /** Age in ms after which events are pruned from the DB. */
         private static final long HORIZON_MS = 7 * 24 * 60 * 60 * 1000L;  // 1 week
@@ -559,32 +559,19 @@ public class NotificationUsageStats {
                             COL_CATEGORY + " TEXT," +
                             COL_ACTION_COUNT + " INT," +
                             COL_POSTTIME_MS + " INT," +
-                            COL_AIRTIME_MS + " INT" +
-                            COL_FIRST_EXPANSIONTIME_MS + " INT" +
-                            COL_AIRTIME_EXPANDED_MS + " INT" +
+                            COL_AIRTIME_MS + " INT," +
+                            COL_FIRST_EXPANSIONTIME_MS + " INT," +
+                            COL_AIRTIME_EXPANDED_MS + " INT," +
                             COL_EXPAND_COUNT + " INT" +
                             ")");
                 }
 
                 @Override
                 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-                    switch (oldVersion) {
-                        case 1:
-                            // Add COL_POSTTIME_MS, COL_AIRTIME_MS columns,
-                            db.execSQL("ALTER TABLE " + TAB_LOG + " ADD COLUMN " +
-                                    COL_POSTTIME_MS + " INT");
-                            db.execSQL("ALTER TABLE " + TAB_LOG + " ADD COLUMN " +
-                                    COL_AIRTIME_MS + " INT");
-                        case 2:
-                            // Add COL_EXPANSIONTIME_MS column
-                            db.execSQL("ALTER TABLE " + TAB_LOG + " ADD COLUMN " +
-                                    COL_FIRST_EXPANSIONTIME_MS + " INT");
-                            // Add COL_AIRTIME_EXPANDED_MS column
-                            db.execSQL("ALTER TABLE " + TAB_LOG + " ADD COLUMN " +
-                                    COL_AIRTIME_EXPANDED_MS + " INT");
-                            // Add COL_EXPAND_COUNT column
-                            db.execSQL("ALTER TABLE " + TAB_LOG + " ADD COLUMN " +
-                                    COL_EXPAND_COUNT + " INT");
+                    if (oldVersion <= 3) {
+                        // Version 3 creation left 'log' in a weird state. Just reset for now.
+                        db.execSQL("DROP TABLE IF EXISTS " + TAB_LOG);
+                        onCreate(db);
                     }
                 }
             };