blob: 4e631c4fca1509e9cbd142390cf2c457480691a5 [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;
20import android.content.pm.ProviderInfo;
21import android.content.res.AssetFileDescriptor;
22import android.content.res.Configuration;
23import android.database.Cursor;
24import android.database.CursorToBulkCursorAdaptor;
25import android.database.CursorWindow;
26import android.database.IBulkCursor;
27import android.database.IContentObserver;
28import android.database.SQLException;
29import android.net.Uri;
30import android.os.Binder;
31import android.os.ParcelFileDescriptor;
32
33import java.io.File;
34import java.io.FileNotFoundException;
Fred Quintana03d94902009-05-22 14:23:31 -070035import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37/**
38 * Content providers are one of the primary building blocks of Android applications, providing
39 * content to applications. They encapsulate data and provide it to applications through the single
40 * {@link ContentResolver} interface. A content provider is only required if you need to share
41 * data between multiple applications. For example, the contacts data is used by multiple
42 * applications and must be stored in a content provider. If you don't need to share data amongst
43 * multiple applications you can use a database directly via
44 * {@link android.database.sqlite.SQLiteDatabase}.
45 *
46 * <p>For more information, read <a href="{@docRoot}guide/topics/providers/content-providers.html">Content
47 * Providers</a>.</p>
48 *
49 * <p>When a request is made via
50 * a {@link ContentResolver} the system inspects the authority of the given URI and passes the
51 * request to the content provider registered with the authority. The content provider can interpret
52 * the rest of the URI however it wants. The {@link UriMatcher} class is helpful for parsing
53 * URIs.</p>
54 *
55 * <p>The primary methods that need to be implemented are:
56 * <ul>
57 * <li>{@link #query} which returns data to the caller</li>
58 * <li>{@link #insert} which inserts new data into the content provider</li>
59 * <li>{@link #update} which updates existing data in the content provider</li>
60 * <li>{@link #delete} which deletes data from the content provider</li>
61 * <li>{@link #getType} which returns the MIME type of data in the content provider</li>
62 * </ul></p>
63 *
64 * <p>This class takes care of cross process calls so subclasses don't have to worry about which
65 * process a request is coming from.</p>
66 */
67public abstract class ContentProvider implements ComponentCallbacks {
68 private Context mContext = null;
69 private String mReadPermission;
70 private String mWritePermission;
71
72 private Transport mTransport = new Transport();
73
74 /**
75 * Given an IContentProvider, try to coerce it back to the real
76 * ContentProvider object if it is running in the local process. This can
77 * be used if you know you are running in the same process as a provider,
78 * and want to get direct access to its implementation details. Most
79 * clients should not nor have a reason to use it.
80 *
81 * @param abstractInterface The ContentProvider interface that is to be
82 * coerced.
83 * @return If the IContentProvider is non-null and local, returns its actual
84 * ContentProvider instance. Otherwise returns null.
85 * @hide
86 */
87 public static ContentProvider coerceToLocalContentProvider(
88 IContentProvider abstractInterface) {
89 if (abstractInterface instanceof Transport) {
90 return ((Transport)abstractInterface).getContentProvider();
91 }
92 return null;
93 }
94
95 /**
96 * Binder object that deals with remoting.
97 *
98 * @hide
99 */
100 class Transport extends ContentProviderNative {
101 ContentProvider getContentProvider() {
102 return ContentProvider.this;
103 }
104
105 /**
106 * Remote version of a query, which returns an IBulkCursor. The bulk
107 * cursor should be wrapped with BulkCursorToCursorAdaptor before use.
108 */
109 public IBulkCursor bulkQuery(Uri uri, String[] projection,
110 String selection, String[] selectionArgs, String sortOrder,
111 IContentObserver observer, CursorWindow window) {
112 checkReadPermission(uri);
113 Cursor cursor = ContentProvider.this.query(uri, projection,
114 selection, selectionArgs, sortOrder);
115 if (cursor == null) {
116 return null;
117 }
118 String wperm = getWritePermission();
119 return new CursorToBulkCursorAdaptor(cursor, observer,
120 ContentProvider.this.getClass().getName(),
121 wperm == null ||
122 getContext().checkCallingOrSelfPermission(getWritePermission())
123 == PackageManager.PERMISSION_GRANTED,
124 window);
125 }
126
127 public Cursor query(Uri uri, String[] projection,
128 String selection, String[] selectionArgs, String sortOrder) {
129 checkReadPermission(uri);
130 return ContentProvider.this.query(uri, projection, selection,
131 selectionArgs, sortOrder);
132 }
133
Fred Quintana6a8d5332009-05-07 17:35:38 -0700134 public EntityIterator queryEntities(Uri uri, String selection, String[] selectionArgs,
135 String sortOrder) {
136 checkReadPermission(uri);
137 return ContentProvider.this.queryEntities(uri, selection, selectionArgs, sortOrder);
138 }
139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 public String getType(Uri uri) {
141 return ContentProvider.this.getType(uri);
142 }
143
144
145 public Uri insert(Uri uri, ContentValues initialValues) {
146 checkWritePermission(uri);
147 return ContentProvider.this.insert(uri, initialValues);
148 }
149
150 public int bulkInsert(Uri uri, ContentValues[] initialValues) {
151 checkWritePermission(uri);
152 return ContentProvider.this.bulkInsert(uri, initialValues);
153 }
154
Fred Quintana89437372009-05-15 15:10:40 -0700155 public Uri insertEntity(Uri uri, Entity entities) {
Fred Quintana6a8d5332009-05-07 17:35:38 -0700156 checkWritePermission(uri);
Fred Quintana89437372009-05-15 15:10:40 -0700157 return ContentProvider.this.insertEntity(uri, entities);
158 }
159
Fred Quintana03d94902009-05-22 14:23:31 -0700160 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
Fred Quintana89437372009-05-15 15:10:40 -0700161 throws OperationApplicationException {
162 for (ContentProviderOperation operation : operations) {
163 if (operation.isReadOperation()) {
164 checkReadPermission(operation.getUri());
165 }
166
167 if (operation.isWriteOperation()) {
168 checkWritePermission(operation.getUri());
169 }
170 }
171 return ContentProvider.this.applyBatch(operations);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700172 }
173
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 public int delete(Uri uri, String selection, String[] selectionArgs) {
175 checkWritePermission(uri);
176 return ContentProvider.this.delete(uri, selection, selectionArgs);
177 }
178
179 public int update(Uri uri, ContentValues values, String selection,
180 String[] selectionArgs) {
181 checkWritePermission(uri);
182 return ContentProvider.this.update(uri, values, selection, selectionArgs);
183 }
184
Fred Quintana89437372009-05-15 15:10:40 -0700185 public int updateEntity(Uri uri, Entity entity) {
Fred Quintana6a8d5332009-05-07 17:35:38 -0700186 checkWritePermission(uri);
Fred Quintana89437372009-05-15 15:10:40 -0700187 return ContentProvider.this.updateEntity(uri, entity);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700188 }
189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 public ParcelFileDescriptor openFile(Uri uri, String mode)
191 throws FileNotFoundException {
192 if (mode != null && mode.startsWith("rw")) checkWritePermission(uri);
193 else checkReadPermission(uri);
194 return ContentProvider.this.openFile(uri, mode);
195 }
196
197 public AssetFileDescriptor openAssetFile(Uri uri, String mode)
198 throws FileNotFoundException {
199 if (mode != null && mode.startsWith("rw")) checkWritePermission(uri);
200 else checkReadPermission(uri);
201 return ContentProvider.this.openAssetFile(uri, mode);
202 }
203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 private void checkReadPermission(Uri uri) {
205 final String rperm = getReadPermission();
206 final int pid = Binder.getCallingPid();
207 final int uid = Binder.getCallingUid();
208 if (getContext().checkUriPermission(uri, rperm, null, pid, uid,
209 Intent.FLAG_GRANT_READ_URI_PERMISSION)
210 == PackageManager.PERMISSION_GRANTED) {
211 return;
212 }
213 String msg = "Permission Denial: reading "
214 + ContentProvider.this.getClass().getName()
215 + " uri " + uri + " from pid=" + Binder.getCallingPid()
216 + ", uid=" + Binder.getCallingUid()
217 + " requires " + rperm;
218 throw new SecurityException(msg);
219 }
220
221 private void checkWritePermission(Uri uri) {
222 final String wperm = getWritePermission();
223 final int pid = Binder.getCallingPid();
224 final int uid = Binder.getCallingUid();
225 if (getContext().checkUriPermission(uri, null, wperm, pid, uid,
226 Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
227 == PackageManager.PERMISSION_GRANTED) {
228 return;
229 }
230 String msg = "Permission Denial: writing "
231 + ContentProvider.this.getClass().getName()
232 + " uri " + uri + " from pid=" + Binder.getCallingPid()
233 + ", uid=" + Binder.getCallingUid()
234 + " requires " + wperm;
235 throw new SecurityException(msg);
236 }
237 }
238
239
240 /**
241 * Retrieve the Context this provider is running in. Only available once
242 * onCreate(Map icicle) has been called -- this will be null in the
243 * constructor.
244 */
245 public final Context getContext() {
246 return mContext;
247 }
248
249 /**
250 * Change the permission required to read data from the content
251 * provider. This is normally set for you from its manifest information
252 * when the provider is first created.
253 *
254 * @param permission Name of the permission required for read-only access.
255 */
256 protected final void setReadPermission(String permission) {
257 mReadPermission = permission;
258 }
259
260 /**
261 * Return the name of the permission required for read-only access to
262 * this content provider. This method can be called from multiple
263 * threads, as described in
264 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
265 * Processes and Threads</a>.
266 */
267 public final String getReadPermission() {
268 return mReadPermission;
269 }
270
271 /**
272 * Change the permission required to read and write data in the content
273 * provider. This is normally set for you from its manifest information
274 * when the provider is first created.
275 *
276 * @param permission Name of the permission required for read/write access.
277 */
278 protected final void setWritePermission(String permission) {
279 mWritePermission = permission;
280 }
281
282 /**
283 * Return the name of the permission required for read/write access to
284 * this content provider. This method can be called from multiple
285 * threads, as described in
286 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
287 * Processes and Threads</a>.
288 */
289 public final String getWritePermission() {
290 return mWritePermission;
291 }
292
293 /**
294 * Called when the provider is being started.
295 *
296 * @return true if the provider was successfully loaded, false otherwise
297 */
298 public abstract boolean onCreate();
299
300 public void onConfigurationChanged(Configuration newConfig) {
301 }
302
303 public void onLowMemory() {
304 }
305
306 /**
307 * Receives a query request from a client in a local process, and
308 * returns a Cursor. This is called internally by the {@link ContentResolver}.
309 * This method can be called from multiple
310 * threads, as described in
311 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
312 * Processes and Threads</a>.
313 * <p>
314 * Example client call:<p>
315 * <pre>// Request a specific record.
316 * Cursor managedCursor = managedQuery(
317 Contacts.People.CONTENT_URI.addId(2),
318 projection, // Which columns to return.
319 null, // WHERE clause.
320 People.NAME + " ASC"); // Sort order.</pre>
321 * Example implementation:<p>
322 * <pre>// SQLiteQueryBuilder is a helper class that creates the
323 // proper SQL syntax for us.
324 SQLiteQueryBuilder qBuilder = new SQLiteQueryBuilder();
325
326 // Set the table we're querying.
327 qBuilder.setTables(DATABASE_TABLE_NAME);
328
329 // If the query ends in a specific record number, we're
330 // being asked for a specific record, so set the
331 // WHERE clause in our query.
332 if((URI_MATCHER.match(uri)) == SPECIFIC_MESSAGE){
333 qBuilder.appendWhere("_id=" + uri.getPathLeafId());
334 }
335
336 // Make the query.
337 Cursor c = qBuilder.query(mDb,
338 projection,
339 selection,
340 selectionArgs,
341 groupBy,
342 having,
343 sortOrder);
344 c.setNotificationUri(getContext().getContentResolver(), uri);
345 return c;</pre>
346 *
347 * @param uri The URI to query. This will be the full URI sent by the client;
348 * if the client is requesting a specific record, the URI will end in a record number
349 * that the implementation should parse and add to a WHERE or HAVING clause, specifying
350 * that _id value.
351 * @param projection The list of columns to put into the cursor. If
352 * null all columns are included.
353 * @param selection A selection criteria to apply when filtering rows.
354 * If null then all rows are included.
355 * @param sortOrder How the rows in the cursor should be sorted.
356 * If null then the provider is free to define the sort order.
357 * @return a Cursor or null.
358 */
359 public abstract Cursor query(Uri uri, String[] projection,
360 String selection, String[] selectionArgs, String sortOrder);
361
Fred Quintana6a8d5332009-05-07 17:35:38 -0700362 public EntityIterator queryEntities(Uri uri, String selection, String[] selectionArgs,
363 String sortOrder) {
364 throw new UnsupportedOperationException();
365 }
366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800367 /**
368 * Return the MIME type of the data at the given URI. This should start with
369 * <code>vnd.android.cursor.item</code> for a single record,
370 * or <code>vnd.android.cursor.dir/</code> for multiple items.
371 * This method can be called from multiple
372 * threads, as described in
373 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
374 * Processes and Threads</a>.
375 *
376 * @param uri the URI to query.
377 * @return a MIME type string, or null if there is no type.
378 */
379 public abstract String getType(Uri uri);
380
381 /**
382 * Implement this to insert a new row.
383 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
384 * after inserting.
385 * This method can be called from multiple
386 * threads, as described in
387 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
388 * Processes and Threads</a>.
389 * @param uri The content:// URI of the insertion request.
390 * @param values A set of column_name/value pairs to add to the database.
391 * @return The URI for the newly inserted item.
392 */
393 public abstract Uri insert(Uri uri, ContentValues values);
394
395 /**
396 * Implement this to insert a set of new rows, or the default implementation will
397 * iterate over the values and call {@link #insert} on each of them.
398 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
399 * after inserting.
400 * This method can be called from multiple
401 * threads, as described in
402 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
403 * Processes and Threads</a>.
404 *
405 * @param uri The content:// URI of the insertion request.
406 * @param values An array of sets of column_name/value pairs to add to the database.
407 * @return The number of values that were inserted.
408 */
409 public int bulkInsert(Uri uri, ContentValues[] values) {
410 int numValues = values.length;
411 for (int i = 0; i < numValues; i++) {
412 insert(uri, values[i]);
413 }
414 return numValues;
415 }
416
Fred Quintana6a8d5332009-05-07 17:35:38 -0700417 public Uri insertEntity(Uri uri, Entity entity) {
418 throw new UnsupportedOperationException();
419 }
420
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800421 /**
422 * A request to delete one or more rows. The selection clause is applied when performing
423 * the deletion, allowing the operation to affect multiple rows in a
424 * directory.
425 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyDelete()}
426 * after deleting.
427 * This method can be called from multiple
428 * threads, as described in
429 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
430 * Processes and Threads</a>.
431 *
432 * <p>The implementation is responsible for parsing out a row ID at the end
433 * of the URI, if a specific row is being deleted. That is, the client would
434 * pass in <code>content://contacts/people/22</code> and the implementation is
435 * responsible for parsing the record number (22) when creating a SQL statement.
436 *
437 * @param uri The full URI to query, including a row ID (if a specific record is requested).
438 * @param selection An optional restriction to apply to rows when deleting.
439 * @return The number of rows affected.
440 * @throws SQLException
441 */
442 public abstract int delete(Uri uri, String selection, String[] selectionArgs);
443
444 /**
445 * Update a content URI. All rows matching the optionally provided selection
446 * will have their columns listed as the keys in the values map with the
447 * values of those keys.
448 * As a courtesy, call {@link ContentResolver#notifyChange(android.net.Uri ,android.database.ContentObserver) notifyChange()}
449 * after updating.
450 * This method can be called from multiple
451 * threads, as described in
452 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
453 * Processes and Threads</a>.
454 *
455 * @param uri The URI to query. This can potentially have a record ID if this
456 * is an update request for a specific record.
457 * @param values A Bundle mapping from column names to new column values (NULL is a
458 * valid value).
459 * @param selection An optional filter to match rows to update.
460 * @return the number of rows affected.
461 */
462 public abstract int update(Uri uri, ContentValues values, String selection,
463 String[] selectionArgs);
464
Fred Quintana6a8d5332009-05-07 17:35:38 -0700465 public int updateEntity(Uri uri, Entity entity) {
466 throw new UnsupportedOperationException();
467 }
468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 /**
470 * Open a file blob associated with a content URI.
471 * This method can be called from multiple
472 * threads, as described in
473 * <a href="{@docRoot}guide/topics/fundamentals.html#procthread">Application Fundamentals:
474 * Processes and Threads</a>.
475 *
476 * <p>Returns a
477 * ParcelFileDescriptor, from which you can obtain a
478 * {@link java.io.FileDescriptor} for use with
479 * {@link java.io.FileInputStream}, {@link java.io.FileOutputStream}, etc.
480 * This can be used to store large data (such as an image) associated with
481 * a particular piece of content.
482 *
483 * <p>The returned ParcelFileDescriptor is owned by the caller, so it is
484 * their responsibility to close it when done. That is, the implementation
485 * of this method should create a new ParcelFileDescriptor for each call.
486 *
487 * @param uri The URI whose file is to be opened.
488 * @param mode Access mode for the file. May be "r" for read-only access,
489 * "rw" for read and write access, or "rwt" for read and write access
490 * that truncates any existing file.
491 *
492 * @return Returns a new ParcelFileDescriptor which you can use to access
493 * the file.
494 *
495 * @throws FileNotFoundException Throws FileNotFoundException if there is
496 * no file associated with the given URI or the mode is invalid.
497 * @throws SecurityException Throws SecurityException if the caller does
498 * not have permission to access the file.
499 *
500 * @see #openAssetFile(Uri, String)
501 * @see #openFileHelper(Uri, String)
502 */
503 public ParcelFileDescriptor openFile(Uri uri, String mode)
504 throws FileNotFoundException {
505 throw new FileNotFoundException("No files supported by provider at "
506 + uri);
507 }
508
509 /**
510 * This is like {@link #openFile}, but can be implemented by providers
511 * that need to be able to return sub-sections of files, often assets
512 * inside of their .apk. Note that when implementing this your clients
513 * must be able to deal with such files, either directly with
514 * {@link ContentResolver#openAssetFileDescriptor
515 * ContentResolver.openAssetFileDescriptor}, or by using the higher-level
516 * {@link ContentResolver#openInputStream ContentResolver.openInputStream}
517 * or {@link ContentResolver#openOutputStream ContentResolver.openOutputStream}
518 * methods.
519 *
520 * <p><em>Note: if you are implementing this to return a full file, you
521 * should create the AssetFileDescriptor with
522 * {@link AssetFileDescriptor#UNKNOWN_LENGTH} to be compatible with
523 * applications that can not handle sub-sections of files.</em></p>
524 *
525 * @param uri The URI whose file is to be opened.
526 * @param mode Access mode for the file. May be "r" for read-only access,
527 * "w" for write-only access (erasing whatever data is currently in
528 * the file), "wa" for write-only access to append to any existing data,
529 * "rw" for read and write access on any existing data, and "rwt" for read
530 * and write access that truncates any existing file.
531 *
532 * @return Returns a new AssetFileDescriptor which you can use to access
533 * the file.
534 *
535 * @throws FileNotFoundException Throws FileNotFoundException if there is
536 * no file associated with the given URI or the mode is invalid.
537 * @throws SecurityException Throws SecurityException if the caller does
538 * not have permission to access the file.
539 *
540 * @see #openFile(Uri, String)
541 * @see #openFileHelper(Uri, String)
542 */
543 public AssetFileDescriptor openAssetFile(Uri uri, String mode)
544 throws FileNotFoundException {
545 ParcelFileDescriptor fd = openFile(uri, mode);
546 return fd != null ? new AssetFileDescriptor(fd, 0, -1) : null;
547 }
548
549 /**
550 * Convenience for subclasses that wish to implement {@link #openFile}
551 * by looking up a column named "_data" at the given URI.
552 *
553 * @param uri The URI to be opened.
554 * @param mode The file mode. May be "r" for read-only access,
555 * "w" for write-only access (erasing whatever data is currently in
556 * the file), "wa" for write-only access to append to any existing data,
557 * "rw" for read and write access on any existing data, and "rwt" for read
558 * and write access that truncates any existing file.
559 *
560 * @return Returns a new ParcelFileDescriptor that can be used by the
561 * client to access the file.
562 */
563 protected final ParcelFileDescriptor openFileHelper(Uri uri,
564 String mode) throws FileNotFoundException {
565 Cursor c = query(uri, new String[]{"_data"}, null, null, null);
566 int count = (c != null) ? c.getCount() : 0;
567 if (count != 1) {
568 // If there is not exactly one result, throw an appropriate
569 // exception.
570 if (c != null) {
571 c.close();
572 }
573 if (count == 0) {
574 throw new FileNotFoundException("No entry for " + uri);
575 }
576 throw new FileNotFoundException("Multiple items at " + uri);
577 }
578
579 c.moveToFirst();
580 int i = c.getColumnIndex("_data");
581 String path = (i >= 0 ? c.getString(i) : null);
582 c.close();
583 if (path == null) {
584 throw new FileNotFoundException("Column _data not found.");
585 }
586
587 int modeBits = ContentResolver.modeToMode(uri, mode);
588 return ParcelFileDescriptor.open(new File(path), modeBits);
589 }
590
591 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800592 * Returns true if this instance is a temporary content provider.
593 * @return true if this instance is a temporary content provider
594 */
595 protected boolean isTemporary() {
596 return false;
597 }
598
599 /**
600 * Returns the Binder object for this provider.
601 *
602 * @return the Binder object for this provider
603 * @hide
604 */
605 public IContentProvider getIContentProvider() {
606 return mTransport;
607 }
608
609 /**
610 * After being instantiated, this is called to tell the content provider
611 * about itself.
612 *
613 * @param context The context this provider is running in
614 * @param info Registered information about this content provider
615 */
616 public void attachInfo(Context context, ProviderInfo info) {
617
618 /*
619 * Only allow it to be set once, so after the content service gives
620 * this to us clients can't change it.
621 */
622 if (mContext == null) {
623 mContext = context;
624 if (info != null) {
625 setReadPermission(info.readPermission);
626 setWritePermission(info.writePermission);
627 }
628 ContentProvider.this.onCreate();
629 }
630 }
Fred Quintanace31b232009-05-04 16:01:15 -0700631
632 /**
633 * Applies each of the {@link ContentProviderOperation} objects and returns an array
634 * of their results. Passes through OperationApplicationException, which may be thrown
635 * by the call to {@link ContentProviderOperation#apply}.
636 * If all the applications succeed then a {@link ContentProviderResult} array with the
637 * same number of elements as the operations will be returned. It is implementation-specific
638 * how many, if any, operations will have been successfully applied if a call to
639 * apply results in a {@link OperationApplicationException}.
640 * @param operations the operations to apply
641 * @return the results of the applications
642 * @throws OperationApplicationException thrown if an application fails.
643 * See {@link ContentProviderOperation#apply} for more information.
644 */
Fred Quintana03d94902009-05-22 14:23:31 -0700645 public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
Fred Quintanace31b232009-05-04 16:01:15 -0700646 throws OperationApplicationException {
Fred Quintana03d94902009-05-22 14:23:31 -0700647 final int numOperations = operations.size();
648 final ContentProviderResult[] results = new ContentProviderResult[numOperations];
649 for (int i = 0; i < numOperations; i++) {
650 results[i] = operations.get(i).apply(this, results, i);
Fred Quintanace31b232009-05-04 16:01:15 -0700651 }
652 return results;
653 }
654}