Bug 752444 - Detect missing Mobile root folders and fix. r=lucasr a=jpr MOBILE140_2012050917_RELBRANCH FENNEC_14_0b1_BUILD3 FENNEC_14_0b1_RELEASE
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Thu, 10 May 2012 17:10:09 +0200
branchMOBILE140_2012050917_RELBRANCH
changeset 94207 14ce1b84167697e7ed411246ecd1dd0320b73278
parent 94192 f0a97d9b107a223be9416830c04c28d0de286b69
child 94208 95cfe1618e7df116190881f17f6be343f5012d51
push idunknown
push userunknown
push dateunknown
reviewerslucasr, jpr
bugs752444
milestone14.0
Bug 752444 - Detect missing Mobile root folders and fix. r=lucasr a=jpr
mobile/android/base/ProfileMigrator.java
--- a/mobile/android/base/ProfileMigrator.java
+++ b/mobile/android/base/ProfileMigrator.java
@@ -122,16 +122,24 @@ public class ProfileMigrator {
     private static final String ROOT_QUERY =
         "SELECT root_name, folder_id FROM moz_bookmarks_roots";
     private static final String ROOT_NAME      = "root_name";
     private static final String ROOT_FOLDER_ID = "folder_id";
 
     // We use this to ignore the tags folder during migration.
     private static final String ROOT_TAGS_FOLDER_NAME = "tags";
 
+    // Find the Mobile bookmarks root in places (bug 746860).
+    // We cannot rely on the name as that is locale-dependent.
+    // If it exists, it will have Id=6, fk=null, type=folder.
+    private static final String MOBILE_ROOT_QUERY =
+        "SELECT id FROM moz_bookmarks " +
+        "WHERE id=6 AND type=2 AND fk IS NULL AND parent=1";
+    private static final String MOBILE_ROOT_ID = "id";
+
     private static final String BOOKMARK_QUERY_SELECT =
         "SELECT places.url             AS p_url,"         +
         "       bookmark.guid          AS b_guid,"        +
         "       bookmark.id            AS b_id,"          +
         "       bookmark.title         AS b_title,"       +
         "       bookmark.type          AS b_type,"        +
         "       bookmark.parent        AS b_parent,"      +
         "       bookmark.dateAdded     AS b_added,"       +
@@ -666,16 +674,32 @@ public class ProfileMigrator {
                     // Keep track of the tags folder id so we can avoid
                     // migrating tags later.
                     if (ROOT_TAGS_FOLDER_NAME.equals(name))
                         mTagsPlacesFolderId = placesFolderId;
 
                     cursor.moveToNext();
                 }
                 cursor.close();
+
+                // XUL Fennec doesn't mark the Mobile folder as a root,
+                // so fix that up here.
+                cursor = db.rawQuery(MOBILE_ROOT_QUERY, null);
+                if (cursor.moveToFirst()) {
+                    Log.v(LOGTAG, "Mobile root found, adding to known roots.");
+                    final int idCol = cursor.getColumnIndex(MOBILE_ROOT_ID);
+                    final long mobileRootId = cursor.getLong(idCol);
+                    mRerootMap.put(mobileRootId, getFolderId(Bookmarks.MOBILE_FOLDER_GUID));
+                    Log.v(LOGTAG, "Name: mobile, pid=" + mobileRootId
+                          + ", nid=" + mRerootMap.get(mobileRootId));
+                } else {
+                    Log.v(LOGTAG, "Mobile root not found, is this a desktop profile?");
+                }
+                cursor.close();
+
             } catch (SQLiteBridgeException e) {
                 Log.e(LOGTAG, "Failed to get bookmark roots: ", e);
                 // Do not try again.
                 setMigratedBookmarks();
                 return;
             }
         }