diff options
author | John Reck <jreck@google.com> | 2011-02-23 14:41:45 -0800 |
---|---|---|
committer | John Reck <jreck@google.com> | 2011-02-23 15:08:59 -0800 |
commit | 17e78fd06905d090cfab4c4f7313bd4b3eec5473 (patch) | |
tree | c3c3de1782f7963002efb70430a7cffc49283621 /src | |
parent | 128e6fc298d695790d1d5c378306cf509a957dce (diff) | |
download | packages_apps_Browser-17e78fd06905d090cfab4c4f7313bd4b3eec5473.zip packages_apps_Browser-17e78fd06905d090cfab4c4f7313bd4b3eec5473.tar.gz packages_apps_Browser-17e78fd06905d090cfab4c4f7313bd4b3eec5473.tar.bz2 |
Prevent PARENT account from not matching inserted values
Bug: 3481259
Adds a check in insert to make sure that the PARENT folder has the
same account_* values as the bookmark being inserted.
Change-Id: I5e42e94fd4eac39eb73047e4246d2102d8e55d82
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/browser/provider/BrowserProvider2.java | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/com/android/browser/provider/BrowserProvider2.java b/src/com/android/browser/provider/BrowserProvider2.java index 3033db4..94b1651 100644 --- a/src/com/android/browser/provider/BrowserProvider2.java +++ b/src/com/android/browser/provider/BrowserProvider2.java @@ -1142,12 +1142,20 @@ public class BrowserProvider2 extends SQLiteContentProvider { values.put(Bookmarks.DATE_MODIFIED, now); values.put(Bookmarks.DIRTY, 1); + String accountType = values + .getAsString(Bookmarks.ACCOUNT_TYPE); + String accountName = values + .getAsString(Bookmarks.ACCOUNT_NAME); + boolean hasParent = values.containsKey(Bookmarks.PARENT); + if (hasParent) { + // Let's make sure it's valid + long parentId = values.getAsLong(Bookmarks.PARENT); + hasParent = isValidParent( + accountType, accountName, parentId); + } + // If no parent is set default to the "Bookmarks Bar" folder - if (!values.containsKey(Bookmarks.PARENT)) { - String accountType = values - .getAsString(Bookmarks.ACCOUNT_TYPE); - String accountName = values - .getAsString(Bookmarks.ACCOUNT_NAME); + if (!hasParent) { values.put(Bookmarks.PARENT, queryDefaultFolderId(accountName, accountType)); } @@ -1226,6 +1234,27 @@ public class BrowserProvider2 extends SQLiteContentProvider { } } + private boolean isValidParent(String accountType, String accountName, + long parentId) { + Uri uri = Bookmarks.buildFolderUri(parentId); + Cursor c = query(uri, + new String[] { Bookmarks.ACCOUNT_NAME, Bookmarks.ACCOUNT_TYPE }, + null, null, null); + try { + if (c.moveToFirst()) { + String parentName = c.getString(0); + String parentType = c.getString(1); + if (TextUtils.equals(accountName, parentName) + && TextUtils.equals(accountType, parentType)) { + return true; + } + } + return false; + } finally { + c.close(); + } + } + private void filterSearchClient(String[] selectionArgs) { if (selectionArgs != null) { for (int i = 0; i < selectionArgs.length; i++) { |