summaryrefslogtreecommitdiff
path: root/core/java/android/content/ContentResolver.java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2015-06-11 19:30:57 -0700
committerJeff Sharkey <jsharkey@android.com>2015-06-11 21:45:05 -0700
commit673db44fb3da4558059ef9746a496a63157f10bc (patch)
tree4f72ab64ee84f8dbe16063ebfcb4bc65f8cc61b7 /core/java/android/content/ContentResolver.java
parent4f5e8b3ca489245005b76176ac6d28f5f184f3fe (diff)
Annotate ContentResolver/Provider arguments.
Explicitly mark if they're @Nullable or @NonNull. Bug: 21560515 Change-Id: I5f671c241dfe65e5ab8bc06b2382fbf5a82bdb20
Diffstat (limited to 'core/java/android/content/ContentResolver.java')
-rw-r--r--core/java/android/content/ContentResolver.java156
1 files changed, 98 insertions, 58 deletions
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 96a80e70c3df..bccd144f2f6c 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -17,6 +17,7 @@
package android.content;
import android.accounts.Account;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityManagerNative;
import android.app.ActivityThread;
@@ -47,6 +48,8 @@ import android.util.Log;
import dalvik.system.CloseGuard;
+import com.android.internal.util.Preconditions;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -320,7 +323,9 @@ public abstract class ContentResolver {
* using the content:// scheme.
* @return A MIME type for the content, or null if the URL is invalid or the type is unknown
*/
- public final String getType(Uri url) {
+ public final @Nullable String getType(@NonNull Uri url) {
+ Preconditions.checkNotNull(url, "url");
+
// XXX would like to have an acquireExistingUnstableProvider for this.
IContentProvider provider = acquireExistingProvider(url);
if (provider != null) {
@@ -371,7 +376,10 @@ public abstract class ContentResolver {
* data streams that match the given mimeTypeFilter. If there are none,
* null is returned.
*/
- public String[] getStreamTypes(Uri url, String mimeTypeFilter) {
+ public @Nullable String[] getStreamTypes(@NonNull Uri url, @NonNull String mimeTypeFilter) {
+ Preconditions.checkNotNull(url, "url");
+ Preconditions.checkNotNull(mimeTypeFilter, "mimeTypeFilter");
+
IContentProvider provider = acquireProvider(url);
if (provider == null) {
return null;
@@ -418,8 +426,9 @@ public abstract class ContentResolver {
* @return A Cursor object, which is positioned before the first entry, or null
* @see Cursor
*/
- public final Cursor query(Uri uri, String[] projection,
- String selection, String[] selectionArgs, String sortOrder) {
+ public final @Nullable Cursor query(@NonNull Uri uri, @Nullable String[] projection,
+ @Nullable String selection, @Nullable String[] selectionArgs,
+ @Nullable String sortOrder) {
return query(uri, projection, selection, selectionArgs, sortOrder, null);
}
@@ -457,9 +466,10 @@ public abstract class ContentResolver {
* @return A Cursor object, which is positioned before the first entry, or null
* @see Cursor
*/
- public final Cursor query(final Uri uri, String[] projection,
- String selection, String[] selectionArgs, String sortOrder,
- CancellationSignal cancellationSignal) {
+ public final @Nullable Cursor query(final @NonNull Uri uri, @Nullable String[] projection,
+ @Nullable String selection, @Nullable String[] selectionArgs,
+ @Nullable String sortOrder, @Nullable CancellationSignal cancellationSignal) {
+ Preconditions.checkNotNull(uri, "uri");
IContentProvider unstableProvider = acquireUnstableProvider(uri);
if (unstableProvider == null) {
return null;
@@ -555,7 +565,8 @@ public abstract class ContentResolver {
*
* @see #uncanonicalize
*/
- public final Uri canonicalize(Uri url) {
+ public final @Nullable Uri canonicalize(@NonNull Uri url) {
+ Preconditions.checkNotNull(url, "url");
IContentProvider provider = acquireProvider(url);
if (provider == null) {
return null;
@@ -590,7 +601,8 @@ public abstract class ContentResolver {
*
* @see #canonicalize
*/
- public final Uri uncanonicalize(Uri url) {
+ public final @Nullable Uri uncanonicalize(@NonNull Uri url) {
+ Preconditions.checkNotNull(url, "url");
IContentProvider provider = acquireProvider(url);
if (provider == null) {
return null;
@@ -626,8 +638,9 @@ public abstract class ContentResolver {
* @throws FileNotFoundException if the provided URI could not be opened.
* @see #openAssetFileDescriptor(Uri, String)
*/
- public final InputStream openInputStream(Uri uri)
+ public final @Nullable InputStream openInputStream(@NonNull Uri uri)
throws FileNotFoundException {
+ Preconditions.checkNotNull(uri, "uri");
String scheme = uri.getScheme();
if (SCHEME_ANDROID_RESOURCE.equals(scheme)) {
// Note: left here to avoid breaking compatibility. May be removed
@@ -658,7 +671,7 @@ public abstract class ContentResolver {
* openOutputStream(uri, "w")}.
* @throws FileNotFoundException if the provided URI could not be opened.
*/
- public final OutputStream openOutputStream(Uri uri)
+ public final @Nullable OutputStream openOutputStream(@NonNull Uri uri)
throws FileNotFoundException {
return openOutputStream(uri, "w");
}
@@ -682,7 +695,7 @@ public abstract class ContentResolver {
* @throws FileNotFoundException if the provided URI could not be opened.
* @see #openAssetFileDescriptor(Uri, String)
*/
- public final OutputStream openOutputStream(Uri uri, String mode)
+ public final @Nullable OutputStream openOutputStream(@NonNull Uri uri, @NonNull String mode)
throws FileNotFoundException {
AssetFileDescriptor fd = openAssetFileDescriptor(uri, mode, null);
try {
@@ -729,8 +742,8 @@ public abstract class ContentResolver {
* file exists under the URI or the mode is invalid.
* @see #openAssetFileDescriptor(Uri, String)
*/
- public final ParcelFileDescriptor openFileDescriptor(Uri uri, String mode)
- throws FileNotFoundException {
+ public final @Nullable ParcelFileDescriptor openFileDescriptor(@NonNull Uri uri,
+ @NonNull String mode) throws FileNotFoundException {
return openFileDescriptor(uri, mode, null);
}
@@ -774,8 +787,9 @@ public abstract class ContentResolver {
* file exists under the URI or the mode is invalid.
* @see #openAssetFileDescriptor(Uri, String)
*/
- public final ParcelFileDescriptor openFileDescriptor(Uri uri,
- String mode, CancellationSignal cancellationSignal) throws FileNotFoundException {
+ public final @Nullable ParcelFileDescriptor openFileDescriptor(@NonNull Uri uri,
+ @NonNull String mode, @Nullable CancellationSignal cancellationSignal)
+ throws FileNotFoundException {
AssetFileDescriptor afd = openAssetFileDescriptor(uri, mode, cancellationSignal);
if (afd == null) {
return null;
@@ -844,8 +858,8 @@ public abstract class ContentResolver {
* @throws FileNotFoundException Throws FileNotFoundException of no
* file exists under the URI or the mode is invalid.
*/
- public final AssetFileDescriptor openAssetFileDescriptor(Uri uri, String mode)
- throws FileNotFoundException {
+ public final @Nullable AssetFileDescriptor openAssetFileDescriptor(@NonNull Uri uri,
+ @NonNull String mode) throws FileNotFoundException {
return openAssetFileDescriptor(uri, mode, null);
}
@@ -900,8 +914,12 @@ public abstract class ContentResolver {
* @throws FileNotFoundException Throws FileNotFoundException of no
* file exists under the URI or the mode is invalid.
*/
- public final AssetFileDescriptor openAssetFileDescriptor(Uri uri,
- String mode, CancellationSignal cancellationSignal) throws FileNotFoundException {
+ public final @Nullable AssetFileDescriptor openAssetFileDescriptor(@NonNull Uri uri,
+ @NonNull String mode, @Nullable CancellationSignal cancellationSignal)
+ throws FileNotFoundException {
+ Preconditions.checkNotNull(uri, "uri");
+ Preconditions.checkNotNull(mode, "mode");
+
String scheme = uri.getScheme();
if (SCHEME_ANDROID_RESOURCE.equals(scheme)) {
if (!"r".equals(mode)) {
@@ -1023,8 +1041,8 @@ public abstract class ContentResolver {
* @throws FileNotFoundException Throws FileNotFoundException of no
* data of the desired type exists under the URI.
*/
- public final AssetFileDescriptor openTypedAssetFileDescriptor(
- Uri uri, String mimeType, Bundle opts) throws FileNotFoundException {
+ public final @Nullable AssetFileDescriptor openTypedAssetFileDescriptor(@NonNull Uri uri,
+ @NonNull String mimeType, @Nullable Bundle opts) throws FileNotFoundException {
return openTypedAssetFileDescriptor(uri, mimeType, opts, null);
}
@@ -1059,9 +1077,12 @@ public abstract class ContentResolver {
* @throws FileNotFoundException Throws FileNotFoundException of no
* data of the desired type exists under the URI.
*/
- public final AssetFileDescriptor openTypedAssetFileDescriptor(Uri uri,
- String mimeType, Bundle opts, CancellationSignal cancellationSignal)
- throws FileNotFoundException {
+ public final @Nullable AssetFileDescriptor openTypedAssetFileDescriptor(@NonNull Uri uri,
+ @NonNull String mimeType, @Nullable Bundle opts,
+ @Nullable CancellationSignal cancellationSignal) throws FileNotFoundException {
+ Preconditions.checkNotNull(uri, "uri");
+ Preconditions.checkNotNull(mimeType, "mimeType");
+
IContentProvider unstableProvider = acquireUnstableProvider(uri);
if (unstableProvider == null) {
throw new FileNotFoundException("No content provider: " + uri);
@@ -1197,8 +1218,10 @@ public abstract class ContentResolver {
* the field. Passing an empty ContentValues will create an empty row.
* @return the URL of the newly created row.
*/
- public final Uri insert(Uri url, ContentValues values)
- {
+ public final @Nullable Uri insert(@NonNull Uri url, @NonNull ContentValues values) {
+ Preconditions.checkNotNull(url, "url");
+ Preconditions.checkNotNull(values, "values");
+
IContentProvider provider = acquireProvider(url);
if (provider == null) {
throw new IllegalArgumentException("Unknown URL " + url);
@@ -1234,9 +1257,11 @@ public abstract class ContentResolver {
* @throws RemoteException thrown if a RemoteException is encountered while attempting
* to communicate with a remote provider.
*/
- public ContentProviderResult[] applyBatch(String authority,
- ArrayList<ContentProviderOperation> operations)
- throws RemoteException, OperationApplicationException {
+ public @NonNull ContentProviderResult[] applyBatch(@NonNull String authority,
+ @NonNull ArrayList<ContentProviderOperation> operations)
+ throws RemoteException, OperationApplicationException {
+ Preconditions.checkNotNull(authority, "authority");
+ Preconditions.checkNotNull(operations, "operations");
ContentProviderClient provider = acquireContentProviderClient(authority);
if (provider == null) {
throw new IllegalArgumentException("Unknown authority " + authority);
@@ -1258,8 +1283,9 @@ public abstract class ContentResolver {
* the field. Passing null will create an empty row.
* @return the number of newly created rows.
*/
- public final int bulkInsert(Uri url, ContentValues[] values)
- {
+ public final int bulkInsert(@NonNull Uri url, @NonNull ContentValues[] values) {
+ Preconditions.checkNotNull(url, "url");
+ Preconditions.checkNotNull(values, "values");
IContentProvider provider = acquireProvider(url);
if (provider == null) {
throw new IllegalArgumentException("Unknown URL " + url);
@@ -1289,8 +1315,9 @@ public abstract class ContentResolver {
(excluding the WHERE itself).
* @return The number of rows deleted.
*/
- public final int delete(Uri url, String where, String[] selectionArgs)
- {
+ public final int delete(@NonNull Uri url, @Nullable String where,
+ @Nullable String[] selectionArgs) {
+ Preconditions.checkNotNull(url, "url");
IContentProvider provider = acquireProvider(url);
if (provider == null) {
throw new IllegalArgumentException("Unknown URL " + url);
@@ -1323,8 +1350,10 @@ public abstract class ContentResolver {
* @return the number of rows updated.
* @throws NullPointerException if uri or values are null
*/
- public final int update(Uri uri, ContentValues values, String where,
- String[] selectionArgs) {
+ public final int update(@NonNull Uri uri, @NonNull ContentValues values,
+ @Nullable String where, @Nullable String[] selectionArgs) {
+ Preconditions.checkNotNull(uri, "uri");
+ Preconditions.checkNotNull(values, "values");
IContentProvider provider = acquireProvider(uri);
if (provider == null) {
throw new IllegalArgumentException("Unknown URI " + uri);
@@ -1358,14 +1387,10 @@ public abstract class ContentResolver {
* @throws NullPointerException if uri or method is null
* @throws IllegalArgumentException if uri is not known
*/
- public final Bundle call(
- Uri uri, String method, @Nullable String arg, @Nullable Bundle extras) {
- if (uri == null) {
- throw new NullPointerException("uri == null");
- }
- if (method == null) {
- throw new NullPointerException("method == null");
- }
+ public final @Nullable Bundle call(@NonNull Uri uri, @NonNull String method,
+ @Nullable String arg, @Nullable Bundle extras) {
+ Preconditions.checkNotNull(uri, "uri");
+ Preconditions.checkNotNull(method, "method");
IContentProvider provider = acquireProvider(uri);
if (provider == null) {
throw new IllegalArgumentException("Unknown URI " + uri);
@@ -1467,12 +1492,12 @@ public abstract class ContentResolver {
* @return a {@link ContentProviderClient} that is associated with the {@link ContentProvider}
* that services the content at uri or null if there isn't one.
*/
- public final ContentProviderClient acquireContentProviderClient(Uri uri) {
+ public final @Nullable ContentProviderClient acquireContentProviderClient(@NonNull Uri uri) {
+ Preconditions.checkNotNull(uri, "uri");
IContentProvider provider = acquireProvider(uri);
if (provider != null) {
return new ContentProviderClient(this, provider, true);
}
-
return null;
}
@@ -1487,7 +1512,9 @@ public abstract class ContentResolver {
* @return a {@link ContentProviderClient} that is associated with the {@link ContentProvider}
* with the authority of name or null if there isn't one.
*/
- public final ContentProviderClient acquireContentProviderClient(String name) {
+ public final @Nullable ContentProviderClient acquireContentProviderClient(
+ @NonNull String name) {
+ Preconditions.checkNotNull(name, "name");
IContentProvider provider = acquireProvider(name);
if (provider != null) {
return new ContentProviderClient(this, provider, true);
@@ -1512,7 +1539,9 @@ public abstract class ContentResolver {
* can acquire a new one if you would like to try to restart the provider
* and perform new operations on it.
*/
- public final ContentProviderClient acquireUnstableContentProviderClient(Uri uri) {
+ public final @Nullable ContentProviderClient acquireUnstableContentProviderClient(
+ @NonNull Uri uri) {
+ Preconditions.checkNotNull(uri, "uri");
IContentProvider provider = acquireUnstableProvider(uri);
if (provider != null) {
return new ContentProviderClient(this, provider, false);
@@ -1537,7 +1566,9 @@ public abstract class ContentResolver {
* can acquire a new one if you would like to try to restart the provider
* and perform new operations on it.
*/
- public final ContentProviderClient acquireUnstableContentProviderClient(String name) {
+ public final @Nullable ContentProviderClient acquireUnstableContentProviderClient(
+ @NonNull String name) {
+ Preconditions.checkNotNull(name, "name");
IContentProvider provider = acquireUnstableProvider(name);
if (provider != null) {
return new ContentProviderClient(this, provider, false);
@@ -1559,8 +1590,10 @@ public abstract class ContentResolver {
* @param observer The object that receives callbacks when changes occur.
* @see #unregisterContentObserver
*/
- public final void registerContentObserver(Uri uri, boolean notifyForDescendents,
- ContentObserver observer) {
+ public final void registerContentObserver(@NonNull Uri uri, boolean notifyForDescendents,
+ @NonNull ContentObserver observer) {
+ Preconditions.checkNotNull(uri, "uri");
+ Preconditions.checkNotNull(observer, "observer");
registerContentObserver(uri, notifyForDescendents, observer, UserHandle.myUserId());
}
@@ -1580,7 +1613,8 @@ public abstract class ContentResolver {
* @param observer The previously registered observer that is no longer needed.
* @see #registerContentObserver
*/
- public final void unregisterContentObserver(ContentObserver observer) {
+ public final void unregisterContentObserver(@NonNull ContentObserver observer) {
+ Preconditions.checkNotNull(observer, "observer");
try {
IContentObserver contentObserver = observer.releaseContentObserver();
if (contentObserver != null) {
@@ -1603,7 +1637,7 @@ public abstract class ContentResolver {
* has requested to receive self-change notifications by implementing
* {@link ContentObserver#deliverSelfNotifications()} to return true.
*/
- public void notifyChange(Uri uri, ContentObserver observer) {
+ public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer) {
notifyChange(uri, observer, true /* sync to network */);
}
@@ -1623,7 +1657,9 @@ public abstract class ContentResolver {
* @param syncToNetwork If true, attempt to sync the change to the network.
* @see #requestSync(android.accounts.Account, String, android.os.Bundle)
*/
- public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) {
+ public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer,
+ boolean syncToNetwork) {
+ Preconditions.checkNotNull(uri, "uri");
notifyChange(uri, observer, syncToNetwork, UserHandle.myUserId());
}
@@ -1653,7 +1689,9 @@ public abstract class ContentResolver {
*
* @see #getPersistedUriPermissions()
*/
- public void takePersistableUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags) {
+ public void takePersistableUriPermission(@NonNull Uri uri,
+ @Intent.AccessUriMode int modeFlags) {
+ Preconditions.checkNotNull(uri, "uri");
try {
ActivityManagerNative.getDefault().takePersistableUriPermission(
ContentProvider.getUriWithoutUserId(uri), modeFlags, resolveUserId(uri));
@@ -1669,7 +1707,9 @@ public abstract class ContentResolver {
*
* @see #getPersistedUriPermissions()
*/
- public void releasePersistableUriPermission(Uri uri, @Intent.AccessUriMode int modeFlags) {
+ public void releasePersistableUriPermission(@NonNull Uri uri,
+ @Intent.AccessUriMode int modeFlags) {
+ Preconditions.checkNotNull(uri, "uri");
try {
ActivityManagerNative.getDefault().releasePersistableUriPermission(
ContentProvider.getUriWithoutUserId(uri), modeFlags, resolveUserId(uri));
@@ -1686,7 +1726,7 @@ public abstract class ContentResolver {
* @see #takePersistableUriPermission(Uri, int)
* @see #releasePersistableUriPermission(Uri, int)
*/
- public List<UriPermission> getPersistedUriPermissions() {
+ public @NonNull List<UriPermission> getPersistedUriPermissions() {
try {
return ActivityManagerNative.getDefault()
.getPersistedUriPermissions(mPackageName, true).getList();
@@ -1701,7 +1741,7 @@ public abstract class ContentResolver {
* <em>from</em> the calling app. Only grants taken with
* {@link #takePersistableUriPermission(Uri, int)} are returned.
*/
- public List<UriPermission> getOutgoingPersistedUriPermissions() {
+ public @NonNull List<UriPermission> getOutgoingPersistedUriPermissions() {
try {
return ActivityManagerNative.getDefault()
.getPersistedUriPermissions(mPackageName, false).getList();