From 59f68505b7f8569473e23b1f42f1ff978411178a Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Tue, 13 Dec 2011 13:44:54 +0000 Subject: [PATCH] Bug 698828 - Fix add bookmark operation in Honeycomb/ICS (r=blassey, a=mfinkle) --- mobile/android/base/db/AndroidBrowserDB.java | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/db/AndroidBrowserDB.java b/mobile/android/base/db/AndroidBrowserDB.java index d4541a2ffa1..7899a2816dc 100644 --- a/mobile/android/base/db/AndroidBrowserDB.java +++ b/mobile/android/base/db/AndroidBrowserDB.java @@ -56,6 +56,9 @@ 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) { @@ -154,7 +157,7 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface { 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 + " = ?", @@ -180,6 +183,28 @@ public class AndroidBrowserDB implements BrowserDB.BrowserDBIface { 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");