am 1c83a043: Merge "Annotate ContentResolver/Provider arguments." into mnc-dev

* commit '1c83a0430fc36e59ee736021c54a35587981030a':
  Annotate ContentResolver/Provider arguments.
This commit is contained in:
Jeff Sharkey
2015-06-12 04:50:58 +00:00
committed by Android Git Automerger
2 changed files with 146 additions and 101 deletions

View File

@@ -19,6 +19,7 @@ package android.content;
import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.Manifest.permission.INTERACT_ACROSS_USERS; import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.app.AppOpsManager; import android.app.AppOpsManager;
import android.content.pm.PathPermission; import android.content.pm.PathPermission;
@@ -639,7 +640,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* {@link #onCreate} has been called -- this will return {@code null} in the * {@link #onCreate} has been called -- this will return {@code null} in the
* constructor. * constructor.
*/ */
public final Context getContext() { public final @Nullable Context getContext() {
return mContext; return mContext;
} }
@@ -667,7 +668,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @throws SecurityException if the calling package doesn't belong to the * @throws SecurityException if the calling package doesn't belong to the
* calling UID. * calling UID.
*/ */
public final String getCallingPackage() { public final @Nullable String getCallingPackage() {
final String pkg = mCallingPackage.get(); final String pkg = mCallingPackage.get();
if (pkg != null) { if (pkg != null) {
mTransport.mAppOpsManager.checkPackage(Binder.getCallingUid(), pkg); mTransport.mAppOpsManager.checkPackage(Binder.getCallingUid(), pkg);
@@ -716,7 +717,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* *
* @param permission Name of the permission required for read-only access. * @param permission Name of the permission required for read-only access.
*/ */
protected final void setReadPermission(String permission) { protected final void setReadPermission(@Nullable String permission) {
mReadPermission = permission; mReadPermission = permission;
} }
@@ -727,7 +728,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
* and Threads</a>. * and Threads</a>.
*/ */
public final String getReadPermission() { public final @Nullable String getReadPermission() {
return mReadPermission; return mReadPermission;
} }
@@ -738,7 +739,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* *
* @param permission Name of the permission required for read/write access. * @param permission Name of the permission required for read/write access.
*/ */
protected final void setWritePermission(String permission) { protected final void setWritePermission(@Nullable String permission) {
mWritePermission = permission; mWritePermission = permission;
} }
@@ -749,7 +750,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
* and Threads</a>. * and Threads</a>.
*/ */
public final String getWritePermission() { public final @Nullable String getWritePermission() {
return mWritePermission; return mWritePermission;
} }
@@ -760,7 +761,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* *
* @param permissions Array of path permission descriptions. * @param permissions Array of path permission descriptions.
*/ */
protected final void setPathPermissions(PathPermission[] permissions) { protected final void setPathPermissions(@Nullable PathPermission[] permissions) {
mPathPermissions = permissions; mPathPermissions = permissions;
} }
@@ -771,7 +772,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
* and Threads</a>. * and Threads</a>.
*/ */
public final PathPermission[] getPathPermissions() { public final @Nullable PathPermission[] getPathPermissions() {
return mPathPermissions; return mPathPermissions;
} }
@@ -897,8 +898,9 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* If {@code null} then the provider is free to define the sort order. * If {@code null} then the provider is free to define the sort order.
* @return a Cursor or {@code null}. * @return a Cursor or {@code null}.
*/ */
public abstract Cursor query(Uri uri, String[] projection, public abstract @Nullable Cursor query(@NonNull Uri uri, @Nullable String[] projection,
String selection, String[] selectionArgs, String sortOrder); @Nullable String selection, @Nullable String[] selectionArgs,
@Nullable String sortOrder);
/** /**
* Implement this to handle query requests from clients with support for cancellation. * Implement this to handle query requests from clients with support for cancellation.
@@ -963,9 +965,9 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* when the query is executed. * when the query is executed.
* @return a Cursor or {@code null}. * @return a Cursor or {@code null}.
*/ */
public Cursor query(Uri uri, String[] projection, public @Nullable Cursor query(@NonNull Uri uri, @Nullable String[] projection,
String selection, String[] selectionArgs, String sortOrder, @Nullable String selection, @Nullable String[] selectionArgs,
CancellationSignal cancellationSignal) { @Nullable String sortOrder, @Nullable CancellationSignal cancellationSignal) {
return query(uri, projection, selection, selectionArgs, sortOrder); return query(uri, projection, selection, selectionArgs, sortOrder);
} }
@@ -987,7 +989,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @param uri the URI to query. * @param uri the URI to query.
* @return a MIME type string, or {@code null} if there is no type. * @return a MIME type string, or {@code null} if there is no type.
*/ */
public abstract String getType(Uri uri); public abstract @Nullable String getType(@NonNull Uri uri);
/** /**
* Implement this to support canonicalization of URIs that refer to your * Implement this to support canonicalization of URIs that refer to your
@@ -1019,7 +1021,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @return Return the canonical representation of <var>url</var>, or null if * @return Return the canonical representation of <var>url</var>, or null if
* canonicalization of that Uri is not supported. * canonicalization of that Uri is not supported.
*/ */
public Uri canonicalize(Uri url) { public @Nullable Uri canonicalize(@NonNull Uri url) {
return null; return null;
} }
@@ -1037,7 +1039,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* the data identified by the canonical representation can not be found in * the data identified by the canonical representation can not be found in
* the current environment. * the current environment.
*/ */
public Uri uncanonicalize(Uri url) { public @Nullable Uri uncanonicalize(@NonNull Uri url) {
return url; return url;
} }
@@ -1070,7 +1072,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* This must not be {@code null}. * This must not be {@code null}.
* @return The URI for the newly inserted item. * @return The URI for the newly inserted item.
*/ */
public abstract Uri insert(Uri uri, ContentValues values); public abstract @Nullable Uri insert(@NonNull Uri uri, @NonNull ContentValues values);
/** /**
* Override this to handle requests to insert a set of new rows, or the * Override this to handle requests to insert a set of new rows, or the
@@ -1087,7 +1089,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* This must not be {@code null}. * This must not be {@code null}.
* @return The number of values that were inserted. * @return The number of values that were inserted.
*/ */
public int bulkInsert(Uri uri, ContentValues[] values) { public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
int numValues = values.length; int numValues = values.length;
for (int i = 0; i < numValues; i++) { for (int i = 0; i < numValues; i++) {
insert(uri, values[i]); insert(uri, values[i]);
@@ -1115,7 +1117,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @return The number of rows affected. * @return The number of rows affected.
* @throws SQLException * @throws SQLException
*/ */
public abstract int delete(Uri uri, String selection, String[] selectionArgs); public abstract int delete(@NonNull Uri uri, @Nullable String selection,
@Nullable String[] selectionArgs);
/** /**
* Implement this to handle requests to update one or more rows. * Implement this to handle requests to update one or more rows.
@@ -1134,8 +1137,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @param selection An optional filter to match rows to update. * @param selection An optional filter to match rows to update.
* @return the number of rows affected. * @return the number of rows affected.
*/ */
public abstract int update(Uri uri, ContentValues values, String selection, public abstract int update(@NonNull Uri uri, @NonNull ContentValues values,
String[] selectionArgs); @Nullable String selection, @Nullable String[] selectionArgs);
/** /**
* Override this to handle requests to open a file blob. * Override this to handle requests to open a file blob.
@@ -1194,7 +1197,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @see #getType(android.net.Uri) * @see #getType(android.net.Uri)
* @see ParcelFileDescriptor#parseMode(String) * @see ParcelFileDescriptor#parseMode(String)
*/ */
public ParcelFileDescriptor openFile(Uri uri, String mode) public @Nullable ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode)
throws FileNotFoundException { throws FileNotFoundException {
throw new FileNotFoundException("No files supported by provider at " throw new FileNotFoundException("No files supported by provider at "
+ uri); + uri);
@@ -1264,8 +1267,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @see #getType(android.net.Uri) * @see #getType(android.net.Uri)
* @see ParcelFileDescriptor#parseMode(String) * @see ParcelFileDescriptor#parseMode(String)
*/ */
public ParcelFileDescriptor openFile(Uri uri, String mode, CancellationSignal signal) public @Nullable ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode,
throws FileNotFoundException { @Nullable CancellationSignal signal) throws FileNotFoundException {
return openFile(uri, mode); return openFile(uri, mode);
} }
@@ -1320,7 +1323,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @see #openFileHelper(Uri, String) * @see #openFileHelper(Uri, String)
* @see #getType(android.net.Uri) * @see #getType(android.net.Uri)
*/ */
public AssetFileDescriptor openAssetFile(Uri uri, String mode) public @Nullable AssetFileDescriptor openAssetFile(@NonNull Uri uri, @NonNull String mode)
throws FileNotFoundException { throws FileNotFoundException {
ParcelFileDescriptor fd = openFile(uri, mode); ParcelFileDescriptor fd = openFile(uri, mode);
return fd != null ? new AssetFileDescriptor(fd, 0, -1) : null; return fd != null ? new AssetFileDescriptor(fd, 0, -1) : null;
@@ -1383,8 +1386,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @see #openFileHelper(Uri, String) * @see #openFileHelper(Uri, String)
* @see #getType(android.net.Uri) * @see #getType(android.net.Uri)
*/ */
public AssetFileDescriptor openAssetFile(Uri uri, String mode, CancellationSignal signal) public @Nullable AssetFileDescriptor openAssetFile(@NonNull Uri uri, @NonNull String mode,
throws FileNotFoundException { @Nullable CancellationSignal signal) throws FileNotFoundException {
return openAssetFile(uri, mode); return openAssetFile(uri, mode);
} }
@@ -1402,8 +1405,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @return Returns a new ParcelFileDescriptor that can be used by the * @return Returns a new ParcelFileDescriptor that can be used by the
* client to access the file. * client to access the file.
*/ */
protected final ParcelFileDescriptor openFileHelper(Uri uri, protected final @NonNull ParcelFileDescriptor openFileHelper(@NonNull Uri uri,
String mode) throws FileNotFoundException { @NonNull String mode) throws FileNotFoundException {
Cursor c = query(uri, new String[]{"_data"}, null, null, null); Cursor c = query(uri, new String[]{"_data"}, null, null, null);
int count = (c != null) ? c.getCount() : 0; int count = (c != null) ? c.getCount() : 0;
if (count != 1) { if (count != 1) {
@@ -1449,7 +1452,7 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @see #openTypedAssetFile(Uri, String, Bundle) * @see #openTypedAssetFile(Uri, String, Bundle)
* @see ClipDescription#compareMimeTypes(String, String) * @see ClipDescription#compareMimeTypes(String, String)
*/ */
public String[] getStreamTypes(Uri uri, String mimeTypeFilter) { public @Nullable String[] getStreamTypes(@NonNull Uri uri, @NonNull String mimeTypeFilter) {
return null; return null;
} }
@@ -1498,8 +1501,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @see #openAssetFile(Uri, String) * @see #openAssetFile(Uri, String)
* @see ClipDescription#compareMimeTypes(String, String) * @see ClipDescription#compareMimeTypes(String, String)
*/ */
public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts) public @Nullable AssetFileDescriptor openTypedAssetFile(@NonNull Uri uri,
throws FileNotFoundException { @NonNull String mimeTypeFilter, @Nullable Bundle opts) throws FileNotFoundException {
if ("*/*".equals(mimeTypeFilter)) { if ("*/*".equals(mimeTypeFilter)) {
// If they can take anything, the untyped open call is good enough. // If they can take anything, the untyped open call is good enough.
return openAssetFile(uri, "r"); return openAssetFile(uri, "r");
@@ -1565,9 +1568,9 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @see #openAssetFile(Uri, String) * @see #openAssetFile(Uri, String)
* @see ClipDescription#compareMimeTypes(String, String) * @see ClipDescription#compareMimeTypes(String, String)
*/ */
public AssetFileDescriptor openTypedAssetFile( public @Nullable AssetFileDescriptor openTypedAssetFile(@NonNull Uri uri,
Uri uri, String mimeTypeFilter, Bundle opts, CancellationSignal signal) @NonNull String mimeTypeFilter, @Nullable Bundle opts,
throws FileNotFoundException { @Nullable CancellationSignal signal) throws FileNotFoundException {
return openTypedAssetFile(uri, mimeTypeFilter, opts); return openTypedAssetFile(uri, mimeTypeFilter, opts);
} }
@@ -1589,8 +1592,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @param opts Options supplied by caller. * @param opts Options supplied by caller.
* @param args Your own custom arguments. * @param args Your own custom arguments.
*/ */
public void writeDataToPipe(ParcelFileDescriptor output, Uri uri, String mimeType, public void writeDataToPipe(@NonNull ParcelFileDescriptor output, @NonNull Uri uri,
Bundle opts, T args); @NonNull String mimeType, @Nullable Bundle opts, @Nullable T args);
} }
/** /**
@@ -1610,9 +1613,9 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* the pipe. This should be returned to the caller for reading; the caller * the pipe. This should be returned to the caller for reading; the caller
* is responsible for closing it when done. * is responsible for closing it when done.
*/ */
public <T> ParcelFileDescriptor openPipeHelper(final Uri uri, final String mimeType, public @NonNull <T> ParcelFileDescriptor openPipeHelper(final @NonNull Uri uri,
final Bundle opts, final T args, final PipeDataWriter<T> func) final @NonNull String mimeType, final @Nullable Bundle opts, final @Nullable T args,
throws FileNotFoundException { final @NonNull PipeDataWriter<T> func) throws FileNotFoundException {
try { try {
final ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe(); final ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
@@ -1717,8 +1720,9 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @throws OperationApplicationException thrown if any operation fails. * @throws OperationApplicationException thrown if any operation fails.
* @see ContentProviderOperation#apply * @see ContentProviderOperation#apply
*/ */
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) public @NonNull ContentProviderResult[] applyBatch(
throws OperationApplicationException { @NonNull ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
final int numOperations = operations.size(); final int numOperations = operations.size();
final ContentProviderResult[] results = new ContentProviderResult[numOperations]; final ContentProviderResult[] results = new ContentProviderResult[numOperations];
for (int i = 0; i < numOperations; i++) { for (int i = 0; i < numOperations; i++) {
@@ -1745,7 +1749,8 @@ public abstract class ContentProvider implements ComponentCallbacks2 {
* @return provider-defined return value. May be {@code null}, which is also * @return provider-defined return value. May be {@code null}, which is also
* the default for providers which don't implement any call methods. * the default for providers which don't implement any call methods.
*/ */
public Bundle call(String method, @Nullable String arg, @Nullable Bundle extras) { public @Nullable Bundle call(@NonNull String method, @Nullable String arg,
@Nullable Bundle extras) {
return null; return null;
} }

View File

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