Skip to content

Commit

Permalink
Merge "Add permission annotations to the Browser"
Browse files Browse the repository at this point in the history
  • Loading branch information
tnorbye authored and Android (Google) Code Review committed Apr 24, 2015
2 parents 7defaef + 52881c8 commit 6de5f43
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core/java/android/provider/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package android.provider;

import android.annotation.RequiresPermission;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
Expand All @@ -32,6 +33,9 @@
import android.util.Log;
import android.webkit.WebIconDatabase;

import static android.Manifest.permission.READ_HISTORY_BOOKMARKS;
import static android.Manifest.permission.WRITE_HISTORY_BOOKMARKS;

public class Browser {
private static final String LOGTAG = "browser";

Expand All @@ -41,6 +45,8 @@ public class Browser {
* {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS} permission and writing to it
* requires the {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS} permission.
*/
@RequiresPermission.Read(@RequiresPermission(READ_HISTORY_BOOKMARKS))
@RequiresPermission.Write(@RequiresPermission(WRITE_HISTORY_BOOKMARKS))
public static final Uri BOOKMARKS_URI = Uri.parse("content://browser/bookmarks");

/**
Expand Down Expand Up @@ -122,6 +128,8 @@ public class Browser {
* {@link android.Manifest.permission#READ_HISTORY_BOOKMARKS} permission and writing to it
* requires the {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS} permission.
*/
@RequiresPermission.Read(@RequiresPermission(READ_HISTORY_BOOKMARKS))
@RequiresPermission.Write(@RequiresPermission(WRITE_HISTORY_BOOKMARKS))
public static final Uri SEARCHES_URI = Uri.parse("content://browser/searches");

/**
Expand Down Expand Up @@ -233,6 +241,7 @@ public static final void sendString(Context c,
*
* @param cr The ContentResolver used to access the database.
*/
@RequiresPermission(READ_HISTORY_BOOKMARKS)
public static final Cursor getAllBookmarks(ContentResolver cr) throws
IllegalStateException {
return cr.query(Bookmarks.CONTENT_URI,
Expand All @@ -248,6 +257,7 @@ public static final Cursor getAllBookmarks(ContentResolver cr) throws
*
* @param cr The ContentResolver used to access the database.
*/
@RequiresPermission(READ_HISTORY_BOOKMARKS)
public static final Cursor getAllVisitedUrls(ContentResolver cr) throws
IllegalStateException {
return cr.query(Combined.CONTENT_URI,
Expand Down Expand Up @@ -308,6 +318,7 @@ private static final Cursor getVisitedLike(ContentResolver cr, String url) {
* @param real If true, this is an actual visit, and should add to the
* number of visits. If false, the user entered it manually.
*/
@RequiresPermission(allOf = {READ_HISTORY_BOOKMARKS, WRITE_HISTORY_BOOKMARKS})
public static final void updateVisitedHistory(ContentResolver cr,
String url, boolean real) {
long now = System.currentTimeMillis();
Expand Down Expand Up @@ -358,6 +369,7 @@ public static final void updateVisitedHistory(ContentResolver cr,
* @param cr The ContentResolver used to access the database.
* @hide pending API council approval
*/
@RequiresPermission(READ_HISTORY_BOOKMARKS)
public static final String[] getVisitedHistory(ContentResolver cr) {
Cursor c = null;
String[] str = null;
Expand Down Expand Up @@ -393,6 +405,7 @@ public static final String[] getVisitedHistory(ContentResolver cr) {
*
* @param cr The ContentResolver used to access the database.
*/
@RequiresPermission(allOf = {READ_HISTORY_BOOKMARKS, WRITE_HISTORY_BOOKMARKS})
public static final void truncateHistory(ContentResolver cr) {
// TODO make a single request to the provider to do this in a single transaction
Cursor cursor = null;
Expand Down Expand Up @@ -424,6 +437,7 @@ public static final void truncateHistory(ContentResolver cr) {
* @param cr The ContentResolver used to access the database.
* @return boolean True if the history can be cleared.
*/
@RequiresPermission(READ_HISTORY_BOOKMARKS)
public static final boolean canClearHistory(ContentResolver cr) {
Cursor cursor = null;
boolean ret = false;
Expand All @@ -446,6 +460,7 @@ public static final boolean canClearHistory(ContentResolver cr) {
* Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
* @param cr The ContentResolver used to access the database.
*/
@RequiresPermission(WRITE_HISTORY_BOOKMARKS)
public static final void clearHistory(ContentResolver cr) {
deleteHistoryWhere(cr, null);
}
Expand All @@ -461,6 +476,7 @@ public static final void clearHistory(ContentResolver cr) {
* @param whereClause String to limit the items affected.
* null means all items.
*/
@RequiresPermission(allOf = {READ_HISTORY_BOOKMARKS, WRITE_HISTORY_BOOKMARKS})
private static final void deleteHistoryWhere(ContentResolver cr, String whereClause) {
Cursor cursor = null;
try {
Expand All @@ -486,6 +502,7 @@ private static final void deleteHistoryWhere(ContentResolver cr, String whereCla
* @param end Last date to remove. If -1, all dates after begin.
* Non-inclusive.
*/
@RequiresPermission(WRITE_HISTORY_BOOKMARKS)
public static final void deleteHistoryTimeFrame(ContentResolver cr,
long begin, long end) {
String whereClause;
Expand All @@ -511,6 +528,7 @@ public static final void deleteHistoryTimeFrame(ContentResolver cr,
* @param cr The ContentResolver used to access the database.
* @param url url to remove.
*/
@RequiresPermission(WRITE_HISTORY_BOOKMARKS)
public static final void deleteFromHistory(ContentResolver cr,
String url) {
cr.delete(History.CONTENT_URI, History.URL + "=?", new String[] { url });
Expand All @@ -523,6 +541,7 @@ public static final void deleteFromHistory(ContentResolver cr,
* @param cr The ContentResolver used to access the database.
* @param search The string to add to the searches database.
*/
@RequiresPermission(allOf = {READ_HISTORY_BOOKMARKS, WRITE_HISTORY_BOOKMARKS})
public static final void addSearchUrl(ContentResolver cr, String search) {
// The content provider will take care of updating existing searches instead of duplicating
ContentValues values = new ContentValues();
Expand All @@ -536,6 +555,7 @@ public static final void addSearchUrl(ContentResolver cr, String search) {
* Requires {@link android.Manifest.permission#WRITE_HISTORY_BOOKMARKS}
* @param cr The ContentResolver used to access the database.
*/
@RequiresPermission(WRITE_HISTORY_BOOKMARKS)
public static final void clearSearches(ContentResolver cr) {
// FIXME: Should this clear the urls to which these searches lead?
// (i.e. remove google.com/query= blah blah blah)
Expand All @@ -557,6 +577,7 @@ public static final void clearSearches(ContentResolver cr) {
* @param listener IconListener that gets the icons once they are
* retrieved.
*/
@RequiresPermission(READ_HISTORY_BOOKMARKS)
public static final void requestAllIcons(ContentResolver cr, String where,
WebIconDatabase.IconListener listener) {
// Do nothing: this is no longer used.
Expand Down

0 comments on commit 6de5f43

Please sign in to comment.