blob: ff3e843916ad99c5022acaf701051cb2100000af [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content;
18
Jeff Sharkey110a6b62012-03-12 11:12:41 -070019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Dianne Hackborn35654b62013-01-14 17:38:02 -080021import android.app.AppOpsManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.pm.PackageManager;
Dianne Hackborn2af632f2009-07-08 14:56:37 -070023import android.content.pm.PathPermission;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.content.pm.ProviderInfo;
25import android.content.res.AssetFileDescriptor;
26import android.content.res.Configuration;
27import android.database.Cursor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.database.SQLException;
29import android.net.Uri;
Dianne Hackborn23fdaf62010-08-06 12:16:55 -070030import android.os.AsyncTask;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Binder;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080032import android.os.Bundle;
Jeff Browna7771df2012-05-07 20:06:46 -070033import android.os.CancellationSignal;
34import android.os.ICancellationSignal;
35import android.os.OperationCanceledException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import android.os.ParcelFileDescriptor;
Dianne Hackborn2af632f2009-07-08 14:56:37 -070037import android.os.Process;
Jeff Brown75ea64f2012-01-25 19:37:13 -080038import android.os.RemoteException;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070039import android.os.UserHandle;
Vasu Nori0c9e14a2010-08-04 13:31:48 -070040import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
42import java.io.File;
Marco Nelissen18cb2872011-11-15 11:19:53 -080043import java.io.FileDescriptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044import java.io.FileNotFoundException;
Dianne Hackborn23fdaf62010-08-06 12:16:55 -070045import java.io.IOException;
Marco Nelissen18cb2872011-11-15 11:19:53 -080046import java.io.PrintWriter;
Fred Quintana03d94902009-05-22 14:23:31 -070047import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048
49/**
50 * Content providers are one of the primary building blocks of Android applications, providing
51 * content to applications. They encapsulate data and provide it to applications through the single
52 * {@link ContentResolver} interface. A content provider is only required if you need to share
53 * data between multiple applications. For example, the contacts data is used by multiple
54 * applications and must be stored in a content provider. If you don't need to share data amongst
55 * multiple applications you can use a database directly via
56 * {@link android.database.sqlite.SQLiteDatabase}.
57 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 * <p>When a request is made via
59 * a {@link ContentResolver} the system inspects the authority of the given URI and passes the
60 * request to the content provider registered with the authority. The content provider can interpret
61 * the rest of the URI however it wants. The {@link UriMatcher} class is helpful for parsing
62 * URIs.</p>
63 *
64 * <p>The primary methods that need to be implemented are:
65 * <ul>
Dan Egnor6fcc0f0732010-07-27 16:32:17 -070066 * <li>{@link #onCreate} which is called to initialize the provider</li>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 * <li>{@link #query} which returns data to the caller</li>
68 * <li>{@link #insert} which inserts new data into the content provider</li>
69 * <li>{@link #update} which updates existing data in the content provider</li>
70 * <li>{@link #delete} which deletes data from the content provider</li>
71 * <li>{@link #getType} which returns the MIME type of data in the content provider</li>
72 * </ul></p>
73 *
Dan Egnor6fcc0f0732010-07-27 16:32:17 -070074 * <p class="caution">Data access methods (such as {@link #insert} and
75 * {@link #update}) may be called from many threads at once, and must be thread-safe.
76 * Other methods (such as {@link #onCreate}) are only called from the application
77 * main thread, and must avoid performing lengthy operations. See the method
78 * descriptions for their expected thread behavior.</p>
79 *
80 * <p>Requests to {@link ContentResolver} are automatically forwarded to the appropriate
81 * ContentProvider instance, so subclasses don't have to worry about the details of
82 * cross-process calls.</p>
Joe Fernandez558459f2011-10-13 16:47:36 -070083 *
84 * <div class="special reference">
85 * <h3>Developer Guides</h3>
86 * <p>For more information about using content providers, read the
87 * <a href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a>
88 * developer guide.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 */
Dianne Hackbornc68c9132011-07-29 01:25:18 -070090public abstract class ContentProvider implements ComponentCallbacks2 {
Vasu Nori0c9e14a2010-08-04 13:31:48 -070091 private static final String TAG = "ContentProvider";
92
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090093 /*
94 * Note: if you add methods to ContentProvider, you must add similar methods to
95 * MockContentProvider.
96 */
97
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080098 private Context mContext = null;
Dianne Hackborn2af632f2009-07-08 14:56:37 -070099 private int mMyUid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100 private String mReadPermission;
101 private String mWritePermission;
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700102 private PathPermission[] mPathPermissions;
Dianne Hackbornb424b632010-08-18 15:59:05 -0700103 private boolean mExported;
Dianne Hackborn7e6f9762013-02-26 13:35:11 -0800104 private boolean mNoPerms;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105
106 private Transport mTransport = new Transport();
107
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700108 /**
109 * Construct a ContentProvider instance. Content providers must be
110 * <a href="{@docRoot}guide/topics/manifest/provider-element.html">declared
111 * in the manifest</a>, accessed with {@link ContentResolver}, and created
112 * automatically by the system, so applications usually do not create
113 * ContentProvider instances directly.
114 *
115 * <p>At construction time, the object is uninitialized, and most fields and
116 * methods are unavailable. Subclasses should initialize themselves in
117 * {@link #onCreate}, not the constructor.
118 *
119 * <p>Content providers are created on the application main thread at
120 * application launch time. The constructor must not perform lengthy
121 * operations, or application startup will be delayed.
122 */
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +0900123 public ContentProvider() {
124 }
125
126 /**
127 * Constructor just for mocking.
128 *
129 * @param context A Context object which should be some mock instance (like the
130 * instance of {@link android.test.mock.MockContext}).
131 * @param readPermission The read permision you want this instance should have in the
132 * test, which is available via {@link #getReadPermission()}.
133 * @param writePermission The write permission you want this instance should have
134 * in the test, which is available via {@link #getWritePermission()}.
135 * @param pathPermissions The PathPermissions you want this instance should have
136 * in the test, which is available via {@link #getPathPermissions()}.
137 * @hide
138 */
139 public ContentProvider(
140 Context context,
141 String readPermission,
142 String writePermission,
143 PathPermission[] pathPermissions) {
144 mContext = context;
145 mReadPermission = readPermission;
146 mWritePermission = writePermission;
147 mPathPermissions = pathPermissions;
148 }
149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 /**
151 * Given an IContentProvider, try to coerce it back to the real
152 * ContentProvider object if it is running in the local process. This can
153 * be used if you know you are running in the same process as a provider,
154 * and want to get direct access to its implementation details. Most
155 * clients should not nor have a reason to use it.
156 *
157 * @param abstractInterface The ContentProvider interface that is to be
158 * coerced.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800159 * @return If the IContentProvider is non-{@code null} and local, returns its actual
160 * ContentProvider instance. Otherwise returns {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800161 * @hide
162 */
163 public static ContentProvider coerceToLocalContentProvider(
164 IContentProvider abstractInterface) {
165 if (abstractInterface instanceof Transport) {
166 return ((Transport)abstractInterface).getContentProvider();
167 }
168 return null;
169 }
170
171 /**
172 * Binder object that deals with remoting.
173 *
174 * @hide
175 */
176 class Transport extends ContentProviderNative {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800177 AppOpsManager mAppOpsManager = null;
Dianne Hackborn961321f2013-02-05 17:22:41 -0800178 int mReadOp = AppOpsManager.OP_NONE;
179 int mWriteOp = AppOpsManager.OP_NONE;
Dianne Hackborn35654b62013-01-14 17:38:02 -0800180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 ContentProvider getContentProvider() {
182 return ContentProvider.this;
183 }
184
Jeff Brownd2183652011-10-09 12:39:53 -0700185 @Override
186 public String getProviderName() {
187 return getContentProvider().getClass().getName();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 }
189
Jeff Brown75ea64f2012-01-25 19:37:13 -0800190 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800191 public Cursor query(String callingPkg, Uri uri, String[] projection,
Jeff Brown75ea64f2012-01-25 19:37:13 -0800192 String selection, String[] selectionArgs, String sortOrder,
Jeff Brown4c1241d2012-02-02 17:05:00 -0800193 ICancellationSignal cancellationSignal) {
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800194 if (enforceReadPermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
Dianne Hackbornd7960d12013-01-29 18:55:48 -0800195 return rejectQuery(uri, projection, selection, selectionArgs, sortOrder,
196 CancellationSignal.fromTransport(cancellationSignal));
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800197 }
Jeff Brown75ea64f2012-01-25 19:37:13 -0800198 return ContentProvider.this.query(uri, projection, selection, selectionArgs, sortOrder,
Jeff Brown4c1241d2012-02-02 17:05:00 -0800199 CancellationSignal.fromTransport(cancellationSignal));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 }
201
Jeff Brown75ea64f2012-01-25 19:37:13 -0800202 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 public String getType(Uri uri) {
204 return ContentProvider.this.getType(uri);
205 }
206
Jeff Brown75ea64f2012-01-25 19:37:13 -0800207 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800208 public Uri insert(String callingPkg, Uri uri, ContentValues initialValues) {
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800209 if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
Dianne Hackbornd7960d12013-01-29 18:55:48 -0800210 return rejectInsert(uri, initialValues);
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800211 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 return ContentProvider.this.insert(uri, initialValues);
213 }
214
Jeff Brown75ea64f2012-01-25 19:37:13 -0800215 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800216 public int bulkInsert(String callingPkg, Uri uri, ContentValues[] initialValues) {
217 if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
218 return 0;
219 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800220 return ContentProvider.this.bulkInsert(uri, initialValues);
221 }
222
Jeff Brown75ea64f2012-01-25 19:37:13 -0800223 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800224 public ContentProviderResult[] applyBatch(String callingPkg,
225 ArrayList<ContentProviderOperation> operations)
Fred Quintana89437372009-05-15 15:10:40 -0700226 throws OperationApplicationException {
227 for (ContentProviderOperation operation : operations) {
228 if (operation.isReadOperation()) {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800229 if (enforceReadPermission(callingPkg, operation.getUri())
230 != AppOpsManager.MODE_ALLOWED) {
231 throw new OperationApplicationException("App op not allowed", 0);
232 }
Fred Quintana89437372009-05-15 15:10:40 -0700233 }
234
235 if (operation.isWriteOperation()) {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800236 if (enforceWritePermission(callingPkg, operation.getUri())
237 != AppOpsManager.MODE_ALLOWED) {
238 throw new OperationApplicationException("App op not allowed", 0);
239 }
Fred Quintana89437372009-05-15 15:10:40 -0700240 }
241 }
242 return ContentProvider.this.applyBatch(operations);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700243 }
244
Jeff Brown75ea64f2012-01-25 19:37:13 -0800245 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800246 public int delete(String callingPkg, Uri uri, String selection, String[] selectionArgs) {
247 if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
248 return 0;
249 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 return ContentProvider.this.delete(uri, selection, selectionArgs);
251 }
252
Jeff Brown75ea64f2012-01-25 19:37:13 -0800253 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800254 public int update(String callingPkg, Uri uri, ContentValues values, String selection,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 String[] selectionArgs) {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800256 if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
257 return 0;
258 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 return ContentProvider.this.update(uri, values, selection, selectionArgs);
260 }
261
Jeff Brown75ea64f2012-01-25 19:37:13 -0800262 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800263 public ParcelFileDescriptor openFile(String callingPkg, Uri uri, String mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800264 throws FileNotFoundException {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800265 enforceFilePermission(callingPkg, uri, mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800266 return ContentProvider.this.openFile(uri, mode);
267 }
268
Jeff Brown75ea64f2012-01-25 19:37:13 -0800269 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800270 public AssetFileDescriptor openAssetFile(String callingPkg, Uri uri, String mode)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 throws FileNotFoundException {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800272 enforceFilePermission(callingPkg, uri, mode);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800273 return ContentProvider.this.openAssetFile(uri, mode);
274 }
275
Jeff Brown75ea64f2012-01-25 19:37:13 -0800276 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800277 public Bundle call(String callingPkg, String method, String arg, Bundle extras) {
Dianne Hackborn961321f2013-02-05 17:22:41 -0800278 return ContentProvider.this.callFromPackage(callingPkg, method, arg, extras);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800279 }
280
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700281 @Override
282 public String[] getStreamTypes(Uri uri, String mimeTypeFilter) {
283 return ContentProvider.this.getStreamTypes(uri, mimeTypeFilter);
284 }
285
286 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800287 public AssetFileDescriptor openTypedAssetFile(String callingPkg, Uri uri, String mimeType,
288 Bundle opts) throws FileNotFoundException {
289 enforceFilePermission(callingPkg, uri, "r");
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700290 return ContentProvider.this.openTypedAssetFile(uri, mimeType, opts);
291 }
292
Jeff Brown75ea64f2012-01-25 19:37:13 -0800293 @Override
Jeff Brown4c1241d2012-02-02 17:05:00 -0800294 public ICancellationSignal createCancellationSignal() throws RemoteException {
295 return CancellationSignal.createTransport();
Jeff Brown75ea64f2012-01-25 19:37:13 -0800296 }
297
Dianne Hackborn35654b62013-01-14 17:38:02 -0800298 private void enforceFilePermission(String callingPkg, Uri uri, String mode)
299 throws FileNotFoundException, SecurityException {
300 if (mode != null && mode.startsWith("rw")) {
301 if (enforceWritePermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
302 throw new FileNotFoundException("App op not allowed");
303 }
304 } else {
305 if (enforceReadPermission(callingPkg, uri) != AppOpsManager.MODE_ALLOWED) {
306 throw new FileNotFoundException("App op not allowed");
307 }
308 }
309 }
310
311 private int enforceReadPermission(String callingPkg, Uri uri) throws SecurityException {
312 enforceReadPermissionInner(uri);
Dianne Hackborn961321f2013-02-05 17:22:41 -0800313 if (mReadOp != AppOpsManager.OP_NONE) {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800314 return mAppOpsManager.noteOp(mReadOp, Binder.getCallingUid(), callingPkg);
315 }
316 return AppOpsManager.MODE_ALLOWED;
317 }
318
319 private void enforceReadPermissionInner(Uri uri) throws SecurityException {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700320 final Context context = getContext();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 final int pid = Binder.getCallingPid();
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700322 final int uid = Binder.getCallingUid();
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700323 String missingPerm = null;
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700324
Dianne Hackborn0d8af782012-08-17 16:51:54 -0700325 if (UserHandle.isSameApp(uid, mMyUid)) {
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700326 return;
327 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700328
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700329 if (mExported) {
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700330 final String componentPerm = getReadPermission();
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700331 if (componentPerm != null) {
332 if (context.checkPermission(componentPerm, pid, uid) == PERMISSION_GRANTED) {
333 return;
334 } else {
335 missingPerm = componentPerm;
336 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700337 }
338
339 // track if unprotected read is allowed; any denied
340 // <path-permission> below removes this ability
341 boolean allowDefaultRead = (componentPerm == null);
342
343 final PathPermission[] pps = getPathPermissions();
344 if (pps != null) {
345 final String path = uri.getPath();
346 for (PathPermission pp : pps) {
347 final String pathPerm = pp.getReadPermission();
348 if (pathPerm != null && pp.match(path)) {
349 if (context.checkPermission(pathPerm, pid, uid) == PERMISSION_GRANTED) {
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700350 return;
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700351 } else {
352 // any denied <path-permission> means we lose
353 // default <provider> access.
354 allowDefaultRead = false;
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700355 missingPerm = pathPerm;
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700356 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700357 }
358 }
359 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700360
361 // if we passed <path-permission> checks above, and no default
362 // <provider> permission, then allow access.
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700363 if (allowDefaultRead) return;
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700364 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700365
366 // last chance, check against any uri grants
367 if (context.checkUriPermission(uri, pid, uid, Intent.FLAG_GRANT_READ_URI_PERMISSION)
368 == PERMISSION_GRANTED) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800369 return;
370 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700371
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700372 final String failReason = mExported
373 ? " requires " + missingPerm + ", or grantUriPermission()"
374 : " requires the provider be exported, or grantUriPermission()";
375 throw new SecurityException("Permission Denial: reading "
376 + ContentProvider.this.getClass().getName() + " uri " + uri + " from pid=" + pid
377 + ", uid=" + uid + failReason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800378 }
379
Dianne Hackborn35654b62013-01-14 17:38:02 -0800380 private int enforceWritePermission(String callingPkg, Uri uri) throws SecurityException {
381 enforceWritePermissionInner(uri);
Dianne Hackborn961321f2013-02-05 17:22:41 -0800382 if (mWriteOp != AppOpsManager.OP_NONE) {
Dianne Hackborn35654b62013-01-14 17:38:02 -0800383 return mAppOpsManager.noteOp(mWriteOp, Binder.getCallingUid(), callingPkg);
384 }
385 return AppOpsManager.MODE_ALLOWED;
386 }
387
388 private void enforceWritePermissionInner(Uri uri) throws SecurityException {
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700389 final Context context = getContext();
390 final int pid = Binder.getCallingPid();
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700391 final int uid = Binder.getCallingUid();
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700392 String missingPerm = null;
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700393
Dianne Hackborn0d8af782012-08-17 16:51:54 -0700394 if (UserHandle.isSameApp(uid, mMyUid)) {
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700395 return;
396 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700397
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700398 if (mExported) {
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700399 final String componentPerm = getWritePermission();
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700400 if (componentPerm != null) {
401 if (context.checkPermission(componentPerm, pid, uid) == PERMISSION_GRANTED) {
402 return;
403 } else {
404 missingPerm = componentPerm;
405 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700406 }
407
408 // track if unprotected write is allowed; any denied
409 // <path-permission> below removes this ability
410 boolean allowDefaultWrite = (componentPerm == null);
411
412 final PathPermission[] pps = getPathPermissions();
413 if (pps != null) {
414 final String path = uri.getPath();
415 for (PathPermission pp : pps) {
416 final String pathPerm = pp.getWritePermission();
417 if (pathPerm != null && pp.match(path)) {
418 if (context.checkPermission(pathPerm, pid, uid) == PERMISSION_GRANTED) {
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700419 return;
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700420 } else {
421 // any denied <path-permission> means we lose
422 // default <provider> access.
423 allowDefaultWrite = false;
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700424 missingPerm = pathPerm;
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700425 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700426 }
427 }
428 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700429
430 // if we passed <path-permission> checks above, and no default
431 // <provider> permission, then allow access.
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700432 if (allowDefaultWrite) return;
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700433 }
Jeff Sharkey110a6b62012-03-12 11:12:41 -0700434
435 // last chance, check against any uri grants
436 if (context.checkUriPermission(uri, pid, uid, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
437 == PERMISSION_GRANTED) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800438 return;
439 }
Jeff Sharkeye5d49332012-03-13 12:13:17 -0700440
441 final String failReason = mExported
442 ? " requires " + missingPerm + ", or grantUriPermission()"
443 : " requires the provider be exported, or grantUriPermission()";
444 throw new SecurityException("Permission Denial: writing "
445 + ContentProvider.this.getClass().getName() + " uri " + uri + " from pid=" + pid
446 + ", uid=" + uid + failReason);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 }
448 }
449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800450 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700451 * Retrieves the Context this provider is running in. Only available once
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800452 * {@link #onCreate} has been called -- this will return {@code null} in the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453 * constructor.
454 */
455 public final Context getContext() {
456 return mContext;
457 }
458
459 /**
460 * Change the permission required to read data from the content
461 * provider. This is normally set for you from its manifest information
462 * when the provider is first created.
463 *
464 * @param permission Name of the permission required for read-only access.
465 */
466 protected final void setReadPermission(String permission) {
467 mReadPermission = permission;
468 }
469
470 /**
471 * Return the name of the permission required for read-only access to
472 * this content provider. This method can be called from multiple
473 * threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800474 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
475 * and Threads</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800476 */
477 public final String getReadPermission() {
478 return mReadPermission;
479 }
480
481 /**
482 * Change the permission required to read and write data in the content
483 * provider. This is normally set for you from its manifest information
484 * when the provider is first created.
485 *
486 * @param permission Name of the permission required for read/write access.
487 */
488 protected final void setWritePermission(String permission) {
489 mWritePermission = permission;
490 }
491
492 /**
493 * Return the name of the permission required for read/write access to
494 * this content provider. This method can be called from multiple
495 * threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800496 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
497 * and Threads</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800498 */
499 public final String getWritePermission() {
500 return mWritePermission;
501 }
502
503 /**
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700504 * Change the path-based permission required to read and/or write data in
505 * the content provider. This is normally set for you from its manifest
506 * information when the provider is first created.
507 *
508 * @param permissions Array of path permission descriptions.
509 */
510 protected final void setPathPermissions(PathPermission[] permissions) {
511 mPathPermissions = permissions;
512 }
513
514 /**
515 * Return the path-based permissions required for read and/or write access to
516 * this content provider. This method can be called from multiple
517 * threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800518 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
519 * and Threads</a>.
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700520 */
521 public final PathPermission[] getPathPermissions() {
522 return mPathPermissions;
523 }
524
Dianne Hackborn35654b62013-01-14 17:38:02 -0800525 /** @hide */
526 public final void setAppOps(int readOp, int writeOp) {
Dianne Hackborn7e6f9762013-02-26 13:35:11 -0800527 if (!mNoPerms) {
528 mTransport.mAppOpsManager = (AppOpsManager)mContext.getSystemService(
529 Context.APP_OPS_SERVICE);
530 mTransport.mReadOp = readOp;
531 mTransport.mWriteOp = writeOp;
532 }
Dianne Hackborn35654b62013-01-14 17:38:02 -0800533 }
534
Dianne Hackborn961321f2013-02-05 17:22:41 -0800535 /** @hide */
536 public AppOpsManager getAppOpsManager() {
537 return mTransport.mAppOpsManager;
538 }
539
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700540 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700541 * Implement this to initialize your content provider on startup.
542 * This method is called for all registered content providers on the
543 * application main thread at application launch time. It must not perform
544 * lengthy operations, or application startup will be delayed.
545 *
546 * <p>You should defer nontrivial initialization (such as opening,
547 * upgrading, and scanning databases) until the content provider is used
548 * (via {@link #query}, {@link #insert}, etc). Deferred initialization
549 * keeps application startup fast, avoids unnecessary work if the provider
550 * turns out not to be needed, and stops database errors (such as a full
551 * disk) from halting application launch.
552 *
Dan Egnor17876aa2010-07-28 12:28:04 -0700553 * <p>If you use SQLite, {@link android.database.sqlite.SQLiteOpenHelper}
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700554 * is a helpful utility class that makes it easy to manage databases,
555 * and will automatically defer opening until first use. If you do use
556 * SQLiteOpenHelper, make sure to avoid calling
557 * {@link android.database.sqlite.SQLiteOpenHelper#getReadableDatabase} or
558 * {@link android.database.sqlite.SQLiteOpenHelper#getWritableDatabase}
559 * from this method. (Instead, override
560 * {@link android.database.sqlite.SQLiteOpenHelper#onOpen} to initialize the
561 * database when it is first opened.)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800562 *
563 * @return true if the provider was successfully loaded, false otherwise
564 */
565 public abstract boolean onCreate();
566
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700567 /**
568 * {@inheritDoc}
569 * This method is always called on the application main thread, and must
570 * not perform lengthy operations.
571 *
572 * <p>The default content provider implementation does nothing.
573 * Override this method to take appropriate action.
574 * (Content providers do not usually care about things like screen
575 * orientation, but may want to know about locale changes.)
576 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577 public void onConfigurationChanged(Configuration newConfig) {
578 }
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700579
580 /**
581 * {@inheritDoc}
582 * This method is always called on the application main thread, and must
583 * not perform lengthy operations.
584 *
585 * <p>The default content provider implementation does nothing.
586 * Subclasses may override this method to take appropriate action.
587 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 public void onLowMemory() {
589 }
590
Dianne Hackbornc68c9132011-07-29 01:25:18 -0700591 public void onTrimMemory(int level) {
592 }
593
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 /**
Dianne Hackbornd7960d12013-01-29 18:55:48 -0800595 * @hide
596 * Implementation when a caller has performed a query on the content
597 * provider, but that call has been rejected for the operation given
598 * to {@link #setAppOps(int, int)}. The default implementation
599 * rewrites the <var>selection</var> argument to include a condition
600 * that is never true (so will always result in an empty cursor)
601 * and calls through to {@link #query(android.net.Uri, String[], String, String[],
602 * String, android.os.CancellationSignal)} with that.
603 */
604 public Cursor rejectQuery(Uri uri, String[] projection,
605 String selection, String[] selectionArgs, String sortOrder,
606 CancellationSignal cancellationSignal) {
607 // The read is not allowed... to fake it out, we replace the given
608 // selection statement with a dummy one that will always be false.
609 // This way we will get a cursor back that has the correct structure
610 // but contains no rows.
611 if (selection == null) {
612 selection = "'A' = 'B'";
613 } else {
614 selection = "'A' = 'B' AND (" + selection + ")";
615 }
616 return query(uri, projection, selection, selectionArgs, sortOrder, cancellationSignal);
617 }
618
619 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700620 * Implement this to handle query requests from clients.
621 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800622 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
623 * and Threads</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 * <p>
625 * Example client call:<p>
626 * <pre>// Request a specific record.
627 * Cursor managedCursor = managedQuery(
Alan Jones81a476f2009-05-21 12:32:17 +1000628 ContentUris.withAppendedId(Contacts.People.CONTENT_URI, 2),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 projection, // Which columns to return.
630 null, // WHERE clause.
Alan Jones81a476f2009-05-21 12:32:17 +1000631 null, // WHERE clause value substitution
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 People.NAME + " ASC"); // Sort order.</pre>
633 * Example implementation:<p>
634 * <pre>// SQLiteQueryBuilder is a helper class that creates the
635 // proper SQL syntax for us.
636 SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
637
638 // Set the table we're querying.
639 qBuilder.setTables(DATABASE_TABLE_NAME);
640
641 // If the query ends in a specific record number, we're
642 // being asked for a specific record, so set the
643 // WHERE clause in our query.
644 if((URI_MATCHER.match(uri)) == SPECIFIC_MESSAGE){
645 qBuilder.appendWhere("_id=" + uri.getPathLeafId());
646 }
647
648 // Make the query.
649 Cursor c = qBuilder.query(mDb,
650 projection,
651 selection,
652 selectionArgs,
653 groupBy,
654 having,
655 sortOrder);
656 c.setNotificationUri(getContext().getContentResolver(), uri);
657 return c;</pre>
658 *
659 * @param uri The URI to query. This will be the full URI sent by the client;
Alan Jones81a476f2009-05-21 12:32:17 +1000660 * if the client is requesting a specific record, the URI will end in a record number
661 * that the implementation should parse and add to a WHERE or HAVING clause, specifying
662 * that _id value.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 * @param projection The list of columns to put into the cursor. If
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800664 * {@code null} all columns are included.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800665 * @param selection A selection criteria to apply when filtering rows.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800666 * If {@code null} then all rows are included.
Alan Jones81a476f2009-05-21 12:32:17 +1000667 * @param selectionArgs You may include ?s in selection, which will be replaced by
668 * the values from selectionArgs, in order that they appear in the selection.
669 * The values will be bound as Strings.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800670 * @param sortOrder How the rows in the cursor should be sorted.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800671 * If {@code null} then the provider is free to define the sort order.
672 * @return a Cursor or {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 */
674 public abstract Cursor query(Uri uri, String[] projection,
675 String selection, String[] selectionArgs, String sortOrder);
676
Fred Quintana5bba6322009-10-05 14:21:12 -0700677 /**
Jeff Brown4c1241d2012-02-02 17:05:00 -0800678 * Implement this to handle query requests from clients with support for cancellation.
Jeff Brown75ea64f2012-01-25 19:37:13 -0800679 * This method can be called from multiple threads, as described in
680 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
681 * and Threads</a>.
682 * <p>
683 * Example client call:<p>
684 * <pre>// Request a specific record.
685 * Cursor managedCursor = managedQuery(
686 ContentUris.withAppendedId(Contacts.People.CONTENT_URI, 2),
687 projection, // Which columns to return.
688 null, // WHERE clause.
689 null, // WHERE clause value substitution
690 People.NAME + " ASC"); // Sort order.</pre>
691 * Example implementation:<p>
692 * <pre>// SQLiteQueryBuilder is a helper class that creates the
693 // proper SQL syntax for us.
694 SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
695
696 // Set the table we're querying.
697 qBuilder.setTables(DATABASE_TABLE_NAME);
698
699 // If the query ends in a specific record number, we're
700 // being asked for a specific record, so set the
701 // WHERE clause in our query.
702 if((URI_MATCHER.match(uri)) == SPECIFIC_MESSAGE){
703 qBuilder.appendWhere("_id=" + uri.getPathLeafId());
704 }
705
706 // Make the query.
707 Cursor c = qBuilder.query(mDb,
708 projection,
709 selection,
710 selectionArgs,
711 groupBy,
712 having,
713 sortOrder);
714 c.setNotificationUri(getContext().getContentResolver(), uri);
715 return c;</pre>
716 * <p>
717 * If you implement this method then you must also implement the version of
Jeff Brown4c1241d2012-02-02 17:05:00 -0800718 * {@link #query(Uri, String[], String, String[], String)} that does not take a cancellation
719 * signal to ensure correct operation on older versions of the Android Framework in
720 * which the cancellation signal overload was not available.
Jeff Brown75ea64f2012-01-25 19:37:13 -0800721 *
722 * @param uri The URI to query. This will be the full URI sent by the client;
723 * if the client is requesting a specific record, the URI will end in a record number
724 * that the implementation should parse and add to a WHERE or HAVING clause, specifying
725 * that _id value.
726 * @param projection The list of columns to put into the cursor. If
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800727 * {@code null} all columns are included.
Jeff Brown75ea64f2012-01-25 19:37:13 -0800728 * @param selection A selection criteria to apply when filtering rows.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800729 * If {@code null} then all rows are included.
Jeff Brown75ea64f2012-01-25 19:37:13 -0800730 * @param selectionArgs You may include ?s in selection, which will be replaced by
731 * the values from selectionArgs, in order that they appear in the selection.
732 * The values will be bound as Strings.
733 * @param sortOrder How the rows in the cursor should be sorted.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800734 * If {@code null} then the provider is free to define the sort order.
735 * @param cancellationSignal A signal to cancel the operation in progress, or {@code null} if none.
Jeff Brown75ea64f2012-01-25 19:37:13 -0800736 * If the operation is canceled, then {@link OperationCanceledException} will be thrown
737 * when the query is executed.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800738 * @return a Cursor or {@code null}.
Jeff Brown75ea64f2012-01-25 19:37:13 -0800739 */
740 public Cursor query(Uri uri, String[] projection,
741 String selection, String[] selectionArgs, String sortOrder,
Jeff Brown4c1241d2012-02-02 17:05:00 -0800742 CancellationSignal cancellationSignal) {
Jeff Brown75ea64f2012-01-25 19:37:13 -0800743 return query(uri, projection, selection, selectionArgs, sortOrder);
744 }
745
746 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700747 * Implement this to handle requests for the MIME type of the data at the
748 * given URI. The returned MIME type should start with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800749 * <code>vnd.android.cursor.item</code> for a single record,
750 * or <code>vnd.android.cursor.dir/</code> for multiple items.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700751 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800752 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
753 * and Threads</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754 *
Dianne Hackborncca1f0e2010-09-26 18:34:53 -0700755 * <p>Note that there are no permissions needed for an application to
756 * access this information; if your content provider requires read and/or
757 * write permissions, or is not exported, all applications can still call
758 * this method regardless of their access permissions. This allows them
759 * to retrieve the MIME type for a URI when dispatching intents.
760 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800761 * @param uri the URI to query.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800762 * @return a MIME type string, or {@code null} if there is no type.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 */
764 public abstract String getType(Uri uri);
765
766 /**
Dianne Hackbornd7960d12013-01-29 18:55:48 -0800767 * @hide
768 * Implementation when a caller has performed an insert on the content
769 * provider, but that call has been rejected for the operation given
770 * to {@link #setAppOps(int, int)}. The default implementation simply
771 * returns a dummy URI that is the base URI with a 0 path element
772 * appended.
773 */
774 public Uri rejectInsert(Uri uri, ContentValues values) {
775 // If not allowed, we need to return some reasonable URI. Maybe the
776 // content provider should be responsible for this, but for now we
777 // will just return the base URI with a dummy '0' tagged on to it.
778 // You shouldn't be able to read if you can't write, anyway, so it
779 // shouldn't matter much what is returned.
780 return uri.buildUpon().appendPath("0").build();
781 }
782
783 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700784 * Implement this to handle requests to insert a new row.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
786 * after inserting.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700787 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800788 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
789 * and Threads</a>.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800790 * @param uri The content:// URI of the insertion request. This must not be {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800791 * @param values A set of column_name/value pairs to add to the database.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800792 * This must not be {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800793 * @return The URI for the newly inserted item.
794 */
795 public abstract Uri insert(Uri uri, ContentValues values);
796
797 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700798 * Override this to handle requests to insert a set of new rows, or the
799 * default implementation will iterate over the values and call
800 * {@link #insert} on each of them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
802 * after inserting.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700803 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800804 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
805 * and Threads</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800806 *
807 * @param uri The content:// URI of the insertion request.
808 * @param values An array of sets of column_name/value pairs to add to the database.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800809 * This must not be {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 * @return The number of values that were inserted.
811 */
812 public int bulkInsert(Uri uri, ContentValues[] values) {
813 int numValues = values.length;
814 for (int i = 0; i < numValues; i++) {
815 insert(uri, values[i]);
816 }
817 return numValues;
818 }
819
820 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700821 * Implement this to handle requests to delete one or more rows.
822 * The implementation should apply the selection clause when performing
823 * deletion, allowing the operation to affect multiple rows in a directory.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyDelete()}
825 * after deleting.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700826 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800827 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
828 * and Threads</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800829 *
830 * <p>The implementation is responsible for parsing out a row ID at the end
831 * of the URI, if a specific row is being deleted. That is, the client would
832 * pass in <code>content://contacts/people/22</code> and the implementation is
833 * responsible for parsing the record number (22) when creating a SQL statement.
834 *
835 * @param uri The full URI to query, including a row ID (if a specific record is requested).
836 * @param selection An optional restriction to apply to rows when deleting.
837 * @return The number of rows affected.
838 * @throws SQLException
839 */
840 public abstract int delete(Uri uri, String selection, String[] selectionArgs);
841
842 /**
Dan Egnor17876aa2010-07-28 12:28:04 -0700843 * Implement this to handle requests to update one or more rows.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700844 * The implementation should update all rows matching the selection
845 * to set the columns according to the provided values map.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800846 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
847 * after updating.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700848 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800849 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
850 * and Threads</a>.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 *
852 * @param uri The URI to query. This can potentially have a record ID if this
853 * is an update request for a specific record.
Christopher Tate2bc6eb82013-01-03 12:04:08 -0800854 * @param values A set of column_name/value pairs to update in the database.
855 * This must not be {@code null}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800856 * @param selection An optional filter to match rows to update.
857 * @return the number of rows affected.
858 */
859 public abstract int update(Uri uri, ContentValues values, String selection,
860 String[] selectionArgs);
861
862 /**
Dan Egnor17876aa2010-07-28 12:28:04 -0700863 * Override this to handle requests to open a file blob.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700864 * The default implementation always throws {@link FileNotFoundException}.
865 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800866 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
867 * and Threads</a>.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700868 *
Dan Egnor17876aa2010-07-28 12:28:04 -0700869 * <p>This method returns a ParcelFileDescriptor, which is returned directly
870 * to the caller. This way large data (such as images and documents) can be
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700871 * returned without copying the content.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800872 *
873 * <p>The returned ParcelFileDescriptor is owned by the caller, so it is
874 * their responsibility to close it when done. That is, the implementation
875 * of this method should create a new ParcelFileDescriptor for each call.
876 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800877 * <p class="note">For use in Intents, you will want to implement {@link #getType}
878 * to return the appropriate MIME type for the data returned here with
879 * the same URI. This will allow intent resolution to automatically determine the data MIME
880 * type and select the appropriate matching targets as part of its operation.</p>
881 *
882 * <p class="note">For better interoperability with other applications, it is recommended
883 * that for any URIs that can be opened, you also support queries on them
884 * containing at least the columns specified by {@link android.provider.OpenableColumns}.
885 * You may also want to support other common columns if you have additional meta-data
886 * to supply, such as {@link android.provider.MediaStore.MediaColumns#DATE_ADDED}
887 * in {@link android.provider.MediaStore.MediaColumns}.</p>
888 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800889 * @param uri The URI whose file is to be opened.
890 * @param mode Access mode for the file. May be "r" for read-only access,
891 * "rw" for read and write access, or "rwt" for read and write access
892 * that truncates any existing file.
893 *
894 * @return Returns a new ParcelFileDescriptor which you can use to access
895 * the file.
896 *
897 * @throws FileNotFoundException Throws FileNotFoundException if there is
898 * no file associated with the given URI or the mode is invalid.
899 * @throws SecurityException Throws SecurityException if the caller does
900 * not have permission to access the file.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700901 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 * @see #openAssetFile(Uri, String)
903 * @see #openFileHelper(Uri, String)
Dianne Hackborna53ee352013-02-20 12:47:02 -0800904 * @see #getType(android.net.Uri)
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700905 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 public ParcelFileDescriptor openFile(Uri uri, String mode)
907 throws FileNotFoundException {
908 throw new FileNotFoundException("No files supported by provider at "
909 + uri);
910 }
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700911
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800912 /**
913 * This is like {@link #openFile}, but can be implemented by providers
914 * that need to be able to return sub-sections of files, often assets
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700915 * inside of their .apk.
916 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -0800917 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
918 * and Threads</a>.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700919 *
920 * <p>If you implement this, your clients must be able to deal with such
Dan Egnor17876aa2010-07-28 12:28:04 -0700921 * file slices, either directly with
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700922 * {@link ContentResolver#openAssetFileDescriptor}, or by using the higher-level
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800923 * {@link ContentResolver#openInputStream ContentResolver.openInputStream}
924 * or {@link ContentResolver#openOutputStream ContentResolver.openOutputStream}
925 * methods.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700926 *
927 * <p class="note">If you are implementing this to return a full file, you
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800928 * should create the AssetFileDescriptor with
929 * {@link AssetFileDescriptor#UNKNOWN_LENGTH} to be compatible with
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700930 * applications that can not handle sub-sections of files.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800931 *
Dianne Hackborna53ee352013-02-20 12:47:02 -0800932 * <p class="note">For use in Intents, you will want to implement {@link #getType}
933 * to return the appropriate MIME type for the data returned here with
934 * the same URI. This will allow intent resolution to automatically determine the data MIME
935 * type and select the appropriate matching targets as part of its operation.</p>
936 *
937 * <p class="note">For better interoperability with other applications, it is recommended
938 * that for any URIs that can be opened, you also support queries on them
939 * containing at least the columns specified by {@link android.provider.OpenableColumns}.</p>
940 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 * @param uri The URI whose file is to be opened.
942 * @param mode Access mode for the file. May be "r" for read-only access,
943 * "w" for write-only access (erasing whatever data is currently in
944 * the file), "wa" for write-only access to append to any existing data,
945 * "rw" for read and write access on any existing data, and "rwt" for read
946 * and write access that truncates any existing file.
947 *
948 * @return Returns a new AssetFileDescriptor which you can use to access
949 * the file.
950 *
951 * @throws FileNotFoundException Throws FileNotFoundException if there is
952 * no file associated with the given URI or the mode is invalid.
953 * @throws SecurityException Throws SecurityException if the caller does
954 * not have permission to access the file.
955 *
956 * @see #openFile(Uri, String)
957 * @see #openFileHelper(Uri, String)
Dianne Hackborna53ee352013-02-20 12:47:02 -0800958 * @see #getType(android.net.Uri)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 */
960 public AssetFileDescriptor openAssetFile(Uri uri, String mode)
961 throws FileNotFoundException {
962 ParcelFileDescriptor fd = openFile(uri, mode);
963 return fd != null ? new AssetFileDescriptor(fd, 0, -1) : null;
964 }
965
966 /**
967 * Convenience for subclasses that wish to implement {@link #openFile}
968 * by looking up a column named "_data" at the given URI.
969 *
970 * @param uri The URI to be opened.
971 * @param mode The file mode. May be "r" for read-only access,
972 * "w" for write-only access (erasing whatever data is currently in
973 * the file), "wa" for write-only access to append to any existing data,
974 * "rw" for read and write access on any existing data, and "rwt" for read
975 * and write access that truncates any existing file.
976 *
977 * @return Returns a new ParcelFileDescriptor that can be used by the
978 * client to access the file.
979 */
980 protected final ParcelFileDescriptor openFileHelper(Uri uri,
981 String mode) throws FileNotFoundException {
982 Cursor c = query(uri, new String[]{"_data"}, null, null, null);
983 int count = (c != null) ? c.getCount() : 0;
984 if (count != 1) {
985 // If there is not exactly one result, throw an appropriate
986 // exception.
987 if (c != null) {
988 c.close();
989 }
990 if (count == 0) {
991 throw new FileNotFoundException("No entry for " + uri);
992 }
993 throw new FileNotFoundException("Multiple items at " + uri);
994 }
995
996 c.moveToFirst();
997 int i = c.getColumnIndex("_data");
998 String path = (i >= 0 ? c.getString(i) : null);
999 c.close();
1000 if (path == null) {
1001 throw new FileNotFoundException("Column _data not found.");
1002 }
1003
1004 int modeBits = ContentResolver.modeToMode(uri, mode);
1005 return ParcelFileDescriptor.open(new File(path), modeBits);
1006 }
1007
1008 /**
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001009 * Called by a client to determine the types of data streams that this
1010 * content provider supports for the given URI. The default implementation
Christopher Tate2bc6eb82013-01-03 12:04:08 -08001011 * returns {@code null}, meaning no types. If your content provider stores data
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001012 * of a particular type, return that MIME type if it matches the given
1013 * mimeTypeFilter. If it can perform type conversions, return an array
1014 * of all supported MIME types that match mimeTypeFilter.
1015 *
1016 * @param uri The data in the content provider being queried.
1017 * @param mimeTypeFilter The type of data the client desires. May be
1018 * a pattern, such as *\/* to retrieve all possible data types.
Christopher Tate2bc6eb82013-01-03 12:04:08 -08001019 * @return Returns {@code null} if there are no possible data streams for the
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001020 * given mimeTypeFilter. Otherwise returns an array of all available
1021 * concrete MIME types.
1022 *
1023 * @see #getType(Uri)
1024 * @see #openTypedAssetFile(Uri, String, Bundle)
Dianne Hackborn1040dc42010-08-26 22:11:06 -07001025 * @see ClipDescription#compareMimeTypes(String, String)
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001026 */
1027 public String[] getStreamTypes(Uri uri, String mimeTypeFilter) {
1028 return null;
1029 }
1030
1031 /**
1032 * Called by a client to open a read-only stream containing data of a
1033 * particular MIME type. This is like {@link #openAssetFile(Uri, String)},
1034 * except the file can only be read-only and the content provider may
1035 * perform data conversions to generate data of the desired type.
1036 *
1037 * <p>The default implementation compares the given mimeType against the
Dianne Hackborna53ee352013-02-20 12:47:02 -08001038 * result of {@link #getType(Uri)} and, if they match, simply calls
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001039 * {@link #openAssetFile(Uri, String)}.
1040 *
Dianne Hackborn1040dc42010-08-26 22:11:06 -07001041 * <p>See {@link ClipData} for examples of the use and implementation
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001042 * of this method.
1043 *
Dianne Hackborna53ee352013-02-20 12:47:02 -08001044 * <p class="note">For better interoperability with other applications, it is recommended
1045 * that for any URIs that can be opened, you also support queries on them
1046 * containing at least the columns specified by {@link android.provider.OpenableColumns}.
1047 * You may also want to support other common columns if you have additional meta-data
1048 * to supply, such as {@link android.provider.MediaStore.MediaColumns#DATE_ADDED}
1049 * in {@link android.provider.MediaStore.MediaColumns}.</p>
1050 *
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001051 * @param uri The data in the content provider being queried.
1052 * @param mimeTypeFilter The type of data the client desires. May be
1053 * a pattern, such as *\/*, if the caller does not have specific type
1054 * requirements; in this case the content provider will pick its best
1055 * type matching the pattern.
1056 * @param opts Additional options from the client. The definitions of
1057 * these are specific to the content provider being called.
1058 *
1059 * @return Returns a new AssetFileDescriptor from which the client can
1060 * read data of the desired type.
1061 *
1062 * @throws FileNotFoundException Throws FileNotFoundException if there is
1063 * no file associated with the given URI or the mode is invalid.
1064 * @throws SecurityException Throws SecurityException if the caller does
1065 * not have permission to access the data.
1066 * @throws IllegalArgumentException Throws IllegalArgumentException if the
1067 * content provider does not support the requested MIME type.
1068 *
1069 * @see #getStreamTypes(Uri, String)
1070 * @see #openAssetFile(Uri, String)
Dianne Hackborn1040dc42010-08-26 22:11:06 -07001071 * @see ClipDescription#compareMimeTypes(String, String)
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001072 */
1073 public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts)
1074 throws FileNotFoundException {
Dianne Hackborn02dfd262010-08-13 12:34:58 -07001075 if ("*/*".equals(mimeTypeFilter)) {
1076 // If they can take anything, the untyped open call is good enough.
1077 return openAssetFile(uri, "r");
1078 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001079 String baseType = getType(uri);
Dianne Hackborn1040dc42010-08-26 22:11:06 -07001080 if (baseType != null && ClipDescription.compareMimeTypes(baseType, mimeTypeFilter)) {
Dianne Hackborn02dfd262010-08-13 12:34:58 -07001081 // Use old untyped open call if this provider has a type for this
1082 // URI and it matches the request.
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001083 return openAssetFile(uri, "r");
1084 }
1085 throw new FileNotFoundException("Can't open " + uri + " as type " + mimeTypeFilter);
1086 }
1087
1088 /**
1089 * Interface to write a stream of data to a pipe. Use with
1090 * {@link ContentProvider#openPipeHelper}.
1091 */
1092 public interface PipeDataWriter<T> {
1093 /**
1094 * Called from a background thread to stream data out to a pipe.
1095 * Note that the pipe is blocking, so this thread can block on
1096 * writes for an arbitrary amount of time if the client is slow
1097 * at reading.
1098 *
1099 * @param output The pipe where data should be written. This will be
1100 * closed for you upon returning from this function.
1101 * @param uri The URI whose data is to be written.
1102 * @param mimeType The desired type of data to be written.
1103 * @param opts Options supplied by caller.
1104 * @param args Your own custom arguments.
1105 */
1106 public void writeDataToPipe(ParcelFileDescriptor output, Uri uri, String mimeType,
1107 Bundle opts, T args);
1108 }
1109
1110 /**
1111 * A helper function for implementing {@link #openTypedAssetFile}, for
1112 * creating a data pipe and background thread allowing you to stream
1113 * generated data back to the client. This function returns a new
1114 * ParcelFileDescriptor that should be returned to the caller (the caller
1115 * is responsible for closing it).
1116 *
1117 * @param uri The URI whose data is to be written.
1118 * @param mimeType The desired type of data to be written.
1119 * @param opts Options supplied by caller.
1120 * @param args Your own custom arguments.
1121 * @param func Interface implementing the function that will actually
1122 * stream the data.
1123 * @return Returns a new ParcelFileDescriptor holding the read side of
1124 * the pipe. This should be returned to the caller for reading; the caller
1125 * is responsible for closing it when done.
1126 */
1127 public <T> ParcelFileDescriptor openPipeHelper(final Uri uri, final String mimeType,
1128 final Bundle opts, final T args, final PipeDataWriter<T> func)
1129 throws FileNotFoundException {
1130 try {
1131 final ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
1132
1133 AsyncTask<Object, Object, Object> task = new AsyncTask<Object, Object, Object>() {
1134 @Override
1135 protected Object doInBackground(Object... params) {
1136 func.writeDataToPipe(fds[1], uri, mimeType, opts, args);
1137 try {
1138 fds[1].close();
1139 } catch (IOException e) {
1140 Log.w(TAG, "Failure closing pipe", e);
1141 }
1142 return null;
1143 }
1144 };
Dianne Hackborn5d9d03a2011-01-24 13:15:09 -08001145 task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Object[])null);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001146
1147 return fds[0];
1148 } catch (IOException e) {
1149 throw new FileNotFoundException("failure making pipe");
1150 }
1151 }
1152
1153 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 * Returns true if this instance is a temporary content provider.
1155 * @return true if this instance is a temporary content provider
1156 */
1157 protected boolean isTemporary() {
1158 return false;
1159 }
1160
1161 /**
1162 * Returns the Binder object for this provider.
1163 *
1164 * @return the Binder object for this provider
1165 * @hide
1166 */
1167 public IContentProvider getIContentProvider() {
1168 return mTransport;
1169 }
1170
1171 /**
1172 * After being instantiated, this is called to tell the content provider
1173 * about itself.
1174 *
1175 * @param context The context this provider is running in
1176 * @param info Registered information about this content provider
1177 */
1178 public void attachInfo(Context context, ProviderInfo info) {
Dianne Hackborn23fdaf62010-08-06 12:16:55 -07001179 /*
1180 * We may be using AsyncTask from binder threads. Make it init here
1181 * so its static handler is on the main thread.
1182 */
1183 AsyncTask.init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184
1185 /*
1186 * Only allow it to be set once, so after the content service gives
1187 * this to us clients can't change it.
1188 */
1189 if (mContext == null) {
1190 mContext = context;
Dianne Hackborn2af632f2009-07-08 14:56:37 -07001191 mMyUid = Process.myUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001192 if (info != null) {
1193 setReadPermission(info.readPermission);
1194 setWritePermission(info.writePermission);
Dianne Hackborn2af632f2009-07-08 14:56:37 -07001195 setPathPermissions(info.pathPermissions);
Dianne Hackbornb424b632010-08-18 15:59:05 -07001196 mExported = info.exported;
Dianne Hackborn7e6f9762013-02-26 13:35:11 -08001197 mNoPerms = false;
1198 } else {
1199 // We enter here because the content provider is being instantiated
1200 // as a mock. We don't have any information about the provider (such
1201 // as its required permissions), and also want to avoid doing app op
1202 // checks since these aren't real calls coming in and we may not be
1203 // able to get the app ops service at all (if the test is using something
1204 // like the IsolatedProvider). So set this to true, to prevent us
1205 // from enabling app ops on this object.
1206 mNoPerms = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001207 }
1208 ContentProvider.this.onCreate();
1209 }
1210 }
Fred Quintanace31b232009-05-04 16:01:15 -07001211
1212 /**
Dan Egnor17876aa2010-07-28 12:28:04 -07001213 * Override this to handle requests to perform a batch of operations, or the
1214 * default implementation will iterate over the operations and call
1215 * {@link ContentProviderOperation#apply} on each of them.
1216 * If all calls to {@link ContentProviderOperation#apply} succeed
1217 * then a {@link ContentProviderResult} array with as many
1218 * elements as there were operations will be returned. If any of the calls
Dan Egnor6fcc0f0732010-07-27 16:32:17 -07001219 * fail, it is up to the implementation how many of the others take effect.
1220 * This method can be called from multiple threads, as described in
Scott Main7aee61f2011-02-08 11:25:01 -08001221 * <a href="{@docRoot}guide/topics/fundamentals/processes-and-threads.html#Threads">Processes
1222 * and Threads</a>.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -07001223 *
Fred Quintanace31b232009-05-04 16:01:15 -07001224 * @param operations the operations to apply
1225 * @return the results of the applications
Dan Egnor6fcc0f0732010-07-27 16:32:17 -07001226 * @throws OperationApplicationException thrown if any operation fails.
1227 * @see ContentProviderOperation#apply
Fred Quintanace31b232009-05-04 16:01:15 -07001228 */
Fred Quintana03d94902009-05-22 14:23:31 -07001229 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
Fred Quintanace31b232009-05-04 16:01:15 -07001230 throws OperationApplicationException {
Fred Quintana03d94902009-05-22 14:23:31 -07001231 final int numOperations = operations.size();
1232 final ContentProviderResult[] results = new ContentProviderResult[numOperations];
1233 for (int i = 0; i < numOperations; i++) {
1234 results[i] = operations.get(i).apply(this, results, i);
Fred Quintanace31b232009-05-04 16:01:15 -07001235 }
1236 return results;
1237 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -08001238
1239 /**
Dianne Hackborn961321f2013-02-05 17:22:41 -08001240 * @hide
1241 * Front-end to {@link #call(String, String, android.os.Bundle)} that provides the name
1242 * of the calling package.
1243 */
1244 public Bundle callFromPackage(String callingPackag, String method, String arg, Bundle extras) {
1245 return call(method, arg, extras);
1246 }
1247
1248 /**
Manuel Roman2c96a0c2010-08-05 16:39:49 -07001249 * Call a provider-defined method. This can be used to implement
Brad Fitzpatrick534c84c2011-01-12 14:06:30 -08001250 * interfaces that are cheaper and/or unnatural for a table-like
1251 * model.
Brad Fitzpatrick1877d012010-03-04 17:48:13 -08001252 *
Christopher Tate2bc6eb82013-01-03 12:04:08 -08001253 * @param method method name to call. Opaque to framework, but should not be {@code null}.
1254 * @param arg provider-defined String argument. May be {@code null}.
1255 * @param extras provider-defined Bundle argument. May be {@code null}.
1256 * @return provider-defined return value. May be {@code null}, which is also
Brad Fitzpatrick534c84c2011-01-12 14:06:30 -08001257 * the default for providers which don't implement any call methods.
Brad Fitzpatrick1877d012010-03-04 17:48:13 -08001258 */
Brad Fitzpatrick534c84c2011-01-12 14:06:30 -08001259 public Bundle call(String method, String arg, Bundle extras) {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -08001260 return null;
1261 }
Vasu Nori0c9e14a2010-08-04 13:31:48 -07001262
1263 /**
Manuel Roman2c96a0c2010-08-05 16:39:49 -07001264 * Implement this to shut down the ContentProvider instance. You can then
1265 * invoke this method in unit tests.
1266 *
Vasu Nori0c9e14a2010-08-04 13:31:48 -07001267 * <p>
Manuel Roman2c96a0c2010-08-05 16:39:49 -07001268 * Android normally handles ContentProvider startup and shutdown
1269 * automatically. You do not need to start up or shut down a
1270 * ContentProvider. When you invoke a test method on a ContentProvider,
1271 * however, a ContentProvider instance is started and keeps running after
1272 * the test finishes, even if a succeeding test instantiates another
1273 * ContentProvider. A conflict develops because the two instances are
1274 * usually running against the same underlying data source (for example, an
1275 * sqlite database).
1276 * </p>
Vasu Nori0c9e14a2010-08-04 13:31:48 -07001277 * <p>
Manuel Roman2c96a0c2010-08-05 16:39:49 -07001278 * Implementing shutDown() avoids this conflict by providing a way to
1279 * terminate the ContentProvider. This method can also prevent memory leaks
1280 * from multiple instantiations of the ContentProvider, and it can ensure
1281 * unit test isolation by allowing you to completely clean up the test
1282 * fixture before moving on to the next test.
1283 * </p>
Vasu Nori0c9e14a2010-08-04 13:31:48 -07001284 */
1285 public void shutdown() {
1286 Log.w(TAG, "implement ContentProvider shutdown() to make sure all database " +
1287 "connections are gracefully shutdown");
1288 }
Marco Nelissen18cb2872011-11-15 11:19:53 -08001289
1290 /**
1291 * Print the Provider's state into the given stream. This gets invoked if
Jeff Sharkey5554b702012-04-11 18:30:51 -07001292 * you run "adb shell dumpsys activity provider &lt;provider_component_name&gt;".
Marco Nelissen18cb2872011-11-15 11:19:53 -08001293 *
Marco Nelissen18cb2872011-11-15 11:19:53 -08001294 * @param fd The raw file descriptor that the dump is being sent to.
1295 * @param writer The PrintWriter to which you should dump your state. This will be
1296 * closed for you after you return.
1297 * @param args additional arguments to the dump request.
Marco Nelissen18cb2872011-11-15 11:19:53 -08001298 */
1299 public void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
1300 writer.println("nothing to dump");
1301 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -08001302}