Bug 1183069 - Copy removed fields from android.provider.Browser to LegacyBrowserProvider. r=rnewman
authorSebastian Kaspari <s.kaspari@gmail.com>
Mon, 03 Aug 2015 17:04:27 +0200
changeset 288246 2e605777f948abaa33d6c02b68009f360ccd21f2
parent 288245 0cd73195817b22bf8d371fc9a5c81ffeb269459d
child 288247 80f658adde86a079434d32702cadc281e386f51a
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1183069
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1183069 - Copy removed fields from android.provider.Browser to LegacyBrowserProvider. r=rnewman
mobile/android/base/db/LocalBrowserDB.java
mobile/android/base/preferences/AndroidImport.java
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -50,17 +50,16 @@ import android.content.ContentValues;
 import android.content.Context;
 import android.database.ContentObserver;
 import android.database.Cursor;
 import android.database.CursorWrapper;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
 import android.net.Uri;
-import android.provider.Browser;
 import android.text.TextUtils;
 import android.util.Log;
 import org.mozilla.gecko.util.IOUtils;
 
 import static org.mozilla.gecko.util.IOUtils.ConsumedInputStream;
 import static org.mozilla.gecko.favicons.LoadFaviconTask.DEFAULT_FAVICON_BUFFER_SIZE;
 
 public class LocalBrowserDB implements BrowserDB {
@@ -884,17 +883,17 @@ public class LocalBrowserDB implements B
         int updated  = cr.update(mParentsUriWithProfile, values, where, args);
         debug("Updated " + updated + " rows to new modified time.");
     }
 
     private void addBookmarkItem(ContentResolver cr, String title, String uri, long folderId) {
         final long now = System.currentTimeMillis();
         ContentValues values = new ContentValues();
         if (title != null) {
-            values.put(Browser.BookmarkColumns.TITLE, title);
+            values.put(Bookmarks.TITLE, title);
         }
 
         values.put(Bookmarks.URL, uri);
         values.put(Bookmarks.PARENT, folderId);
         values.put(Bookmarks.DATE_MODIFIED, now);
 
         // Get the page's favicon ID from the history table
         final Cursor c = cr.query(mHistoryUriWithProfile,
@@ -987,17 +986,17 @@ public class LocalBrowserDB implements B
     public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) {
         cr.registerContentObserver(mBookmarksUriWithProfile, false, observer);
     }
 
     @Override
     @RobocopTarget
     public void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword) {
         ContentValues values = new ContentValues();
-        values.put(Browser.BookmarkColumns.TITLE, title);
+        values.put(Bookmarks.TITLE, title);
         values.put(Bookmarks.URL, uri);
         values.put(Bookmarks.KEYWORD, keyword);
         values.put(Bookmarks.DATE_MODIFIED, System.currentTimeMillis());
 
         cr.update(mBookmarksUriWithProfile,
                   values,
                   Bookmarks._ID + " = ?",
                   new String[] { String.valueOf(id) });
--- a/mobile/android/base/preferences/AndroidImport.java
+++ b/mobile/android/base/preferences/AndroidImport.java
@@ -10,23 +10,44 @@ import org.mozilla.gecko.db.BrowserContr
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.LocalBrowserDB;
 
 import android.content.ContentProviderOperation;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.OperationApplicationException;
 import android.database.Cursor;
+import android.net.Uri;
 import android.os.RemoteException;
-import android.provider.Browser;
+import android.provider.BaseColumns;
 import android.util.Log;
 
 import java.util.ArrayList;
 
 class AndroidImport implements Runnable {
+    /**
+     * The Android M SDK removed several fields and methods from android.provider.Browser. This class is used as a
+     * replacement to support building with the new SDK but at the same time still use these fields on lower Android
+     * versions.
+     */
+    private static class LegacyBrowserProvider {
+        public static final Uri BOOKMARKS_URI = Uri.parse("content://browser/bookmarks");
+
+        // Incomplete: This are just the fields we currently use in our code base
+        public static class BookmarkColumns implements BaseColumns {
+            public static final String URL = "url";
+            public static final String VISITS = "visits";
+            public static final String DATE = "date";
+            public static final String BOOKMARK = "bookmark";
+            public static final String TITLE = "title";
+            public static final String CREATED = "created";
+            public static final String FAVICON = "favicon";
+        }
+    }
+
     private static final String LOGTAG = "AndroidImport";
     private final Context mContext;
     private final Runnable mOnDoneRunnable;
     private final ArrayList<ContentProviderOperation> mOperations;
     private final ContentResolver mCr;
     private final LocalBrowserDB mDB;
     private final boolean mImportBookmarks;
     private final boolean mImportHistory;
@@ -40,28 +61,28 @@ class AndroidImport implements Runnable 
         mDB = new LocalBrowserDB(GeckoProfile.get(context).getName());
         mImportBookmarks = doBookmarks;
         mImportHistory = doHistory;
     }
 
     public void mergeBookmarks() {
         Cursor cursor = null;
         try {
-            cursor = mCr.query(Browser.BOOKMARKS_URI,
+            cursor = mCr.query(LegacyBrowserProvider.BOOKMARKS_URI,
                                null,
-                               Browser.BookmarkColumns.BOOKMARK + " = 1",
+                               LegacyBrowserProvider.BookmarkColumns.BOOKMARK + " = 1",
                                null,
                                null);
 
             if (cursor != null) {
-                final int faviconCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.FAVICON);
-                final int titleCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.TITLE);
-                final int urlCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.URL);
+                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(Browser.BookmarkColumns.CREATED);
+                final int createCol = cursor.getColumnIndex(LegacyBrowserProvider.BookmarkColumns.CREATED);
 
                 cursor.moveToFirst();
                 while (!cursor.isAfterLast()) {
                     String url = cursor.getString(urlCol);
                     String title = cursor.getString(titleCol);
                     long created;
                     if (createCol >= 0) {
                         created = cursor.getLong(createCol);
@@ -88,29 +109,29 @@ class AndroidImport implements Runnable 
         }
 
         flushBatchOperations();
     }
 
     public void mergeHistory() {
         Cursor cursor = null;
         try {
-            cursor = mCr.query(Browser.BOOKMARKS_URI,
+            cursor = mCr.query(LegacyBrowserProvider.BOOKMARKS_URI,
                                null,
-                               Browser.BookmarkColumns.BOOKMARK + " = 0 AND " +
-                               Browser.BookmarkColumns.VISITS + " > 0",
+                               LegacyBrowserProvider.BookmarkColumns.BOOKMARK + " = 0 AND " +
+                               LegacyBrowserProvider.BookmarkColumns.VISITS + " > 0",
                                null,
                                null);
 
             if (cursor != null) {
-                final int dateCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.DATE);
-                final int faviconCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.FAVICON);
-                final int titleCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.TITLE);
-                final int urlCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.URL);
-                final int visitsCol = cursor.getColumnIndexOrThrow(Browser.BookmarkColumns.VISITS);
+                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);
 
                 cursor.moveToFirst();
                 while (!cursor.isAfterLast()) {
                     String url = cursor.getString(urlCol);
                     String title = cursor.getString(titleCol);
                     long date = cursor.getLong(dateCol);
                     int visits = cursor.getInt(visitsCol);
                     byte[] data = cursor.getBlob(faviconCol);