blob: 4769bd02a5dc5bd07147314ad5bac492befb289b [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.res.AssetFileDescriptor;
Jeff Brownfb5a4962012-03-14 17:38:59 -070020import android.database.BulkCursorDescriptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.database.BulkCursorToCursorAdaptor;
22import android.database.Cursor;
Jeff Brownd2183652011-10-09 12:39:53 -070023import android.database.CursorToBulkCursorAdaptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.database.DatabaseUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.database.IContentObserver;
26import android.net.Uri;
27import android.os.Binder;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080028import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080029import android.os.IBinder;
Jeff Browna7771df2012-05-07 20:06:46 -070030import android.os.ICancellationSignal;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.Parcel;
32import android.os.ParcelFileDescriptor;
33import android.os.Parcelable;
Jeff Sharkeybd3b9022013-08-20 15:20:04 -070034import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035
36import java.io.FileNotFoundException;
Fred Quintana03d94902009-05-22 14:23:31 -070037import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
39/**
40 * {@hide}
41 */
42abstract public class ContentProviderNative extends Binder implements IContentProvider {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 public ContentProviderNative()
44 {
45 attachInterface(this, descriptor);
46 }
47
48 /**
49 * Cast a Binder object into a content resolver interface, generating
50 * a proxy if needed.
51 */
52 static public IContentProvider asInterface(IBinder obj)
53 {
54 if (obj == null) {
55 return null;
56 }
57 IContentProvider in =
58 (IContentProvider)obj.queryLocalInterface(descriptor);
59 if (in != null) {
60 return in;
61 }
62
63 return new ContentProviderProxy(obj);
64 }
65
Jeff Brownd2183652011-10-09 12:39:53 -070066 /**
67 * Gets the name of the content provider.
68 * Should probably be part of the {@link IContentProvider} interface.
69 * @return The content provider name.
70 */
71 public abstract String getProviderName();
72
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 @Override
74 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
75 throws RemoteException {
76 try {
77 switch (code) {
78 case QUERY_TRANSACTION:
79 {
80 data.enforceInterface(IContentProvider.descriptor);
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -080081
Dianne Hackborn35654b62013-01-14 17:38:02 -080082 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080083 Uri url = Uri.CREATOR.createFromParcel(data);
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -080084
85 // String[] projection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 int num = data.readInt();
87 String[] projection = null;
88 if (num > 0) {
89 projection = new String[num];
90 for (int i = 0; i < num; i++) {
91 projection[i] = data.readString();
92 }
93 }
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -080094
95 // String selection, String[] selectionArgs...
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080096 String selection = data.readString();
97 num = data.readInt();
98 String[] selectionArgs = null;
99 if (num > 0) {
100 selectionArgs = new String[num];
101 for (int i = 0; i < num; i++) {
102 selectionArgs[i] = data.readString();
103 }
104 }
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -0800105
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 String sortOrder = data.readString();
Jeff Brownd2183652011-10-09 12:39:53 -0700107 IContentObserver observer = IContentObserver.Stub.asInterface(
108 data.readStrongBinder());
Jeff Brown4c1241d2012-02-02 17:05:00 -0800109 ICancellationSignal cancellationSignal = ICancellationSignal.Stub.asInterface(
Jeff Brown75ea64f2012-01-25 19:37:13 -0800110 data.readStrongBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111
Dianne Hackborn35654b62013-01-14 17:38:02 -0800112 Cursor cursor = query(callingPkg, url, projection, selection, selectionArgs,
113 sortOrder, cancellationSignal);
Jeff Brownd2183652011-10-09 12:39:53 -0700114 if (cursor != null) {
Peter Eliasson55eda432013-06-28 13:55:41 +0200115 CursorToBulkCursorAdaptor adaptor = null;
116
Jeff Brownc21b5a02013-01-07 17:15:12 -0800117 try {
Peter Eliasson55eda432013-06-28 13:55:41 +0200118 adaptor = new CursorToBulkCursorAdaptor(cursor, observer,
119 getProviderName());
Jeff Brownc21b5a02013-01-07 17:15:12 -0800120 cursor = null;
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -0800121
Peter Eliasson55eda432013-06-28 13:55:41 +0200122 BulkCursorDescriptor d = adaptor.getBulkCursorDescriptor();
123 adaptor = null;
124
Jeff Brownc21b5a02013-01-07 17:15:12 -0800125 reply.writeNoException();
126 reply.writeInt(1);
127 d.writeToParcel(reply, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
128 } finally {
129 // Close cursor if an exception was thrown while constructing the adaptor.
Peter Eliasson55eda432013-06-28 13:55:41 +0200130 if (adaptor != null) {
131 adaptor.close();
132 }
Jeff Brownc21b5a02013-01-07 17:15:12 -0800133 if (cursor != null) {
134 cursor.close();
135 }
136 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 } else {
Fabrice Di Meglioeca53642010-12-01 20:24:40 -0800138 reply.writeNoException();
Jeff Brownfb5a4962012-03-14 17:38:59 -0700139 reply.writeInt(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 }
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -0800141
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800142 return true;
143 }
144
145 case GET_TYPE_TRANSACTION:
146 {
147 data.enforceInterface(IContentProvider.descriptor);
148 Uri url = Uri.CREATOR.createFromParcel(data);
149 String type = getType(url);
150 reply.writeNoException();
151 reply.writeString(type);
152
153 return true;
154 }
155
156 case INSERT_TRANSACTION:
157 {
158 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800159 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 Uri url = Uri.CREATOR.createFromParcel(data);
161 ContentValues values = ContentValues.CREATOR.createFromParcel(data);
162
Dianne Hackborn35654b62013-01-14 17:38:02 -0800163 Uri out = insert(callingPkg, url, values);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 reply.writeNoException();
165 Uri.writeToParcel(reply, out);
166 return true;
167 }
168
169 case BULK_INSERT_TRANSACTION:
170 {
171 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800172 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800173 Uri url = Uri.CREATOR.createFromParcel(data);
174 ContentValues[] values = data.createTypedArray(ContentValues.CREATOR);
175
Dianne Hackborn35654b62013-01-14 17:38:02 -0800176 int count = bulkInsert(callingPkg, url, values);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 reply.writeNoException();
178 reply.writeInt(count);
179 return true;
180 }
181
Fred Quintana89437372009-05-15 15:10:40 -0700182 case APPLY_BATCH_TRANSACTION:
183 {
184 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800185 String callingPkg = data.readString();
Fred Quintana03d94902009-05-22 14:23:31 -0700186 final int numOperations = data.readInt();
187 final ArrayList<ContentProviderOperation> operations =
188 new ArrayList<ContentProviderOperation>(numOperations);
189 for (int i = 0; i < numOperations; i++) {
190 operations.add(i, ContentProviderOperation.CREATOR.createFromParcel(data));
191 }
Dianne Hackborn35654b62013-01-14 17:38:02 -0800192 final ContentProviderResult[] results = applyBatch(callingPkg, operations);
Fred Quintana89437372009-05-15 15:10:40 -0700193 reply.writeNoException();
194 reply.writeTypedArray(results, 0);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700195 return true;
196 }
197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 case DELETE_TRANSACTION:
199 {
200 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800201 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 Uri url = Uri.CREATOR.createFromParcel(data);
203 String selection = data.readString();
204 String[] selectionArgs = data.readStringArray();
205
Dianne Hackborn35654b62013-01-14 17:38:02 -0800206 int count = delete(callingPkg, url, selection, selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207
208 reply.writeNoException();
209 reply.writeInt(count);
210 return true;
211 }
212
213 case UPDATE_TRANSACTION:
214 {
215 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800216 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 Uri url = Uri.CREATOR.createFromParcel(data);
218 ContentValues values = ContentValues.CREATOR.createFromParcel(data);
219 String selection = data.readString();
220 String[] selectionArgs = data.readStringArray();
221
Dianne Hackborn35654b62013-01-14 17:38:02 -0800222 int count = update(callingPkg, url, values, selection, selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223
224 reply.writeNoException();
225 reply.writeInt(count);
226 return true;
227 }
228
229 case OPEN_FILE_TRANSACTION:
230 {
231 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800232 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 Uri url = Uri.CREATOR.createFromParcel(data);
234 String mode = data.readString();
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700235 ICancellationSignal signal = ICancellationSignal.Stub.asInterface(
236 data.readStrongBinder());
Dianne Hackbornff170242014-11-19 10:59:01 -0800237 IBinder callerToken = data.readStrongBinder();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238
239 ParcelFileDescriptor fd;
Dianne Hackbornff170242014-11-19 10:59:01 -0800240 fd = openFile(callingPkg, url, mode, signal, callerToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 reply.writeNoException();
242 if (fd != null) {
243 reply.writeInt(1);
244 fd.writeToParcel(reply,
245 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
246 } else {
247 reply.writeInt(0);
248 }
249 return true;
250 }
251
252 case OPEN_ASSET_FILE_TRANSACTION:
253 {
254 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800255 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 Uri url = Uri.CREATOR.createFromParcel(data);
257 String mode = data.readString();
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700258 ICancellationSignal signal = ICancellationSignal.Stub.asInterface(
259 data.readStrongBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800260
261 AssetFileDescriptor fd;
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700262 fd = openAssetFile(callingPkg, url, mode, signal);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800263 reply.writeNoException();
264 if (fd != null) {
265 reply.writeInt(1);
266 fd.writeToParcel(reply,
267 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
268 } else {
269 reply.writeInt(0);
270 }
271 return true;
272 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800273
274 case CALL_TRANSACTION:
275 {
276 data.enforceInterface(IContentProvider.descriptor);
277
Dianne Hackborn35654b62013-01-14 17:38:02 -0800278 String callingPkg = data.readString();
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800279 String method = data.readString();
280 String stringArg = data.readString();
281 Bundle args = data.readBundle();
282
Dianne Hackborn35654b62013-01-14 17:38:02 -0800283 Bundle responseBundle = call(callingPkg, method, stringArg, args);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800284
285 reply.writeNoException();
286 reply.writeBundle(responseBundle);
287 return true;
288 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700289
290 case GET_STREAM_TYPES_TRANSACTION:
291 {
292 data.enforceInterface(IContentProvider.descriptor);
293 Uri url = Uri.CREATOR.createFromParcel(data);
294 String mimeTypeFilter = data.readString();
295 String[] types = getStreamTypes(url, mimeTypeFilter);
296 reply.writeNoException();
297 reply.writeStringArray(types);
298
299 return true;
300 }
301
302 case OPEN_TYPED_ASSET_FILE_TRANSACTION:
303 {
304 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800305 String callingPkg = data.readString();
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700306 Uri url = Uri.CREATOR.createFromParcel(data);
307 String mimeType = data.readString();
308 Bundle opts = data.readBundle();
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700309 ICancellationSignal signal = ICancellationSignal.Stub.asInterface(
310 data.readStrongBinder());
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700311
312 AssetFileDescriptor fd;
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700313 fd = openTypedAssetFile(callingPkg, url, mimeType, opts, signal);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700314 reply.writeNoException();
315 if (fd != null) {
316 reply.writeInt(1);
317 fd.writeToParcel(reply,
318 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
319 } else {
320 reply.writeInt(0);
321 }
322 return true;
323 }
Jeff Brown75ea64f2012-01-25 19:37:13 -0800324
325 case CREATE_CANCELATION_SIGNAL_TRANSACTION:
326 {
327 data.enforceInterface(IContentProvider.descriptor);
328
Jeff Brown4c1241d2012-02-02 17:05:00 -0800329 ICancellationSignal cancellationSignal = createCancellationSignal();
Jeff Brown75ea64f2012-01-25 19:37:13 -0800330 reply.writeNoException();
Jeff Brown4c1241d2012-02-02 17:05:00 -0800331 reply.writeStrongBinder(cancellationSignal.asBinder());
Jeff Brown75ea64f2012-01-25 19:37:13 -0800332 return true;
333 }
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700334
335 case CANONICALIZE_TRANSACTION:
336 {
337 data.enforceInterface(IContentProvider.descriptor);
338 String callingPkg = data.readString();
339 Uri url = Uri.CREATOR.createFromParcel(data);
340
341 Uri out = canonicalize(callingPkg, url);
342 reply.writeNoException();
343 Uri.writeToParcel(reply, out);
344 return true;
345 }
346
347 case UNCANONICALIZE_TRANSACTION:
348 {
349 data.enforceInterface(IContentProvider.descriptor);
350 String callingPkg = data.readString();
351 Uri url = Uri.CREATOR.createFromParcel(data);
352
353 Uri out = uncanonicalize(callingPkg, url);
354 reply.writeNoException();
355 Uri.writeToParcel(reply, out);
356 return true;
357 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800358 }
359 } catch (Exception e) {
360 DatabaseUtils.writeExceptionToParcel(reply, e);
361 return true;
362 }
363
364 return super.onTransact(code, data, reply, flags);
365 }
366
367 public IBinder asBinder()
368 {
369 return this;
370 }
371}
372
373
374final class ContentProviderProxy implements IContentProvider
375{
376 public ContentProviderProxy(IBinder remote)
377 {
378 mRemote = remote;
379 }
380
381 public IBinder asBinder()
382 {
383 return mRemote;
384 }
385
Dianne Hackborn35654b62013-01-14 17:38:02 -0800386 public Cursor query(String callingPkg, Uri url, String[] projection, String selection,
Jeff Brown4c1241d2012-02-02 17:05:00 -0800387 String[] selectionArgs, String sortOrder, ICancellationSignal cancellationSignal)
Jeff Brown75ea64f2012-01-25 19:37:13 -0800388 throws RemoteException {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700389 BulkCursorToCursorAdaptor adaptor = new BulkCursorToCursorAdaptor();
390 Parcel data = Parcel.obtain();
391 Parcel reply = Parcel.obtain();
Jeff Brownd2183652011-10-09 12:39:53 -0700392 try {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700393 data.writeInterfaceToken(IContentProvider.descriptor);
Jeff Brownd2183652011-10-09 12:39:53 -0700394
Dianne Hackborn35654b62013-01-14 17:38:02 -0800395 data.writeString(callingPkg);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700396 url.writeToParcel(data, 0);
397 int length = 0;
398 if (projection != null) {
399 length = projection.length;
Jeff Brownd2183652011-10-09 12:39:53 -0700400 }
Jeff Brown0cde89f2011-10-10 14:50:10 -0700401 data.writeInt(length);
402 for (int i = 0; i < length; i++) {
403 data.writeString(projection[i]);
404 }
405 data.writeString(selection);
406 if (selectionArgs != null) {
407 length = selectionArgs.length;
408 } else {
409 length = 0;
410 }
411 data.writeInt(length);
412 for (int i = 0; i < length; i++) {
413 data.writeString(selectionArgs[i]);
414 }
415 data.writeString(sortOrder);
416 data.writeStrongBinder(adaptor.getObserver().asBinder());
Jeff Brown4c1241d2012-02-02 17:05:00 -0800417 data.writeStrongBinder(cancellationSignal != null ? cancellationSignal.asBinder() : null);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700418
419 mRemote.transact(IContentProvider.QUERY_TRANSACTION, data, reply, 0);
420
421 DatabaseUtils.readExceptionFromParcel(reply);
422
Jeff Brownfb5a4962012-03-14 17:38:59 -0700423 if (reply.readInt() != 0) {
424 BulkCursorDescriptor d = BulkCursorDescriptor.CREATOR.createFromParcel(reply);
425 adaptor.initialize(d);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700426 } else {
427 adaptor.close();
428 adaptor = null;
429 }
430 return adaptor;
431 } catch (RemoteException ex) {
432 adaptor.close();
433 throw ex;
434 } catch (RuntimeException ex) {
435 adaptor.close();
436 throw ex;
Jeff Brownd2183652011-10-09 12:39:53 -0700437 } finally {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700438 data.recycle();
439 reply.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800440 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800441 }
442
443 public String getType(Uri url) throws RemoteException
444 {
445 Parcel data = Parcel.obtain();
446 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700447 try {
448 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800449
Jeff Browndf6611d2011-10-09 12:28:54 -0700450 url.writeToParcel(data, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800451
Jeff Browndf6611d2011-10-09 12:28:54 -0700452 mRemote.transact(IContentProvider.GET_TYPE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453
Jeff Browndf6611d2011-10-09 12:28:54 -0700454 DatabaseUtils.readExceptionFromParcel(reply);
455 String out = reply.readString();
456 return out;
457 } finally {
458 data.recycle();
459 reply.recycle();
460 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800461 }
462
Dianne Hackborn35654b62013-01-14 17:38:02 -0800463 public Uri insert(String callingPkg, Uri url, ContentValues values) throws RemoteException
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800464 {
465 Parcel data = Parcel.obtain();
466 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700467 try {
468 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469
Dianne Hackborn35654b62013-01-14 17:38:02 -0800470 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700471 url.writeToParcel(data, 0);
472 values.writeToParcel(data, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800473
Jeff Browndf6611d2011-10-09 12:28:54 -0700474 mRemote.transact(IContentProvider.INSERT_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800475
Jeff Browndf6611d2011-10-09 12:28:54 -0700476 DatabaseUtils.readExceptionFromParcel(reply);
477 Uri out = Uri.CREATOR.createFromParcel(reply);
478 return out;
479 } finally {
480 data.recycle();
481 reply.recycle();
482 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800483 }
484
Dianne Hackborn35654b62013-01-14 17:38:02 -0800485 public int bulkInsert(String callingPkg, Uri url, ContentValues[] values) throws RemoteException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 Parcel data = Parcel.obtain();
487 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700488 try {
489 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490
Dianne Hackborn35654b62013-01-14 17:38:02 -0800491 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700492 url.writeToParcel(data, 0);
493 data.writeTypedArray(values, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494
Jeff Browndf6611d2011-10-09 12:28:54 -0700495 mRemote.transact(IContentProvider.BULK_INSERT_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496
Jeff Browndf6611d2011-10-09 12:28:54 -0700497 DatabaseUtils.readExceptionFromParcel(reply);
498 int count = reply.readInt();
499 return count;
500 } finally {
501 data.recycle();
502 reply.recycle();
503 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 }
505
Dianne Hackborn35654b62013-01-14 17:38:02 -0800506 public ContentProviderResult[] applyBatch(String callingPkg,
507 ArrayList<ContentProviderOperation> operations)
508 throws RemoteException, OperationApplicationException {
Fred Quintana6a8d5332009-05-07 17:35:38 -0700509 Parcel data = Parcel.obtain();
510 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700511 try {
512 data.writeInterfaceToken(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800513 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700514 data.writeInt(operations.size());
515 for (ContentProviderOperation operation : operations) {
516 operation.writeToParcel(data, 0);
517 }
518 mRemote.transact(IContentProvider.APPLY_BATCH_TRANSACTION, data, reply, 0);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700519
Jeff Browndf6611d2011-10-09 12:28:54 -0700520 DatabaseUtils.readExceptionWithOperationApplicationExceptionFromParcel(reply);
521 final ContentProviderResult[] results =
522 reply.createTypedArray(ContentProviderResult.CREATOR);
523 return results;
524 } finally {
525 data.recycle();
526 reply.recycle();
Fred Quintana03d94902009-05-22 14:23:31 -0700527 }
Fred Quintana6a8d5332009-05-07 17:35:38 -0700528 }
529
Dianne Hackborn35654b62013-01-14 17:38:02 -0800530 public int delete(String callingPkg, Uri url, String selection, String[] selectionArgs)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800531 throws RemoteException {
532 Parcel data = Parcel.obtain();
533 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700534 try {
535 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536
Dianne Hackborn35654b62013-01-14 17:38:02 -0800537 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700538 url.writeToParcel(data, 0);
539 data.writeString(selection);
540 data.writeStringArray(selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800541
Jeff Browndf6611d2011-10-09 12:28:54 -0700542 mRemote.transact(IContentProvider.DELETE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800543
Jeff Browndf6611d2011-10-09 12:28:54 -0700544 DatabaseUtils.readExceptionFromParcel(reply);
545 int count = reply.readInt();
546 return count;
547 } finally {
548 data.recycle();
549 reply.recycle();
550 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800551 }
552
Dianne Hackborn35654b62013-01-14 17:38:02 -0800553 public int update(String callingPkg, Uri url, ContentValues values, String selection,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800554 String[] selectionArgs) throws RemoteException {
555 Parcel data = Parcel.obtain();
556 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700557 try {
558 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800559
Dianne Hackborn35654b62013-01-14 17:38:02 -0800560 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700561 url.writeToParcel(data, 0);
562 values.writeToParcel(data, 0);
563 data.writeString(selection);
564 data.writeStringArray(selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565
Jeff Browndf6611d2011-10-09 12:28:54 -0700566 mRemote.transact(IContentProvider.UPDATE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800567
Jeff Browndf6611d2011-10-09 12:28:54 -0700568 DatabaseUtils.readExceptionFromParcel(reply);
569 int count = reply.readInt();
570 return count;
571 } finally {
572 data.recycle();
573 reply.recycle();
574 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575 }
576
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700577 @Override
578 public ParcelFileDescriptor openFile(
Dianne Hackbornff170242014-11-19 10:59:01 -0800579 String callingPkg, Uri url, String mode, ICancellationSignal signal, IBinder token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800580 throws RemoteException, FileNotFoundException {
581 Parcel data = Parcel.obtain();
582 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700583 try {
584 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585
Dianne Hackborn35654b62013-01-14 17:38:02 -0800586 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700587 url.writeToParcel(data, 0);
588 data.writeString(mode);
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700589 data.writeStrongBinder(signal != null ? signal.asBinder() : null);
Dianne Hackbornff170242014-11-19 10:59:01 -0800590 data.writeStrongBinder(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800591
Jeff Browndf6611d2011-10-09 12:28:54 -0700592 mRemote.transact(IContentProvider.OPEN_FILE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800593
Jeff Browndf6611d2011-10-09 12:28:54 -0700594 DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
595 int has = reply.readInt();
Ben Kwa192b3d42015-04-29 13:28:25 -0700596 ParcelFileDescriptor fd = has != 0 ? ParcelFileDescriptor.CREATOR
597 .createFromParcel(reply) : null;
Jeff Browndf6611d2011-10-09 12:28:54 -0700598 return fd;
599 } finally {
600 data.recycle();
601 reply.recycle();
602 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603 }
604
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700605 @Override
606 public AssetFileDescriptor openAssetFile(
607 String callingPkg, Uri url, String mode, ICancellationSignal signal)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800608 throws RemoteException, FileNotFoundException {
609 Parcel data = Parcel.obtain();
610 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700611 try {
612 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613
Dianne Hackborn35654b62013-01-14 17:38:02 -0800614 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700615 url.writeToParcel(data, 0);
616 data.writeString(mode);
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700617 data.writeStrongBinder(signal != null ? signal.asBinder() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618
Jeff Browndf6611d2011-10-09 12:28:54 -0700619 mRemote.transact(IContentProvider.OPEN_ASSET_FILE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800620
Jeff Browndf6611d2011-10-09 12:28:54 -0700621 DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
622 int has = reply.readInt();
623 AssetFileDescriptor fd = has != 0
624 ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
625 return fd;
626 } finally {
627 data.recycle();
628 reply.recycle();
629 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630 }
631
Dianne Hackborn35654b62013-01-14 17:38:02 -0800632 public Bundle call(String callingPkg, String method, String request, Bundle args)
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800633 throws RemoteException {
634 Parcel data = Parcel.obtain();
635 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700636 try {
637 data.writeInterfaceToken(IContentProvider.descriptor);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800638
Dianne Hackborn35654b62013-01-14 17:38:02 -0800639 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700640 data.writeString(method);
641 data.writeString(request);
642 data.writeBundle(args);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800643
Jeff Browndf6611d2011-10-09 12:28:54 -0700644 mRemote.transact(IContentProvider.CALL_TRANSACTION, data, reply, 0);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800645
Jeff Browndf6611d2011-10-09 12:28:54 -0700646 DatabaseUtils.readExceptionFromParcel(reply);
647 Bundle bundle = reply.readBundle();
648 return bundle;
649 } finally {
650 data.recycle();
651 reply.recycle();
652 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800653 }
654
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700655 public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException
656 {
657 Parcel data = Parcel.obtain();
658 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700659 try {
660 data.writeInterfaceToken(IContentProvider.descriptor);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700661
Jeff Browndf6611d2011-10-09 12:28:54 -0700662 url.writeToParcel(data, 0);
663 data.writeString(mimeTypeFilter);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700664
Jeff Browndf6611d2011-10-09 12:28:54 -0700665 mRemote.transact(IContentProvider.GET_STREAM_TYPES_TRANSACTION, data, reply, 0);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700666
Jeff Browndf6611d2011-10-09 12:28:54 -0700667 DatabaseUtils.readExceptionFromParcel(reply);
668 String[] out = reply.createStringArray();
669 return out;
670 } finally {
671 data.recycle();
672 reply.recycle();
673 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700674 }
675
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700676 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800677 public AssetFileDescriptor openTypedAssetFile(String callingPkg, Uri url, String mimeType,
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700678 Bundle opts, ICancellationSignal signal) throws RemoteException, FileNotFoundException {
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700679 Parcel data = Parcel.obtain();
680 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700681 try {
682 data.writeInterfaceToken(IContentProvider.descriptor);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700683
Dianne Hackborn35654b62013-01-14 17:38:02 -0800684 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700685 url.writeToParcel(data, 0);
686 data.writeString(mimeType);
687 data.writeBundle(opts);
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700688 data.writeStrongBinder(signal != null ? signal.asBinder() : null);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700689
Jeff Browndf6611d2011-10-09 12:28:54 -0700690 mRemote.transact(IContentProvider.OPEN_TYPED_ASSET_FILE_TRANSACTION, data, reply, 0);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700691
Jeff Browndf6611d2011-10-09 12:28:54 -0700692 DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
693 int has = reply.readInt();
694 AssetFileDescriptor fd = has != 0
695 ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
696 return fd;
697 } finally {
698 data.recycle();
699 reply.recycle();
700 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700701 }
702
Jeff Brown4c1241d2012-02-02 17:05:00 -0800703 public ICancellationSignal createCancellationSignal() throws RemoteException {
Jeff Brown75ea64f2012-01-25 19:37:13 -0800704 Parcel data = Parcel.obtain();
705 Parcel reply = Parcel.obtain();
706 try {
707 data.writeInterfaceToken(IContentProvider.descriptor);
708
709 mRemote.transact(IContentProvider.CREATE_CANCELATION_SIGNAL_TRANSACTION,
710 data, reply, 0);
711
712 DatabaseUtils.readExceptionFromParcel(reply);
Jeff Brown4c1241d2012-02-02 17:05:00 -0800713 ICancellationSignal cancellationSignal = ICancellationSignal.Stub.asInterface(
Jeff Brown75ea64f2012-01-25 19:37:13 -0800714 reply.readStrongBinder());
Jeff Brown4c1241d2012-02-02 17:05:00 -0800715 return cancellationSignal;
Jeff Brown75ea64f2012-01-25 19:37:13 -0800716 } finally {
717 data.recycle();
718 reply.recycle();
719 }
720 }
721
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700722 public Uri canonicalize(String callingPkg, Uri url) throws RemoteException
723 {
724 Parcel data = Parcel.obtain();
725 Parcel reply = Parcel.obtain();
726 try {
727 data.writeInterfaceToken(IContentProvider.descriptor);
728
729 data.writeString(callingPkg);
730 url.writeToParcel(data, 0);
731
732 mRemote.transact(IContentProvider.CANONICALIZE_TRANSACTION, data, reply, 0);
733
734 DatabaseUtils.readExceptionFromParcel(reply);
735 Uri out = Uri.CREATOR.createFromParcel(reply);
736 return out;
737 } finally {
738 data.recycle();
739 reply.recycle();
740 }
741 }
742
743 public Uri uncanonicalize(String callingPkg, Uri url) throws RemoteException {
744 Parcel data = Parcel.obtain();
745 Parcel reply = Parcel.obtain();
746 try {
747 data.writeInterfaceToken(IContentProvider.descriptor);
748
749 data.writeString(callingPkg);
750 url.writeToParcel(data, 0);
751
752 mRemote.transact(IContentProvider.UNCANONICALIZE_TRANSACTION, data, reply, 0);
753
754 DatabaseUtils.readExceptionFromParcel(reply);
755 Uri out = Uri.CREATOR.createFromParcel(reply);
756 return out;
757 } finally {
758 data.recycle();
759 reply.recycle();
760 }
761 }
762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763 private IBinder mRemote;
764}