blob: 1163add3a4d47a6db70c444a1e16301a521fbfc1 [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
19import android.content.pm.PackageManager;
Dianne Hackborn2af632f2009-07-08 14:56:37 -070020import android.content.pm.PathPermission;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.pm.ProviderInfo;
22import android.content.res.AssetFileDescriptor;
23import android.content.res.Configuration;
24import android.database.Cursor;
25import android.database.CursorToBulkCursorAdaptor;
26import android.database.CursorWindow;
27import android.database.IBulkCursor;
28import android.database.IContentObserver;
29import android.database.SQLException;
30import android.net.Uri;
Dianne Hackborn23fdaf62010-08-06 12:16:55 -070031import android.os.AsyncTask;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032import android.os.Binder;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080033import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.os.ParcelFileDescriptor;
Dianne Hackborn2af632f2009-07-08 14:56:37 -070035import android.os.Process;
Vasu Nori0c9e14a2010-08-04 13:31:48 -070036import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38import java.io.File;
39import java.io.FileNotFoundException;
Dianne Hackborn23fdaf62010-08-06 12:16:55 -070040import java.io.IOException;
Fred Quintana03d94902009-05-22 14:23:31 -070041import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43/**
44 * Content providers are one of the primary building blocks of Android applications, providing
45 * content to applications. They encapsulate data and provide it to applications through the single
46 * {@link ContentResolver} interface. A content provider is only required if you need to share
47 * data between multiple applications. For example, the contacts data is used by multiple
48 * applications and must be stored in a content provider. If you don't need to share data amongst
49 * multiple applications you can use a database directly via
50 * {@link android.database.sqlite.SQLiteDatabase}.
51 *
52 * <p>For more information, read <a href="{@docRoot}guide/topics/providers/content-providers.html">Content
53 * Providers</a>.</p>
54 *
55 * <p>When a request is made via
56 * a {@link ContentResolver} the system inspects the authority of the given URI and passes the
57 * request to the content provider registered with the authority. The content provider can interpret
58 * the rest of the URI however it wants. The {@link UriMatcher} class is helpful for parsing
59 * URIs.</p>
60 *
61 * <p>The primary methods that need to be implemented are:
62 * <ul>
Dan Egnor6fcc0f0732010-07-27 16:32:17 -070063 * <li>{@link #onCreate} which is called to initialize the provider</li>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 * <li>{@link #query} which returns data to the caller</li>
65 * <li>{@link #insert} which inserts new data into the content provider</li>
66 * <li>{@link #update} which updates existing data in the content provider</li>
67 * <li>{@link #delete} which deletes data from the content provider</li>
68 * <li>{@link #getType} which returns the MIME type of data in the content provider</li>
69 * </ul></p>
70 *
Dan Egnor6fcc0f0732010-07-27 16:32:17 -070071 * <p class="caution">Data access methods (such as {@link #insert} and
72 * {@link #update}) may be called from many threads at once, and must be thread-safe.
73 * Other methods (such as {@link #onCreate}) are only called from the application
74 * main thread, and must avoid performing lengthy operations. See the method
75 * descriptions for their expected thread behavior.</p>
76 *
77 * <p>Requests to {@link ContentResolver} are automatically forwarded to the appropriate
78 * ContentProvider instance, so subclasses don't have to worry about the details of
79 * cross-process calls.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080080 */
81public abstract class ContentProvider implements ComponentCallbacks {
Vasu Nori0c9e14a2010-08-04 13:31:48 -070082 private static final String TAG = "ContentProvider";
83
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090084 /*
85 * Note: if you add methods to ContentProvider, you must add similar methods to
86 * MockContentProvider.
87 */
88
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 private Context mContext = null;
Dianne Hackborn2af632f2009-07-08 14:56:37 -070090 private int mMyUid;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 private String mReadPermission;
92 private String mWritePermission;
Dianne Hackborn2af632f2009-07-08 14:56:37 -070093 private PathPermission[] mPathPermissions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094
95 private Transport mTransport = new Transport();
96
Dan Egnor6fcc0f0732010-07-27 16:32:17 -070097 /**
98 * Construct a ContentProvider instance. Content providers must be
99 * <a href="{@docRoot}guide/topics/manifest/provider-element.html">declared
100 * in the manifest</a>, accessed with {@link ContentResolver}, and created
101 * automatically by the system, so applications usually do not create
102 * ContentProvider instances directly.
103 *
104 * <p>At construction time, the object is uninitialized, and most fields and
105 * methods are unavailable. Subclasses should initialize themselves in
106 * {@link #onCreate}, not the constructor.
107 *
108 * <p>Content providers are created on the application main thread at
109 * application launch time. The constructor must not perform lengthy
110 * operations, or application startup will be delayed.
111 */
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +0900112 public ContentProvider() {
113 }
114
115 /**
116 * Constructor just for mocking.
117 *
118 * @param context A Context object which should be some mock instance (like the
119 * instance of {@link android.test.mock.MockContext}).
120 * @param readPermission The read permision you want this instance should have in the
121 * test, which is available via {@link #getReadPermission()}.
122 * @param writePermission The write permission you want this instance should have
123 * in the test, which is available via {@link #getWritePermission()}.
124 * @param pathPermissions The PathPermissions you want this instance should have
125 * in the test, which is available via {@link #getPathPermissions()}.
126 * @hide
127 */
128 public ContentProvider(
129 Context context,
130 String readPermission,
131 String writePermission,
132 PathPermission[] pathPermissions) {
133 mContext = context;
134 mReadPermission = readPermission;
135 mWritePermission = writePermission;
136 mPathPermissions = pathPermissions;
137 }
138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800139 /**
140 * Given an IContentProvider, try to coerce it back to the real
141 * ContentProvider object if it is running in the local process. This can
142 * be used if you know you are running in the same process as a provider,
143 * and want to get direct access to its implementation details. Most
144 * clients should not nor have a reason to use it.
145 *
146 * @param abstractInterface The ContentProvider interface that is to be
147 * coerced.
148 * @return If the IContentProvider is non-null and local, returns its actual
149 * ContentProvider instance. Otherwise returns null.
150 * @hide
151 */
152 public static ContentProvider coerceToLocalContentProvider(
153 IContentProvider abstractInterface) {
154 if (abstractInterface instanceof Transport) {
155 return ((Transport)abstractInterface).getContentProvider();
156 }
157 return null;
158 }
159
160 /**
161 * Binder object that deals with remoting.
162 *
163 * @hide
164 */
165 class Transport extends ContentProviderNative {
166 ContentProvider getContentProvider() {
167 return ContentProvider.this;
168 }
169
170 /**
171 * Remote version of a query, which returns an IBulkCursor. The bulk
172 * cursor should be wrapped with BulkCursorToCursorAdaptor before use.
173 */
174 public IBulkCursor bulkQuery(Uri uri, String[] projection,
175 String selection, String[] selectionArgs, String sortOrder,
176 IContentObserver observer, CursorWindow window) {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700177 enforceReadPermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800178 Cursor cursor = ContentProvider.this.query(uri, projection,
179 selection, selectionArgs, sortOrder);
180 if (cursor == null) {
181 return null;
182 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 return new CursorToBulkCursorAdaptor(cursor, observer,
184 ContentProvider.this.getClass().getName(),
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700185 hasWritePermission(uri), window);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800186 }
187
188 public Cursor query(Uri uri, String[] projection,
189 String selection, String[] selectionArgs, String sortOrder) {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700190 enforceReadPermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 return ContentProvider.this.query(uri, projection, selection,
192 selectionArgs, sortOrder);
193 }
194
195 public String getType(Uri uri) {
196 return ContentProvider.this.getType(uri);
197 }
198
199
200 public Uri insert(Uri uri, ContentValues initialValues) {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700201 enforceWritePermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 return ContentProvider.this.insert(uri, initialValues);
203 }
204
205 public int bulkInsert(Uri uri, ContentValues[] initialValues) {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700206 enforceWritePermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 return ContentProvider.this.bulkInsert(uri, initialValues);
208 }
209
Fred Quintana03d94902009-05-22 14:23:31 -0700210 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
Fred Quintana89437372009-05-15 15:10:40 -0700211 throws OperationApplicationException {
212 for (ContentProviderOperation operation : operations) {
213 if (operation.isReadOperation()) {
Dianne Hackborne3f05442009-07-09 12:15:46 -0700214 enforceReadPermission(operation.getUri());
Fred Quintana89437372009-05-15 15:10:40 -0700215 }
216
217 if (operation.isWriteOperation()) {
Dianne Hackborne3f05442009-07-09 12:15:46 -0700218 enforceWritePermission(operation.getUri());
Fred Quintana89437372009-05-15 15:10:40 -0700219 }
220 }
221 return ContentProvider.this.applyBatch(operations);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700222 }
223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 public int delete(Uri uri, String selection, String[] selectionArgs) {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700225 enforceWritePermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 return ContentProvider.this.delete(uri, selection, selectionArgs);
227 }
228
229 public int update(Uri uri, ContentValues values, String selection,
230 String[] selectionArgs) {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700231 enforceWritePermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 return ContentProvider.this.update(uri, values, selection, selectionArgs);
233 }
234
235 public ParcelFileDescriptor openFile(Uri uri, String mode)
236 throws FileNotFoundException {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700237 if (mode != null && mode.startsWith("rw")) enforceWritePermission(uri);
238 else enforceReadPermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 return ContentProvider.this.openFile(uri, mode);
240 }
241
242 public AssetFileDescriptor openAssetFile(Uri uri, String mode)
243 throws FileNotFoundException {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700244 if (mode != null && mode.startsWith("rw")) enforceWritePermission(uri);
245 else enforceReadPermission(uri);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800246 return ContentProvider.this.openAssetFile(uri, mode);
247 }
248
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800249 /**
250 * @hide
251 */
252 public Bundle call(String method, String request, Bundle args) {
253 return ContentProvider.this.call(method, request, args);
254 }
255
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700256 @Override
257 public String[] getStreamTypes(Uri uri, String mimeTypeFilter) {
258 return ContentProvider.this.getStreamTypes(uri, mimeTypeFilter);
259 }
260
261 @Override
262 public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeType, Bundle opts)
263 throws FileNotFoundException {
264 enforceReadPermission(uri);
265 return ContentProvider.this.openTypedAssetFile(uri, mimeType, opts);
266 }
267
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700268 private void enforceReadPermission(Uri uri) {
269 final int uid = Binder.getCallingUid();
270 if (uid == mMyUid) {
271 return;
272 }
273
274 final Context context = getContext();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800275 final String rperm = getReadPermission();
276 final int pid = Binder.getCallingPid();
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700277 if (rperm == null
278 || context.checkPermission(rperm, pid, uid)
279 == PackageManager.PERMISSION_GRANTED) {
280 return;
281 }
282
283 PathPermission[] pps = getPathPermissions();
284 if (pps != null) {
285 final String path = uri.getPath();
286 int i = pps.length;
287 while (i > 0) {
288 i--;
289 final PathPermission pp = pps[i];
290 final String pprperm = pp.getReadPermission();
291 if (pprperm != null && pp.match(path)) {
292 if (context.checkPermission(pprperm, pid, uid)
293 == PackageManager.PERMISSION_GRANTED) {
294 return;
295 }
296 }
297 }
298 }
299
300 if (context.checkUriPermission(uri, pid, uid,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 Intent.FLAG_GRANT_READ_URI_PERMISSION)
302 == PackageManager.PERMISSION_GRANTED) {
303 return;
304 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700305
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800306 String msg = "Permission Denial: reading "
307 + ContentProvider.this.getClass().getName()
308 + " uri " + uri + " from pid=" + Binder.getCallingPid()
309 + ", uid=" + Binder.getCallingUid()
310 + " requires " + rperm;
311 throw new SecurityException(msg);
312 }
313
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700314 private boolean hasWritePermission(Uri uri) {
315 final int uid = Binder.getCallingUid();
316 if (uid == mMyUid) {
317 return true;
318 }
319
320 final Context context = getContext();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800321 final String wperm = getWritePermission();
322 final int pid = Binder.getCallingPid();
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700323 if (wperm == null
324 || context.checkPermission(wperm, pid, uid)
325 == PackageManager.PERMISSION_GRANTED) {
326 return true;
327 }
328
329 PathPermission[] pps = getPathPermissions();
330 if (pps != null) {
331 final String path = uri.getPath();
332 int i = pps.length;
333 while (i > 0) {
334 i--;
335 final PathPermission pp = pps[i];
336 final String ppwperm = pp.getWritePermission();
337 if (ppwperm != null && pp.match(path)) {
338 if (context.checkPermission(ppwperm, pid, uid)
339 == PackageManager.PERMISSION_GRANTED) {
340 return true;
341 }
342 }
343 }
344 }
345
346 if (context.checkUriPermission(uri, pid, uid,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
348 == PackageManager.PERMISSION_GRANTED) {
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700349 return true;
350 }
351
352 return false;
353 }
354
355 private void enforceWritePermission(Uri uri) {
356 if (hasWritePermission(uri)) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 return;
358 }
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 String msg = "Permission Denial: writing "
361 + ContentProvider.this.getClass().getName()
362 + " uri " + uri + " from pid=" + Binder.getCallingPid()
363 + ", uid=" + Binder.getCallingUid()
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700364 + " requires " + getWritePermission();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800365 throw new SecurityException(msg);
366 }
367 }
368
369
370 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700371 * Retrieves the Context this provider is running in. Only available once
372 * {@link #onCreate} has been called -- this will return null in the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800373 * constructor.
374 */
375 public final Context getContext() {
376 return mContext;
377 }
378
379 /**
380 * Change the permission required to read data from the content
381 * provider. This is normally set for you from its manifest information
382 * when the provider is first created.
383 *
384 * @param permission Name of the permission required for read-only access.
385 */
386 protected final void setReadPermission(String permission) {
387 mReadPermission = permission;
388 }
389
390 /**
391 * Return the name of the permission required for read-only access to
392 * this content provider. This method can be called from multiple
393 * threads, as described in
394 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
395 * Processes and Threads</a>.
396 */
397 public final String getReadPermission() {
398 return mReadPermission;
399 }
400
401 /**
402 * Change the permission required to read and write data in the content
403 * provider. This is normally set for you from its manifest information
404 * when the provider is first created.
405 *
406 * @param permission Name of the permission required for read/write access.
407 */
408 protected final void setWritePermission(String permission) {
409 mWritePermission = permission;
410 }
411
412 /**
413 * Return the name of the permission required for read/write access to
414 * this content provider. This method can be called from multiple
415 * threads, as described in
416 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
417 * Processes and Threads</a>.
418 */
419 public final String getWritePermission() {
420 return mWritePermission;
421 }
422
423 /**
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700424 * Change the path-based permission required to read and/or write data in
425 * the content provider. This is normally set for you from its manifest
426 * information when the provider is first created.
427 *
428 * @param permissions Array of path permission descriptions.
429 */
430 protected final void setPathPermissions(PathPermission[] permissions) {
431 mPathPermissions = permissions;
432 }
433
434 /**
435 * Return the path-based permissions required for read and/or write access to
436 * this content provider. This method can be called from multiple
437 * threads, as described in
438 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
439 * Processes and Threads</a>.
440 */
441 public final PathPermission[] getPathPermissions() {
442 return mPathPermissions;
443 }
444
445 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700446 * Implement this to initialize your content provider on startup.
447 * This method is called for all registered content providers on the
448 * application main thread at application launch time. It must not perform
449 * lengthy operations, or application startup will be delayed.
450 *
451 * <p>You should defer nontrivial initialization (such as opening,
452 * upgrading, and scanning databases) until the content provider is used
453 * (via {@link #query}, {@link #insert}, etc). Deferred initialization
454 * keeps application startup fast, avoids unnecessary work if the provider
455 * turns out not to be needed, and stops database errors (such as a full
456 * disk) from halting application launch.
457 *
Dan Egnor17876aa2010-07-28 12:28:04 -0700458 * <p>If you use SQLite, {@link android.database.sqlite.SQLiteOpenHelper}
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700459 * is a helpful utility class that makes it easy to manage databases,
460 * and will automatically defer opening until first use. If you do use
461 * SQLiteOpenHelper, make sure to avoid calling
462 * {@link android.database.sqlite.SQLiteOpenHelper#getReadableDatabase} or
463 * {@link android.database.sqlite.SQLiteOpenHelper#getWritableDatabase}
464 * from this method. (Instead, override
465 * {@link android.database.sqlite.SQLiteOpenHelper#onOpen} to initialize the
466 * database when it is first opened.)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800467 *
468 * @return true if the provider was successfully loaded, false otherwise
469 */
470 public abstract boolean onCreate();
471
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700472 /**
473 * {@inheritDoc}
474 * This method is always called on the application main thread, and must
475 * not perform lengthy operations.
476 *
477 * <p>The default content provider implementation does nothing.
478 * Override this method to take appropriate action.
479 * (Content providers do not usually care about things like screen
480 * orientation, but may want to know about locale changes.)
481 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800482 public void onConfigurationChanged(Configuration newConfig) {
483 }
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700484
485 /**
486 * {@inheritDoc}
487 * This method is always called on the application main thread, and must
488 * not perform lengthy operations.
489 *
490 * <p>The default content provider implementation does nothing.
491 * Subclasses may override this method to take appropriate action.
492 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800493 public void onLowMemory() {
494 }
495
496 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700497 * Implement this to handle query requests from clients.
498 * This method can be called from multiple threads, as described in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
500 * Processes and Threads</a>.
501 * <p>
502 * Example client call:<p>
503 * <pre>// Request a specific record.
504 * Cursor managedCursor = managedQuery(
Alan Jones81a476f2009-05-21 12:32:17 +1000505 ContentUris.withAppendedId(Contacts.People.CONTENT_URI, 2),
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 projection, // Which columns to return.
507 null, // WHERE clause.
Alan Jones81a476f2009-05-21 12:32:17 +1000508 null, // WHERE clause value substitution
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 People.NAME + " ASC"); // Sort order.</pre>
510 * Example implementation:<p>
511 * <pre>// SQLiteQueryBuilder is a helper class that creates the
512 // proper SQL syntax for us.
513 SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
514
515 // Set the table we're querying.
516 qBuilder.setTables(DATABASE_TABLE_NAME);
517
518 // If the query ends in a specific record number, we're
519 // being asked for a specific record, so set the
520 // WHERE clause in our query.
521 if((URI_MATCHER.match(uri)) == SPECIFIC_MESSAGE){
522 qBuilder.appendWhere("_id=" + uri.getPathLeafId());
523 }
524
525 // Make the query.
526 Cursor c = qBuilder.query(mDb,
527 projection,
528 selection,
529 selectionArgs,
530 groupBy,
531 having,
532 sortOrder);
533 c.setNotificationUri(getContext().getContentResolver(), uri);
534 return c;</pre>
535 *
536 * @param uri The URI to query. This will be the full URI sent by the client;
Alan Jones81a476f2009-05-21 12:32:17 +1000537 * if the client is requesting a specific record, the URI will end in a record number
538 * that the implementation should parse and add to a WHERE or HAVING clause, specifying
539 * that _id value.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 * @param projection The list of columns to put into the cursor. If
541 * null all columns are included.
542 * @param selection A selection criteria to apply when filtering rows.
543 * If null then all rows are included.
Alan Jones81a476f2009-05-21 12:32:17 +1000544 * @param selectionArgs You may include ?s in selection, which will be replaced by
545 * the values from selectionArgs, in order that they appear in the selection.
546 * The values will be bound as Strings.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800547 * @param sortOrder How the rows in the cursor should be sorted.
Alan Jones81a476f2009-05-21 12:32:17 +1000548 * If null then the provider is free to define the sort order.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800549 * @return a Cursor or null.
550 */
551 public abstract Cursor query(Uri uri, String[] projection,
552 String selection, String[] selectionArgs, String sortOrder);
553
Fred Quintana5bba6322009-10-05 14:21:12 -0700554 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700555 * Implement this to handle requests for the MIME type of the data at the
556 * given URI. The returned MIME type should start with
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 * <code>vnd.android.cursor.item</code> for a single record,
558 * or <code>vnd.android.cursor.dir/</code> for multiple items.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700559 * This method can be called from multiple threads, as described in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
561 * Processes and Threads</a>.
562 *
563 * @param uri the URI to query.
564 * @return a MIME type string, or null if there is no type.
565 */
566 public abstract String getType(Uri uri);
567
568 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700569 * Implement this to handle requests to insert a new row.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800570 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
571 * after inserting.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700572 * This method can be called from multiple threads, as described in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800573 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
574 * Processes and Threads</a>.
575 * @param uri The content:// URI of the insertion request.
576 * @param values A set of column_name/value pairs to add to the database.
577 * @return The URI for the newly inserted item.
578 */
579 public abstract Uri insert(Uri uri, ContentValues values);
580
581 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700582 * Override this to handle requests to insert a set of new rows, or the
583 * default implementation will iterate over the values and call
584 * {@link #insert} on each of them.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
586 * after inserting.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700587 * This method can be called from multiple threads, as described in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
589 * Processes and Threads</a>.
590 *
591 * @param uri The content:// URI of the insertion request.
592 * @param values An array of sets of column_name/value pairs to add to the database.
593 * @return The number of values that were inserted.
594 */
595 public int bulkInsert(Uri uri, ContentValues[] values) {
596 int numValues = values.length;
597 for (int i = 0; i < numValues; i++) {
598 insert(uri, values[i]);
599 }
600 return numValues;
601 }
602
603 /**
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700604 * Implement this to handle requests to delete one or more rows.
605 * The implementation should apply the selection clause when performing
606 * deletion, allowing the operation to affect multiple rows in a directory.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800607 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyDelete()}
608 * after deleting.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700609 * This method can be called from multiple threads, as described in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800610 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
611 * Processes and Threads</a>.
612 *
613 * <p>The implementation is responsible for parsing out a row ID at the end
614 * of the URI, if a specific row is being deleted. That is, the client would
615 * pass in <code>content://contacts/people/22</code> and the implementation is
616 * responsible for parsing the record number (22) when creating a SQL statement.
617 *
618 * @param uri The full URI to query, including a row ID (if a specific record is requested).
619 * @param selection An optional restriction to apply to rows when deleting.
620 * @return The number of rows affected.
621 * @throws SQLException
622 */
623 public abstract int delete(Uri uri, String selection, String[] selectionArgs);
624
625 /**
Dan Egnor17876aa2010-07-28 12:28:04 -0700626 * Implement this to handle requests to update one or more rows.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700627 * The implementation should update all rows matching the selection
628 * to set the columns according to the provided values map.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800629 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
630 * after updating.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700631 * This method can be called from multiple threads, as described in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800632 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
633 * Processes and Threads</a>.
634 *
635 * @param uri The URI to query. This can potentially have a record ID if this
636 * is an update request for a specific record.
637 * @param values A Bundle mapping from column names to new column values (NULL is a
638 * valid value).
639 * @param selection An optional filter to match rows to update.
640 * @return the number of rows affected.
641 */
642 public abstract int update(Uri uri, ContentValues values, String selection,
643 String[] selectionArgs);
644
645 /**
Dan Egnor17876aa2010-07-28 12:28:04 -0700646 * Override this to handle requests to open a file blob.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700647 * The default implementation always throws {@link FileNotFoundException}.
648 * This method can be called from multiple threads, as described in
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800649 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
650 * Processes and Threads</a>.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700651 *
Dan Egnor17876aa2010-07-28 12:28:04 -0700652 * <p>This method returns a ParcelFileDescriptor, which is returned directly
653 * to the caller. This way large data (such as images and documents) can be
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700654 * returned without copying the content.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800655 *
656 * <p>The returned ParcelFileDescriptor is owned by the caller, so it is
657 * their responsibility to close it when done. That is, the implementation
658 * of this method should create a new ParcelFileDescriptor for each call.
659 *
660 * @param uri The URI whose file is to be opened.
661 * @param mode Access mode for the file. May be "r" for read-only access,
662 * "rw" for read and write access, or "rwt" for read and write access
663 * that truncates any existing file.
664 *
665 * @return Returns a new ParcelFileDescriptor which you can use to access
666 * the file.
667 *
668 * @throws FileNotFoundException Throws FileNotFoundException if there is
669 * no file associated with the given URI or the mode is invalid.
670 * @throws SecurityException Throws SecurityException if the caller does
671 * not have permission to access the file.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700672 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 * @see #openAssetFile(Uri, String)
674 * @see #openFileHelper(Uri, String)
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700675 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800676 public ParcelFileDescriptor openFile(Uri uri, String mode)
677 throws FileNotFoundException {
678 throw new FileNotFoundException("No files supported by provider at "
679 + uri);
680 }
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700681
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800682 /**
683 * This is like {@link #openFile}, but can be implemented by providers
684 * that need to be able to return sub-sections of files, often assets
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700685 * inside of their .apk.
686 * This method can be called from multiple threads, as described in
687 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
688 * Processes and Threads</a>.
689 *
690 * <p>If you implement this, your clients must be able to deal with such
Dan Egnor17876aa2010-07-28 12:28:04 -0700691 * file slices, either directly with
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700692 * {@link ContentResolver#openAssetFileDescriptor}, or by using the higher-level
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800693 * {@link ContentResolver#openInputStream ContentResolver.openInputStream}
694 * or {@link ContentResolver#openOutputStream ContentResolver.openOutputStream}
695 * methods.
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700696 *
697 * <p class="note">If you are implementing this to return a full file, you
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800698 * should create the AssetFileDescriptor with
699 * {@link AssetFileDescriptor#UNKNOWN_LENGTH} to be compatible with
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700700 * applications that can not handle sub-sections of files.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800701 *
702 * @param uri The URI whose file is to be opened.
703 * @param mode Access mode for the file. May be "r" for read-only access,
704 * "w" for write-only access (erasing whatever data is currently in
705 * the file), "wa" for write-only access to append to any existing data,
706 * "rw" for read and write access on any existing data, and "rwt" for read
707 * and write access that truncates any existing file.
708 *
709 * @return Returns a new AssetFileDescriptor which you can use to access
710 * the file.
711 *
712 * @throws FileNotFoundException Throws FileNotFoundException if there is
713 * no file associated with the given URI or the mode is invalid.
714 * @throws SecurityException Throws SecurityException if the caller does
715 * not have permission to access the file.
716 *
717 * @see #openFile(Uri, String)
718 * @see #openFileHelper(Uri, String)
719 */
720 public AssetFileDescriptor openAssetFile(Uri uri, String mode)
721 throws FileNotFoundException {
722 ParcelFileDescriptor fd = openFile(uri, mode);
723 return fd != null ? new AssetFileDescriptor(fd, 0, -1) : null;
724 }
725
726 /**
727 * Convenience for subclasses that wish to implement {@link #openFile}
728 * by looking up a column named "_data" at the given URI.
729 *
730 * @param uri The URI to be opened.
731 * @param mode The file mode. May be "r" for read-only access,
732 * "w" for write-only access (erasing whatever data is currently in
733 * the file), "wa" for write-only access to append to any existing data,
734 * "rw" for read and write access on any existing data, and "rwt" for read
735 * and write access that truncates any existing file.
736 *
737 * @return Returns a new ParcelFileDescriptor that can be used by the
738 * client to access the file.
739 */
740 protected final ParcelFileDescriptor openFileHelper(Uri uri,
741 String mode) throws FileNotFoundException {
742 Cursor c = query(uri, new String[]{"_data"}, null, null, null);
743 int count = (c != null) ? c.getCount() : 0;
744 if (count != 1) {
745 // If there is not exactly one result, throw an appropriate
746 // exception.
747 if (c != null) {
748 c.close();
749 }
750 if (count == 0) {
751 throw new FileNotFoundException("No entry for " + uri);
752 }
753 throw new FileNotFoundException("Multiple items at " + uri);
754 }
755
756 c.moveToFirst();
757 int i = c.getColumnIndex("_data");
758 String path = (i >= 0 ? c.getString(i) : null);
759 c.close();
760 if (path == null) {
761 throw new FileNotFoundException("Column _data not found.");
762 }
763
764 int modeBits = ContentResolver.modeToMode(uri, mode);
765 return ParcelFileDescriptor.open(new File(path), modeBits);
766 }
767
768 /**
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700769 * Helper to compare two MIME types, where one may be a pattern.
770 * @param concreteType A fully-specified MIME type.
771 * @param desiredType A desired MIME type that may be a pattern such as *\/*.
772 * @return Returns true if the two MIME types match.
773 */
774 public static boolean compareMimeTypes(String concreteType, String desiredType) {
775 final int typeLength = desiredType.length();
776 if (typeLength == 3 && desiredType.equals("*/*")) {
777 return true;
778 }
779
780 final int slashpos = desiredType.indexOf('/');
781 if (slashpos > 0) {
782 if (typeLength == slashpos+2 && desiredType.charAt(slashpos+1) == '*') {
783 if (desiredType.regionMatches(0, concreteType, 0, slashpos+1)) {
784 return true;
785 }
786 } else if (desiredType.equals(concreteType)) {
787 return true;
788 }
789 }
790
791 return false;
792 }
793
794 /**
795 * Called by a client to determine the types of data streams that this
796 * content provider supports for the given URI. The default implementation
797 * returns null, meaning no types. If your content provider stores data
798 * of a particular type, return that MIME type if it matches the given
799 * mimeTypeFilter. If it can perform type conversions, return an array
800 * of all supported MIME types that match mimeTypeFilter.
801 *
802 * @param uri The data in the content provider being queried.
803 * @param mimeTypeFilter The type of data the client desires. May be
804 * a pattern, such as *\/* to retrieve all possible data types.
805 * @returns Returns null if there are no possible data streams for the
806 * given mimeTypeFilter. Otherwise returns an array of all available
807 * concrete MIME types.
808 *
809 * @see #getType(Uri)
810 * @see #openTypedAssetFile(Uri, String, Bundle)
811 * @see #compareMimeTypes(String, String)
812 */
813 public String[] getStreamTypes(Uri uri, String mimeTypeFilter) {
814 return null;
815 }
816
817 /**
818 * Called by a client to open a read-only stream containing data of a
819 * particular MIME type. This is like {@link #openAssetFile(Uri, String)},
820 * except the file can only be read-only and the content provider may
821 * perform data conversions to generate data of the desired type.
822 *
823 * <p>The default implementation compares the given mimeType against the
824 * result of {@link #getType(Uri)} and, if the match, simple calls
825 * {@link #openAssetFile(Uri, String)}.
826 *
827 * <p>See {@link ClippedData} for examples of the use and implementation
828 * of this method.
829 *
830 * @param uri The data in the content provider being queried.
831 * @param mimeTypeFilter The type of data the client desires. May be
832 * a pattern, such as *\/*, if the caller does not have specific type
833 * requirements; in this case the content provider will pick its best
834 * type matching the pattern.
835 * @param opts Additional options from the client. The definitions of
836 * these are specific to the content provider being called.
837 *
838 * @return Returns a new AssetFileDescriptor from which the client can
839 * read data of the desired type.
840 *
841 * @throws FileNotFoundException Throws FileNotFoundException if there is
842 * no file associated with the given URI or the mode is invalid.
843 * @throws SecurityException Throws SecurityException if the caller does
844 * not have permission to access the data.
845 * @throws IllegalArgumentException Throws IllegalArgumentException if the
846 * content provider does not support the requested MIME type.
847 *
848 * @see #getStreamTypes(Uri, String)
849 * @see #openAssetFile(Uri, String)
850 * @see #compareMimeTypes(String, String)
851 */
852 public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts)
853 throws FileNotFoundException {
854 String baseType = getType(uri);
855 if (baseType != null && compareMimeTypes(baseType, mimeTypeFilter)) {
856 return openAssetFile(uri, "r");
857 }
858 throw new FileNotFoundException("Can't open " + uri + " as type " + mimeTypeFilter);
859 }
860
861 /**
862 * Interface to write a stream of data to a pipe. Use with
863 * {@link ContentProvider#openPipeHelper}.
864 */
865 public interface PipeDataWriter<T> {
866 /**
867 * Called from a background thread to stream data out to a pipe.
868 * Note that the pipe is blocking, so this thread can block on
869 * writes for an arbitrary amount of time if the client is slow
870 * at reading.
871 *
872 * @param output The pipe where data should be written. This will be
873 * closed for you upon returning from this function.
874 * @param uri The URI whose data is to be written.
875 * @param mimeType The desired type of data to be written.
876 * @param opts Options supplied by caller.
877 * @param args Your own custom arguments.
878 */
879 public void writeDataToPipe(ParcelFileDescriptor output, Uri uri, String mimeType,
880 Bundle opts, T args);
881 }
882
883 /**
884 * A helper function for implementing {@link #openTypedAssetFile}, for
885 * creating a data pipe and background thread allowing you to stream
886 * generated data back to the client. This function returns a new
887 * ParcelFileDescriptor that should be returned to the caller (the caller
888 * is responsible for closing it).
889 *
890 * @param uri The URI whose data is to be written.
891 * @param mimeType The desired type of data to be written.
892 * @param opts Options supplied by caller.
893 * @param args Your own custom arguments.
894 * @param func Interface implementing the function that will actually
895 * stream the data.
896 * @return Returns a new ParcelFileDescriptor holding the read side of
897 * the pipe. This should be returned to the caller for reading; the caller
898 * is responsible for closing it when done.
899 */
900 public <T> ParcelFileDescriptor openPipeHelper(final Uri uri, final String mimeType,
901 final Bundle opts, final T args, final PipeDataWriter<T> func)
902 throws FileNotFoundException {
903 try {
904 final ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
905
906 AsyncTask<Object, Object, Object> task = new AsyncTask<Object, Object, Object>() {
907 @Override
908 protected Object doInBackground(Object... params) {
909 func.writeDataToPipe(fds[1], uri, mimeType, opts, args);
910 try {
911 fds[1].close();
912 } catch (IOException e) {
913 Log.w(TAG, "Failure closing pipe", e);
914 }
915 return null;
916 }
917 };
918 task.execute((Object[])null);
919
920 return fds[0];
921 } catch (IOException e) {
922 throw new FileNotFoundException("failure making pipe");
923 }
924 }
925
926 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800927 * Returns true if this instance is a temporary content provider.
928 * @return true if this instance is a temporary content provider
929 */
930 protected boolean isTemporary() {
931 return false;
932 }
933
934 /**
935 * Returns the Binder object for this provider.
936 *
937 * @return the Binder object for this provider
938 * @hide
939 */
940 public IContentProvider getIContentProvider() {
941 return mTransport;
942 }
943
944 /**
945 * After being instantiated, this is called to tell the content provider
946 * about itself.
947 *
948 * @param context The context this provider is running in
949 * @param info Registered information about this content provider
950 */
951 public void attachInfo(Context context, ProviderInfo info) {
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700952 /*
953 * We may be using AsyncTask from binder threads. Make it init here
954 * so its static handler is on the main thread.
955 */
956 AsyncTask.init();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800957
958 /*
959 * Only allow it to be set once, so after the content service gives
960 * this to us clients can't change it.
961 */
962 if (mContext == null) {
963 mContext = context;
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700964 mMyUid = Process.myUid();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800965 if (info != null) {
966 setReadPermission(info.readPermission);
967 setWritePermission(info.writePermission);
Dianne Hackborn2af632f2009-07-08 14:56:37 -0700968 setPathPermissions(info.pathPermissions);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 }
970 ContentProvider.this.onCreate();
971 }
972 }
Fred Quintanace31b232009-05-04 16:01:15 -0700973
974 /**
Dan Egnor17876aa2010-07-28 12:28:04 -0700975 * Override this to handle requests to perform a batch of operations, or the
976 * default implementation will iterate over the operations and call
977 * {@link ContentProviderOperation#apply} on each of them.
978 * If all calls to {@link ContentProviderOperation#apply} succeed
979 * then a {@link ContentProviderResult} array with as many
980 * elements as there were operations will be returned. If any of the calls
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700981 * fail, it is up to the implementation how many of the others take effect.
982 * This method can be called from multiple threads, as described in
983 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
984 * Processes and Threads</a>.
985 *
Fred Quintanace31b232009-05-04 16:01:15 -0700986 * @param operations the operations to apply
987 * @return the results of the applications
Dan Egnor6fcc0f0732010-07-27 16:32:17 -0700988 * @throws OperationApplicationException thrown if any operation fails.
989 * @see ContentProviderOperation#apply
Fred Quintanace31b232009-05-04 16:01:15 -0700990 */
Fred Quintana03d94902009-05-22 14:23:31 -0700991 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
Fred Quintanace31b232009-05-04 16:01:15 -0700992 throws OperationApplicationException {
Fred Quintana03d94902009-05-22 14:23:31 -0700993 final int numOperations = operations.size();
994 final ContentProviderResult[] results = new ContentProviderResult[numOperations];
995 for (int i = 0; i < numOperations; i++) {
996 results[i] = operations.get(i).apply(this, results, i);
Fred Quintanace31b232009-05-04 16:01:15 -0700997 }
998 return results;
999 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -08001000
1001 /**
1002 * @hide -- until interface has proven itself
1003 *
1004 * Call an provider-defined method. This can be used to implement
1005 * interfaces that are cheaper than using a Cursor.
1006 *
1007 * @param method Method name to call. Opaque to framework.
1008 * @param request Nullable String argument passed to method.
1009 * @param args Nullable Bundle argument passed to method.
1010 */
1011 public Bundle call(String method, String request, Bundle args) {
1012 return null;
1013 }
Vasu Nori0c9e14a2010-08-04 13:31:48 -07001014
1015 /**
1016 * Shuts down this instance of the ContentProvider. It is useful when writing tests that use
1017 * the ContentProvider.
1018 * <p>
1019 * If a unittest starts the ContentProvider in its test(..() methods, it could run into sqlite
1020 * errors "disk I/O error" or "corruption" in the following scenario:
1021 * <ul>
1022 * <li>Say, there are 2 test methods in the unittest</li>
1023 * <li>test1() (or setUp()) causes ContentProvider object to be initialized and
1024 * assume it opens a database connection to "foo.db"</li>
1025 * <li>est1() completes and test2() starts</li>
1026 * <li>During the execution of test2() there will be 2 connections to "foo.db"</li>
1027 * <li>Different threads in the ContentProvider may have one of these two connection
1028 * handles. This is not a problem per se</li>
1029 * <li>But if the two threads with 2 database connections don't interact correctly,
1030 * there could be unexpected errors from sqlite</li>
1031 * <li>Some of those unexpected errros are "disk I/O error" or "corruption" error</li>
1032 * <li>Common practice in tearDown() is to delete test directory (and the database files)</li>
1033 * <li>If this is done while some threads are still holding unclosed database connections,
1034 * sqlite quite easily gets into corruption and disk I/O errors</li>
1035 * </ul>
1036 * <p>
1037 * tearDown() in the unittests should call this method to have ContentProvider gracefully
1038 * shutdown all database connections.
1039 */
1040 public void shutdown() {
1041 Log.w(TAG, "implement ContentProvider shutdown() to make sure all database " +
1042 "connections are gracefully shutdown");
1043 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -08001044}