Bug 1233048 - fix crash in AndroidImport.run(AndroidImport.java). r=liuche a=ritu
authorSwaroop Rao <swaroop.rao@gmail.com>
Mon, 21 Dec 2015 18:17:00 +0100
changeset 305969 28d49ead7a229ce2afba5b4d568d4a795d019ea5
parent 305968 29d96e53182f2b4753d66876963ba2fc8ed89aa1
child 305970 5ef50d105edf23c945779479a114e094702a1df1
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, ritu
bugs1233048
milestone44.0
Bug 1233048 - fix crash in AndroidImport.run(AndroidImport.java). r=liuche a=ritu
mobile/android/base/preferences/AndroidImport.java
--- a/mobile/android/base/preferences/AndroidImport.java
+++ b/mobile/android/base/preferences/AndroidImport.java
@@ -66,25 +66,19 @@ public class AndroidImport implements Ru
         mDB = new LocalBrowserDB(GeckoProfile.get(context).getName());
         mImportBookmarks = doBookmarks;
         mImportHistory = doHistory;
     }
 
     public void mergeBookmarks() {
         Cursor cursor = null;
         try {
-            cursor = mCr.query(LegacyBrowserProvider.BOOKMARKS_URI,
-                               null,
-                               LegacyBrowserProvider.BookmarkColumns.BOOKMARK + " = 1",
-                               null,
-                               null);
-
-            if (Build.MANUFACTURER.equals(SAMSUNG_MANUFACTURER) && cursor != null && cursor.getCount() == 0) {
-                cursor = mCr.query(SAMSUNG_BOOKMARKS_URI, null, null, null, null);
-            }
+            cursor = query(LegacyBrowserProvider.BOOKMARKS_URI,
+                               SAMSUNG_BOOKMARKS_URI,
+                               LegacyBrowserProvider.BookmarkColumns.BOOKMARK + " = 1");
 
             if (cursor != null) {
                 final int faviconCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.FAVICON);
                 final int titleCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.TITLE);
                 final int urlCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.URL);
                 // http://code.google.com/p/android/issues/detail?id=17969
                 final int createCol = cursor.getColumnIndex(LegacyBrowserProvider.BookmarkColumns.CREATED);
 
@@ -118,26 +112,20 @@ public class AndroidImport implements Ru
         }
 
         flushBatchOperations();
     }
 
     public void mergeHistory() {
         Cursor cursor = null;
         try {
-            cursor = mCr.query(LegacyBrowserProvider.BOOKMARKS_URI,
-                               null,
-                               LegacyBrowserProvider.BookmarkColumns.BOOKMARK + " = 0 AND " +
-                               LegacyBrowserProvider.BookmarkColumns.VISITS + " > 0",
-                               null,
-                               null);
-
-            if (Build.MANUFACTURER.equals(SAMSUNG_MANUFACTURER) && cursor.getCount() == 0) {
-                cursor = mCr.query(SAMSUNG_HISTORY_URI, null, null, null, null);
-            }
+            cursor = query (LegacyBrowserProvider.BOOKMARKS_URI,
+                                SAMSUNG_HISTORY_URI,
+                                LegacyBrowserProvider.BookmarkColumns.BOOKMARK + " = 0 AND " +
+                                LegacyBrowserProvider.BookmarkColumns.VISITS + " > 0");
 
             if (cursor != null) {
                 final int dateCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.DATE);
                 final int faviconCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.FAVICON);
                 final int titleCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.TITLE);
                 final int urlCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.URL);
                 final int visitsCol = cursor.getColumnIndexOrThrow(LegacyBrowserProvider.BookmarkColumns.VISITS);
 
@@ -158,16 +146,26 @@ public class AndroidImport implements Ru
         } finally {
             if (cursor != null)
                 cursor.close();
         }
 
         flushBatchOperations();
     }
 
+    protected Cursor query (Uri mainUri, Uri fallbackUri, String condition) {
+        Cursor cursor = mCr.query(mainUri, null, condition, null, null);
+
+        if (Build.MANUFACTURER.equals(SAMSUNG_MANUFACTURER) && (cursor == null || cursor.getCount() == 0)) {
+            cursor = mCr.query(fallbackUri, null, null, null, null);
+        }
+
+        return cursor;
+    }
+
     protected void flushBatchOperations() {
         Log.d(LOGTAG, "Flushing " + mOperations.size() + " DB operations");
         try {
             // We don't really care for the results, this is best-effort.
             mCr.applyBatch(BrowserContract.AUTHORITY, mOperations);
         } catch (RemoteException e) {
             Log.e(LOGTAG, "Remote exception while updating db: ", e);
         } catch (OperationApplicationException e) {