Bug 698828 - Fix add bookmark operation in Honeycomb/ICS (r=blassey, a=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Tue, 13 Dec 2011 13:44:54 +0000
changeset 82480 71a7af64da861a5c20ecd2b98b148eb88a263a9b
parent 82479 98037e1999a63650649f4e25b969bb5e04afb8e0
child 82481 00e184077825245191cba615b15d7d9a69cc33e5
push id21625
push userlrocha@mozilla.com
push dateTue, 13 Dec 2011 13:45:48 +0000
treeherdermozilla-central@00e184077825 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey, mfinkle
bugs698828
milestone11.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 698828 - Fix add bookmark operation in Honeycomb/ICS (r=blassey, a=mfinkle)
mobile/android/base/db/AndroidBrowserDB.java
--- a/mobile/android/base/db/AndroidBrowserDB.java
+++ b/mobile/android/base/db/AndroidBrowserDB.java
@@ -51,16 +51,19 @@ import android.net.Uri;
 import android.os.Build;
 import android.provider.Browser;
 import android.provider.Browser.BookmarkColumns;
 
 public class AndroidBrowserDB implements BrowserDB.BrowserDBIface {
     private static final String URL_COLUMN_ID = "_id";
     private static final String URL_COLUMN_THUMBNAIL = "thumbnail";
 
+    // Only available on Android >= 11
+    private static final String URL_COLUMN_DELETED = "deleted";
+
     private static final Uri BOOKMARKS_CONTENT_URI_POST_11 = Uri.parse("content://com.android.browser/bookmarks");
 
     public Cursor filter(ContentResolver cr, CharSequence constraint, int limit) {
         Cursor c = cr.query(Browser.BOOKMARKS_URI,
                             new String[] { URL_COLUMN_ID,
                                            BookmarkColumns.URL,
                                            BookmarkColumns.TITLE,
                                            BookmarkColumns.FAVICON,
@@ -149,17 +152,17 @@ public class AndroidBrowserDB implements
                                  Browser.BookmarkColumns.URL);
 
         int count = cursor.getCount();
         cursor.close();
 
         return (count == 1);
     }
 
-    public void addBookmark(ContentResolver cr, String title, String uri) {
+    public void addBookmarkPre11(ContentResolver cr, String title, String uri) {
         Cursor cursor = cr.query(Browser.BOOKMARKS_URI,
                                  new String[] { BookmarkColumns.URL },
                                  Browser.BookmarkColumns.URL + " = ?",
                                  new String[] { uri },
                                  Browser.BookmarkColumns.URL);
 
         ContentValues values = new ContentValues();
         values.put(Browser.BookmarkColumns.BOOKMARK, "1");
@@ -175,16 +178,38 @@ public class AndroidBrowserDB implements
             // add a new entry
             values.put(Browser.BookmarkColumns.URL, uri);
             cr.insert(Browser.BOOKMARKS_URI, values);
         }
 
         cursor.close();
     }
 
+    public void addBookmarkPost11(ContentResolver cr, String title, String uri) {
+        ContentValues values = new ContentValues();
+        values.put(Browser.BookmarkColumns.TITLE, title);
+        values.put(Browser.BookmarkColumns.URL, uri);
+        values.put(URL_COLUMN_DELETED, "0");
+
+        int updated = cr.update(BOOKMARKS_CONTENT_URI_POST_11,
+                                values,
+                                Browser.BookmarkColumns.URL + " = ?",
+                                new String[] { uri });
+
+        if (updated == 0)
+            cr.insert(BOOKMARKS_CONTENT_URI_POST_11, values);
+    }
+
+    public void addBookmark(ContentResolver cr, String title, String uri) {
+        if (Build.VERSION.SDK_INT >= 11)
+            addBookmarkPost11(cr, title, uri);
+        else
+            addBookmarkPre11(cr, title, uri);
+    }
+
     public void removeBookmarkPre11(ContentResolver cr, String uri) {
         ContentValues values = new ContentValues();
         values.put(Browser.BookmarkColumns.BOOKMARK, "0");
 
         cr.update(Browser.BOOKMARKS_URI,
                   values,
                   Browser.BookmarkColumns.URL + " = ?",
                   new String[] { uri });