Fixes Chrome Sync caused by BP2 account_* where

 Bug: 3324737
 Chrome Sync adapter was adding the account_* selection directly to
 the query rather than using URI parameters. This caused an issue
 where BP2 would then assume that no account was specified, and added
 a where to only search for NULL account_*. This broke the selection,
 thus breaking sync. Changed it so BP2 only adds account_* selection
 if the selection passed in does not already contain account_*.

Change-Id: I5ed5800a5b478ab9eaaa1da773e9fc726f73db5c
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java
index 1b90cb3..358ee2d 100644
--- a/src/com/android/browser/provider/BrowserProvider2.java
+++ b/src/com/android/browser/provider/BrowserProvider2.java
@@ -635,15 +635,20 @@
                 // Look for account info
                 String accountType = uri.getQueryParameter(Bookmarks.PARAM_ACCOUNT_TYPE);
                 String accountName = uri.getQueryParameter(Bookmarks.PARAM_ACCOUNT_NAME);
-                if (!TextUtils.isEmpty(accountType) && !TextUtils.isEmpty(accountName)) {
-                    selection = DatabaseUtils.concatenateWhere(selection,
-                            Bookmarks.ACCOUNT_TYPE + "=? AND " + Bookmarks.ACCOUNT_NAME + "=? ");
-                    selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
-                            new String[] { accountType, accountName });
-                } else {
-                    selection = DatabaseUtils.concatenateWhere(selection,
-                            Bookmarks.ACCOUNT_TYPE + " IS NULL AND " +
-                            Bookmarks.ACCOUNT_NAME + " IS NULL ");
+                // Only add it if it isn't already in the selection
+                if (selection == null ||
+                        (!selection.contains(Bookmarks.ACCOUNT_NAME)
+                        && !selection.contains(Bookmarks.ACCOUNT_TYPE))) {
+                    if (!TextUtils.isEmpty(accountType) && !TextUtils.isEmpty(accountName)) {
+                        selection = DatabaseUtils.concatenateWhere(selection,
+                                Bookmarks.ACCOUNT_TYPE + "=? AND " + Bookmarks.ACCOUNT_NAME + "=? ");
+                        selectionArgs = DatabaseUtils.appendSelectionArgs(selectionArgs,
+                                new String[] { accountType, accountName });
+                    } else {
+                        selection = DatabaseUtils.concatenateWhere(selection,
+                                Bookmarks.ACCOUNT_TYPE + " IS NULL AND " +
+                                Bookmarks.ACCOUNT_NAME + " IS NULL ");
+                    }
                 }
 
                 // Set a default sort order if one isn't specified