blob: 994833866f40e7e774572b3f56e1d59c47cf46a9 [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
Steve McKayea93fe72016-12-02 11:35:35 -080019import android.annotation.Nullable;
Mathew Inwood5c0d3542018-08-14 13:54:31 +010020import android.annotation.UnsupportedAppUsage;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.res.AssetFileDescriptor;
Jeff Brownfb5a4962012-03-14 17:38:59 -070022import android.database.BulkCursorDescriptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.database.BulkCursorToCursorAdaptor;
24import android.database.Cursor;
Jeff Brownd2183652011-10-09 12:39:53 -070025import android.database.CursorToBulkCursorAdaptor;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026import android.database.DatabaseUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.database.IContentObserver;
28import android.net.Uri;
29import android.os.Binder;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080030import android.os.Bundle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031import android.os.IBinder;
Jeff Browna7771df2012-05-07 20:06:46 -070032import android.os.ICancellationSignal;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033import android.os.Parcel;
34import android.os.ParcelFileDescriptor;
35import android.os.Parcelable;
Jeff Sharkeybd3b9022013-08-20 15:20:04 -070036import android.os.RemoteException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38import java.io.FileNotFoundException;
Fred Quintana03d94902009-05-22 14:23:31 -070039import java.util.ArrayList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
41/**
42 * {@hide}
43 */
44abstract public class ContentProviderNative extends Binder implements IContentProvider {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 public ContentProviderNative()
46 {
47 attachInterface(this, descriptor);
48 }
49
50 /**
51 * Cast a Binder object into a content resolver interface, generating
52 * a proxy if needed.
53 */
Mathew Inwood5c0d3542018-08-14 13:54:31 +010054 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055 static public IContentProvider asInterface(IBinder obj)
56 {
57 if (obj == null) {
58 return null;
59 }
60 IContentProvider in =
61 (IContentProvider)obj.queryLocalInterface(descriptor);
62 if (in != null) {
63 return in;
64 }
65
66 return new ContentProviderProxy(obj);
67 }
68
Jeff Brownd2183652011-10-09 12:39:53 -070069 /**
70 * Gets the name of the content provider.
71 * Should probably be part of the {@link IContentProvider} interface.
72 * @return The content provider name.
73 */
74 public abstract String getProviderName();
75
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076 @Override
77 public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
78 throws RemoteException {
79 try {
80 switch (code) {
81 case QUERY_TRANSACTION:
82 {
83 data.enforceInterface(IContentProvider.descriptor);
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -080084
Dianne Hackborn35654b62013-01-14 17:38:02 -080085 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 Uri url = Uri.CREATOR.createFromParcel(data);
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -080087
88 // String[] projection
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 int num = data.readInt();
90 String[] projection = null;
91 if (num > 0) {
92 projection = new String[num];
93 for (int i = 0; i < num; i++) {
94 projection[i] = data.readString();
95 }
96 }
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -080097
Steve McKayea93fe72016-12-02 11:35:35 -080098 Bundle queryArgs = data.readBundle();
Jeff Brownd2183652011-10-09 12:39:53 -070099 IContentObserver observer = IContentObserver.Stub.asInterface(
100 data.readStrongBinder());
Jeff Brown4c1241d2012-02-02 17:05:00 -0800101 ICancellationSignal cancellationSignal = ICancellationSignal.Stub.asInterface(
Jeff Brown75ea64f2012-01-25 19:37:13 -0800102 data.readStrongBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103
Steve McKayea93fe72016-12-02 11:35:35 -0800104 Cursor cursor = query(callingPkg, url, projection, queryArgs, cancellationSignal);
Jeff Brownd2183652011-10-09 12:39:53 -0700105 if (cursor != null) {
Peter Eliasson55eda432013-06-28 13:55:41 +0200106 CursorToBulkCursorAdaptor adaptor = null;
107
Jeff Brownc21b5a02013-01-07 17:15:12 -0800108 try {
Peter Eliasson55eda432013-06-28 13:55:41 +0200109 adaptor = new CursorToBulkCursorAdaptor(cursor, observer,
110 getProviderName());
Jeff Brownc21b5a02013-01-07 17:15:12 -0800111 cursor = null;
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -0800112
Peter Eliasson55eda432013-06-28 13:55:41 +0200113 BulkCursorDescriptor d = adaptor.getBulkCursorDescriptor();
114 adaptor = null;
115
Jeff Brownc21b5a02013-01-07 17:15:12 -0800116 reply.writeNoException();
117 reply.writeInt(1);
118 d.writeToParcel(reply, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
119 } finally {
120 // Close cursor if an exception was thrown while constructing the adaptor.
Peter Eliasson55eda432013-06-28 13:55:41 +0200121 if (adaptor != null) {
122 adaptor.close();
123 }
Jeff Brownc21b5a02013-01-07 17:15:12 -0800124 if (cursor != null) {
125 cursor.close();
126 }
127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 } else {
Fabrice Di Meglioeca53642010-12-01 20:24:40 -0800129 reply.writeNoException();
Jeff Brownfb5a4962012-03-14 17:38:59 -0700130 reply.writeInt(0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800131 }
Brad Fitzpatrick9ffdfa02010-03-09 13:18:02 -0800132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 return true;
134 }
135
136 case GET_TYPE_TRANSACTION:
137 {
138 data.enforceInterface(IContentProvider.descriptor);
139 Uri url = Uri.CREATOR.createFromParcel(data);
140 String type = getType(url);
141 reply.writeNoException();
142 reply.writeString(type);
143
144 return true;
145 }
146
147 case INSERT_TRANSACTION:
148 {
149 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800150 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 Uri url = Uri.CREATOR.createFromParcel(data);
152 ContentValues values = ContentValues.CREATOR.createFromParcel(data);
153
Dianne Hackborn35654b62013-01-14 17:38:02 -0800154 Uri out = insert(callingPkg, url, values);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 reply.writeNoException();
156 Uri.writeToParcel(reply, out);
157 return true;
158 }
159
160 case BULK_INSERT_TRANSACTION:
161 {
162 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800163 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164 Uri url = Uri.CREATOR.createFromParcel(data);
165 ContentValues[] values = data.createTypedArray(ContentValues.CREATOR);
166
Dianne Hackborn35654b62013-01-14 17:38:02 -0800167 int count = bulkInsert(callingPkg, url, values);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 reply.writeNoException();
169 reply.writeInt(count);
170 return true;
171 }
172
Fred Quintana89437372009-05-15 15:10:40 -0700173 case APPLY_BATCH_TRANSACTION:
174 {
175 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800176 String callingPkg = data.readString();
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700177 String authority = data.readString();
Fred Quintana03d94902009-05-22 14:23:31 -0700178 final int numOperations = data.readInt();
179 final ArrayList<ContentProviderOperation> operations =
Steve McKayea93fe72016-12-02 11:35:35 -0800180 new ArrayList<>(numOperations);
Fred Quintana03d94902009-05-22 14:23:31 -0700181 for (int i = 0; i < numOperations; i++) {
182 operations.add(i, ContentProviderOperation.CREATOR.createFromParcel(data));
183 }
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700184 final ContentProviderResult[] results = applyBatch(callingPkg, authority,
185 operations);
Fred Quintana89437372009-05-15 15:10:40 -0700186 reply.writeNoException();
187 reply.writeTypedArray(results, 0);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700188 return true;
189 }
190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 case DELETE_TRANSACTION:
192 {
193 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800194 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 Uri url = Uri.CREATOR.createFromParcel(data);
196 String selection = data.readString();
197 String[] selectionArgs = data.readStringArray();
198
Dianne Hackborn35654b62013-01-14 17:38:02 -0800199 int count = delete(callingPkg, url, selection, selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200
201 reply.writeNoException();
202 reply.writeInt(count);
203 return true;
204 }
205
206 case UPDATE_TRANSACTION:
207 {
208 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800209 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800210 Uri url = Uri.CREATOR.createFromParcel(data);
211 ContentValues values = ContentValues.CREATOR.createFromParcel(data);
212 String selection = data.readString();
213 String[] selectionArgs = data.readStringArray();
214
Dianne Hackborn35654b62013-01-14 17:38:02 -0800215 int count = update(callingPkg, url, values, selection, selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216
217 reply.writeNoException();
218 reply.writeInt(count);
219 return true;
220 }
221
222 case OPEN_FILE_TRANSACTION:
223 {
224 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800225 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 Uri url = Uri.CREATOR.createFromParcel(data);
227 String mode = data.readString();
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700228 ICancellationSignal signal = ICancellationSignal.Stub.asInterface(
229 data.readStrongBinder());
Dianne Hackbornff170242014-11-19 10:59:01 -0800230 IBinder callerToken = data.readStrongBinder();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231
232 ParcelFileDescriptor fd;
Dianne Hackbornff170242014-11-19 10:59:01 -0800233 fd = openFile(callingPkg, url, mode, signal, callerToken);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800234 reply.writeNoException();
235 if (fd != null) {
236 reply.writeInt(1);
237 fd.writeToParcel(reply,
238 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
239 } else {
240 reply.writeInt(0);
241 }
242 return true;
243 }
244
245 case OPEN_ASSET_FILE_TRANSACTION:
246 {
247 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800248 String callingPkg = data.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 Uri url = Uri.CREATOR.createFromParcel(data);
250 String mode = data.readString();
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700251 ICancellationSignal signal = ICancellationSignal.Stub.asInterface(
252 data.readStrongBinder());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253
254 AssetFileDescriptor fd;
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700255 fd = openAssetFile(callingPkg, url, mode, signal);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800256 reply.writeNoException();
257 if (fd != null) {
258 reply.writeInt(1);
259 fd.writeToParcel(reply,
260 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
261 } else {
262 reply.writeInt(0);
263 }
264 return true;
265 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800266
267 case CALL_TRANSACTION:
268 {
269 data.enforceInterface(IContentProvider.descriptor);
270
Dianne Hackborn35654b62013-01-14 17:38:02 -0800271 String callingPkg = data.readString();
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700272 String authority = data.readString();
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800273 String method = data.readString();
274 String stringArg = data.readString();
275 Bundle args = data.readBundle();
276
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700277 Bundle responseBundle = call(callingPkg, authority, method, stringArg, args);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800278
279 reply.writeNoException();
280 reply.writeBundle(responseBundle);
281 return true;
282 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700283
284 case GET_STREAM_TYPES_TRANSACTION:
285 {
286 data.enforceInterface(IContentProvider.descriptor);
287 Uri url = Uri.CREATOR.createFromParcel(data);
288 String mimeTypeFilter = data.readString();
289 String[] types = getStreamTypes(url, mimeTypeFilter);
290 reply.writeNoException();
291 reply.writeStringArray(types);
292
293 return true;
294 }
295
296 case OPEN_TYPED_ASSET_FILE_TRANSACTION:
297 {
298 data.enforceInterface(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800299 String callingPkg = data.readString();
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700300 Uri url = Uri.CREATOR.createFromParcel(data);
301 String mimeType = data.readString();
302 Bundle opts = data.readBundle();
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700303 ICancellationSignal signal = ICancellationSignal.Stub.asInterface(
304 data.readStrongBinder());
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700305
306 AssetFileDescriptor fd;
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700307 fd = openTypedAssetFile(callingPkg, url, mimeType, opts, signal);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700308 reply.writeNoException();
309 if (fd != null) {
310 reply.writeInt(1);
311 fd.writeToParcel(reply,
312 Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
313 } else {
314 reply.writeInt(0);
315 }
316 return true;
317 }
Jeff Brown75ea64f2012-01-25 19:37:13 -0800318
319 case CREATE_CANCELATION_SIGNAL_TRANSACTION:
320 {
321 data.enforceInterface(IContentProvider.descriptor);
322
Jeff Brown4c1241d2012-02-02 17:05:00 -0800323 ICancellationSignal cancellationSignal = createCancellationSignal();
Jeff Brown75ea64f2012-01-25 19:37:13 -0800324 reply.writeNoException();
Jeff Brown4c1241d2012-02-02 17:05:00 -0800325 reply.writeStrongBinder(cancellationSignal.asBinder());
Jeff Brown75ea64f2012-01-25 19:37:13 -0800326 return true;
327 }
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700328
329 case CANONICALIZE_TRANSACTION:
330 {
331 data.enforceInterface(IContentProvider.descriptor);
332 String callingPkg = data.readString();
333 Uri url = Uri.CREATOR.createFromParcel(data);
334
335 Uri out = canonicalize(callingPkg, url);
336 reply.writeNoException();
337 Uri.writeToParcel(reply, out);
338 return true;
339 }
340
341 case UNCANONICALIZE_TRANSACTION:
342 {
343 data.enforceInterface(IContentProvider.descriptor);
344 String callingPkg = data.readString();
345 Uri url = Uri.CREATOR.createFromParcel(data);
346
347 Uri out = uncanonicalize(callingPkg, url);
348 reply.writeNoException();
349 Uri.writeToParcel(reply, out);
350 return true;
351 }
Ben Lin1cf454f2016-11-10 13:50:54 -0800352
353 case REFRESH_TRANSACTION: {
354 data.enforceInterface(IContentProvider.descriptor);
355 String callingPkg = data.readString();
356 Uri url = Uri.CREATOR.createFromParcel(data);
357 Bundle args = data.readBundle();
358 ICancellationSignal signal = ICancellationSignal.Stub.asInterface(
359 data.readStrongBinder());
360
361 boolean out = refresh(callingPkg, url, args, signal);
362 reply.writeNoException();
363 reply.writeInt(out ? 0 : -1);
364 return true;
365 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 }
367 } catch (Exception e) {
368 DatabaseUtils.writeExceptionToParcel(reply, e);
369 return true;
370 }
371
372 return super.onTransact(code, data, reply, flags);
373 }
374
Steve McKayea93fe72016-12-02 11:35:35 -0800375 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 public IBinder asBinder()
377 {
378 return this;
379 }
380}
381
382
383final class ContentProviderProxy implements IContentProvider
384{
385 public ContentProviderProxy(IBinder remote)
386 {
387 mRemote = remote;
388 }
389
Steve McKayea93fe72016-12-02 11:35:35 -0800390 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800391 public IBinder asBinder()
392 {
393 return mRemote;
394 }
395
Steve McKayea93fe72016-12-02 11:35:35 -0800396 @Override
397 public Cursor query(String callingPkg, Uri url, @Nullable String[] projection,
398 @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal)
399 throws RemoteException {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700400 BulkCursorToCursorAdaptor adaptor = new BulkCursorToCursorAdaptor();
401 Parcel data = Parcel.obtain();
402 Parcel reply = Parcel.obtain();
Jeff Brownd2183652011-10-09 12:39:53 -0700403 try {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700404 data.writeInterfaceToken(IContentProvider.descriptor);
Jeff Brownd2183652011-10-09 12:39:53 -0700405
Dianne Hackborn35654b62013-01-14 17:38:02 -0800406 data.writeString(callingPkg);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700407 url.writeToParcel(data, 0);
408 int length = 0;
409 if (projection != null) {
410 length = projection.length;
Jeff Brownd2183652011-10-09 12:39:53 -0700411 }
Jeff Brown0cde89f2011-10-10 14:50:10 -0700412 data.writeInt(length);
413 for (int i = 0; i < length; i++) {
414 data.writeString(projection[i]);
415 }
Steve McKayea93fe72016-12-02 11:35:35 -0800416 data.writeBundle(queryArgs);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700417 data.writeStrongBinder(adaptor.getObserver().asBinder());
Steve McKayea93fe72016-12-02 11:35:35 -0800418 data.writeStrongBinder(
419 cancellationSignal != null ? cancellationSignal.asBinder() : null);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700420
421 mRemote.transact(IContentProvider.QUERY_TRANSACTION, data, reply, 0);
422
423 DatabaseUtils.readExceptionFromParcel(reply);
424
Jeff Brownfb5a4962012-03-14 17:38:59 -0700425 if (reply.readInt() != 0) {
426 BulkCursorDescriptor d = BulkCursorDescriptor.CREATOR.createFromParcel(reply);
Jeff Sharkey0a17db12016-11-04 11:23:46 -0600427 Binder.copyAllowBlocking(mRemote, (d.cursor != null) ? d.cursor.asBinder() : null);
Jeff Brownfb5a4962012-03-14 17:38:59 -0700428 adaptor.initialize(d);
Jeff Brown0cde89f2011-10-10 14:50:10 -0700429 } else {
430 adaptor.close();
431 adaptor = null;
432 }
433 return adaptor;
434 } catch (RemoteException ex) {
435 adaptor.close();
436 throw ex;
437 } catch (RuntimeException ex) {
438 adaptor.close();
439 throw ex;
Jeff Brownd2183652011-10-09 12:39:53 -0700440 } finally {
Jeff Brown0cde89f2011-10-10 14:50:10 -0700441 data.recycle();
442 reply.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800443 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 }
445
Steve McKayea93fe72016-12-02 11:35:35 -0800446 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800447 public String getType(Uri url) throws RemoteException
448 {
449 Parcel data = Parcel.obtain();
450 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700451 try {
452 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453
Jeff Browndf6611d2011-10-09 12:28:54 -0700454 url.writeToParcel(data, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800455
Jeff Browndf6611d2011-10-09 12:28:54 -0700456 mRemote.transact(IContentProvider.GET_TYPE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457
Jeff Browndf6611d2011-10-09 12:28:54 -0700458 DatabaseUtils.readExceptionFromParcel(reply);
459 String out = reply.readString();
460 return out;
461 } finally {
462 data.recycle();
463 reply.recycle();
464 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800465 }
466
Steve McKayea93fe72016-12-02 11:35:35 -0800467 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800468 public Uri insert(String callingPkg, Uri url, ContentValues values) throws RemoteException
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800469 {
470 Parcel data = Parcel.obtain();
471 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700472 try {
473 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800474
Dianne Hackborn35654b62013-01-14 17:38:02 -0800475 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700476 url.writeToParcel(data, 0);
477 values.writeToParcel(data, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800478
Jeff Browndf6611d2011-10-09 12:28:54 -0700479 mRemote.transact(IContentProvider.INSERT_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800480
Jeff Browndf6611d2011-10-09 12:28:54 -0700481 DatabaseUtils.readExceptionFromParcel(reply);
482 Uri out = Uri.CREATOR.createFromParcel(reply);
483 return out;
484 } finally {
485 data.recycle();
486 reply.recycle();
487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800488 }
489
Steve McKayea93fe72016-12-02 11:35:35 -0800490 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800491 public int bulkInsert(String callingPkg, Uri url, ContentValues[] values) throws RemoteException {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 Parcel data = Parcel.obtain();
493 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700494 try {
495 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496
Dianne Hackborn35654b62013-01-14 17:38:02 -0800497 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700498 url.writeToParcel(data, 0);
499 data.writeTypedArray(values, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500
Jeff Browndf6611d2011-10-09 12:28:54 -0700501 mRemote.transact(IContentProvider.BULK_INSERT_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502
Jeff Browndf6611d2011-10-09 12:28:54 -0700503 DatabaseUtils.readExceptionFromParcel(reply);
504 int count = reply.readInt();
505 return count;
506 } finally {
507 data.recycle();
508 reply.recycle();
509 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 }
511
Steve McKayea93fe72016-12-02 11:35:35 -0800512 @Override
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700513 public ContentProviderResult[] applyBatch(String callingPkg, String authority,
Dianne Hackborn35654b62013-01-14 17:38:02 -0800514 ArrayList<ContentProviderOperation> operations)
515 throws RemoteException, OperationApplicationException {
Fred Quintana6a8d5332009-05-07 17:35:38 -0700516 Parcel data = Parcel.obtain();
517 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700518 try {
519 data.writeInterfaceToken(IContentProvider.descriptor);
Dianne Hackborn35654b62013-01-14 17:38:02 -0800520 data.writeString(callingPkg);
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700521 data.writeString(authority);
Jeff Browndf6611d2011-10-09 12:28:54 -0700522 data.writeInt(operations.size());
523 for (ContentProviderOperation operation : operations) {
524 operation.writeToParcel(data, 0);
525 }
526 mRemote.transact(IContentProvider.APPLY_BATCH_TRANSACTION, data, reply, 0);
Fred Quintana6a8d5332009-05-07 17:35:38 -0700527
Jeff Browndf6611d2011-10-09 12:28:54 -0700528 DatabaseUtils.readExceptionWithOperationApplicationExceptionFromParcel(reply);
529 final ContentProviderResult[] results =
530 reply.createTypedArray(ContentProviderResult.CREATOR);
531 return results;
532 } finally {
533 data.recycle();
534 reply.recycle();
Fred Quintana03d94902009-05-22 14:23:31 -0700535 }
Fred Quintana6a8d5332009-05-07 17:35:38 -0700536 }
537
Steve McKayea93fe72016-12-02 11:35:35 -0800538 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800539 public int delete(String callingPkg, Uri url, String selection, String[] selectionArgs)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800540 throws RemoteException {
541 Parcel data = Parcel.obtain();
542 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700543 try {
544 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800545
Dianne Hackborn35654b62013-01-14 17:38:02 -0800546 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700547 url.writeToParcel(data, 0);
548 data.writeString(selection);
549 data.writeStringArray(selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550
Jeff Browndf6611d2011-10-09 12:28:54 -0700551 mRemote.transact(IContentProvider.DELETE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800552
Jeff Browndf6611d2011-10-09 12:28:54 -0700553 DatabaseUtils.readExceptionFromParcel(reply);
554 int count = reply.readInt();
555 return count;
556 } finally {
557 data.recycle();
558 reply.recycle();
559 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800560 }
561
Steve McKayea93fe72016-12-02 11:35:35 -0800562 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800563 public int update(String callingPkg, Uri url, ContentValues values, String selection,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800564 String[] selectionArgs) throws RemoteException {
565 Parcel data = Parcel.obtain();
566 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700567 try {
568 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569
Dianne Hackborn35654b62013-01-14 17:38:02 -0800570 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700571 url.writeToParcel(data, 0);
572 values.writeToParcel(data, 0);
573 data.writeString(selection);
574 data.writeStringArray(selectionArgs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800575
Jeff Browndf6611d2011-10-09 12:28:54 -0700576 mRemote.transact(IContentProvider.UPDATE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800577
Jeff Browndf6611d2011-10-09 12:28:54 -0700578 DatabaseUtils.readExceptionFromParcel(reply);
579 int count = reply.readInt();
580 return count;
581 } finally {
582 data.recycle();
583 reply.recycle();
584 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800585 }
586
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700587 @Override
588 public ParcelFileDescriptor openFile(
Dianne Hackbornff170242014-11-19 10:59:01 -0800589 String callingPkg, Uri url, String mode, ICancellationSignal signal, IBinder token)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 throws RemoteException, FileNotFoundException {
591 Parcel data = Parcel.obtain();
592 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700593 try {
594 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800595
Dianne Hackborn35654b62013-01-14 17:38:02 -0800596 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700597 url.writeToParcel(data, 0);
598 data.writeString(mode);
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700599 data.writeStrongBinder(signal != null ? signal.asBinder() : null);
Dianne Hackbornff170242014-11-19 10:59:01 -0800600 data.writeStrongBinder(token);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800601
Jeff Browndf6611d2011-10-09 12:28:54 -0700602 mRemote.transact(IContentProvider.OPEN_FILE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800603
Jeff Browndf6611d2011-10-09 12:28:54 -0700604 DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
605 int has = reply.readInt();
Ben Kwa192b3d42015-04-29 13:28:25 -0700606 ParcelFileDescriptor fd = has != 0 ? ParcelFileDescriptor.CREATOR
607 .createFromParcel(reply) : null;
Jeff Browndf6611d2011-10-09 12:28:54 -0700608 return fd;
609 } finally {
610 data.recycle();
611 reply.recycle();
612 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800613 }
614
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700615 @Override
616 public AssetFileDescriptor openAssetFile(
617 String callingPkg, Uri url, String mode, ICancellationSignal signal)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 throws RemoteException, FileNotFoundException {
619 Parcel data = Parcel.obtain();
620 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700621 try {
622 data.writeInterfaceToken(IContentProvider.descriptor);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800623
Dianne Hackborn35654b62013-01-14 17:38:02 -0800624 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700625 url.writeToParcel(data, 0);
626 data.writeString(mode);
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700627 data.writeStrongBinder(signal != null ? signal.asBinder() : null);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800628
Jeff Browndf6611d2011-10-09 12:28:54 -0700629 mRemote.transact(IContentProvider.OPEN_ASSET_FILE_TRANSACTION, data, reply, 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800630
Jeff Browndf6611d2011-10-09 12:28:54 -0700631 DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
632 int has = reply.readInt();
633 AssetFileDescriptor fd = has != 0
634 ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
635 return fd;
636 } finally {
637 data.recycle();
638 reply.recycle();
639 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800640 }
641
Steve McKayea93fe72016-12-02 11:35:35 -0800642 @Override
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700643 public Bundle call(String callingPkg, String authority, String method, String request,
644 Bundle args) throws RemoteException {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800645 Parcel data = Parcel.obtain();
646 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700647 try {
648 data.writeInterfaceToken(IContentProvider.descriptor);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800649
Dianne Hackborn35654b62013-01-14 17:38:02 -0800650 data.writeString(callingPkg);
Jeff Sharkey633a13e2018-12-07 12:00:45 -0700651 data.writeString(authority);
Jeff Browndf6611d2011-10-09 12:28:54 -0700652 data.writeString(method);
653 data.writeString(request);
654 data.writeBundle(args);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800655
Jeff Browndf6611d2011-10-09 12:28:54 -0700656 mRemote.transact(IContentProvider.CALL_TRANSACTION, data, reply, 0);
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800657
Jeff Browndf6611d2011-10-09 12:28:54 -0700658 DatabaseUtils.readExceptionFromParcel(reply);
659 Bundle bundle = reply.readBundle();
660 return bundle;
661 } finally {
662 data.recycle();
663 reply.recycle();
664 }
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800665 }
666
Steve McKayea93fe72016-12-02 11:35:35 -0800667 @Override
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700668 public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException
669 {
670 Parcel data = Parcel.obtain();
671 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700672 try {
673 data.writeInterfaceToken(IContentProvider.descriptor);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700674
Jeff Browndf6611d2011-10-09 12:28:54 -0700675 url.writeToParcel(data, 0);
676 data.writeString(mimeTypeFilter);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700677
Jeff Browndf6611d2011-10-09 12:28:54 -0700678 mRemote.transact(IContentProvider.GET_STREAM_TYPES_TRANSACTION, data, reply, 0);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700679
Jeff Browndf6611d2011-10-09 12:28:54 -0700680 DatabaseUtils.readExceptionFromParcel(reply);
681 String[] out = reply.createStringArray();
682 return out;
683 } finally {
684 data.recycle();
685 reply.recycle();
686 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700687 }
688
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700689 @Override
Dianne Hackborn35654b62013-01-14 17:38:02 -0800690 public AssetFileDescriptor openTypedAssetFile(String callingPkg, Uri url, String mimeType,
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700691 Bundle opts, ICancellationSignal signal) throws RemoteException, FileNotFoundException {
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700692 Parcel data = Parcel.obtain();
693 Parcel reply = Parcel.obtain();
Jeff Browndf6611d2011-10-09 12:28:54 -0700694 try {
695 data.writeInterfaceToken(IContentProvider.descriptor);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700696
Dianne Hackborn35654b62013-01-14 17:38:02 -0800697 data.writeString(callingPkg);
Jeff Browndf6611d2011-10-09 12:28:54 -0700698 url.writeToParcel(data, 0);
699 data.writeString(mimeType);
700 data.writeBundle(opts);
Jeff Sharkeybd3b9022013-08-20 15:20:04 -0700701 data.writeStrongBinder(signal != null ? signal.asBinder() : null);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700702
Jeff Browndf6611d2011-10-09 12:28:54 -0700703 mRemote.transact(IContentProvider.OPEN_TYPED_ASSET_FILE_TRANSACTION, data, reply, 0);
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700704
Jeff Browndf6611d2011-10-09 12:28:54 -0700705 DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(reply);
706 int has = reply.readInt();
707 AssetFileDescriptor fd = has != 0
708 ? AssetFileDescriptor.CREATOR.createFromParcel(reply) : null;
709 return fd;
710 } finally {
711 data.recycle();
712 reply.recycle();
713 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700714 }
715
Steve McKayea93fe72016-12-02 11:35:35 -0800716 @Override
Jeff Brown4c1241d2012-02-02 17:05:00 -0800717 public ICancellationSignal createCancellationSignal() throws RemoteException {
Jeff Brown75ea64f2012-01-25 19:37:13 -0800718 Parcel data = Parcel.obtain();
719 Parcel reply = Parcel.obtain();
720 try {
721 data.writeInterfaceToken(IContentProvider.descriptor);
722
723 mRemote.transact(IContentProvider.CREATE_CANCELATION_SIGNAL_TRANSACTION,
724 data, reply, 0);
725
726 DatabaseUtils.readExceptionFromParcel(reply);
Jeff Brown4c1241d2012-02-02 17:05:00 -0800727 ICancellationSignal cancellationSignal = ICancellationSignal.Stub.asInterface(
Jeff Brown75ea64f2012-01-25 19:37:13 -0800728 reply.readStrongBinder());
Jeff Brown4c1241d2012-02-02 17:05:00 -0800729 return cancellationSignal;
Jeff Brown75ea64f2012-01-25 19:37:13 -0800730 } finally {
731 data.recycle();
732 reply.recycle();
733 }
734 }
735
Steve McKayea93fe72016-12-02 11:35:35 -0800736 @Override
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700737 public Uri canonicalize(String callingPkg, Uri url) throws RemoteException
738 {
739 Parcel data = Parcel.obtain();
740 Parcel reply = Parcel.obtain();
741 try {
742 data.writeInterfaceToken(IContentProvider.descriptor);
743
744 data.writeString(callingPkg);
745 url.writeToParcel(data, 0);
746
747 mRemote.transact(IContentProvider.CANONICALIZE_TRANSACTION, data, reply, 0);
748
749 DatabaseUtils.readExceptionFromParcel(reply);
750 Uri out = Uri.CREATOR.createFromParcel(reply);
751 return out;
752 } finally {
753 data.recycle();
754 reply.recycle();
755 }
756 }
757
Steve McKayea93fe72016-12-02 11:35:35 -0800758 @Override
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700759 public Uri uncanonicalize(String callingPkg, Uri url) throws RemoteException {
760 Parcel data = Parcel.obtain();
761 Parcel reply = Parcel.obtain();
762 try {
763 data.writeInterfaceToken(IContentProvider.descriptor);
764
765 data.writeString(callingPkg);
766 url.writeToParcel(data, 0);
767
768 mRemote.transact(IContentProvider.UNCANONICALIZE_TRANSACTION, data, reply, 0);
769
770 DatabaseUtils.readExceptionFromParcel(reply);
771 Uri out = Uri.CREATOR.createFromParcel(reply);
772 return out;
773 } finally {
774 data.recycle();
775 reply.recycle();
776 }
777 }
778
Steve McKayea93fe72016-12-02 11:35:35 -0800779 @Override
Ben Lin1cf454f2016-11-10 13:50:54 -0800780 public boolean refresh(String callingPkg, Uri url, Bundle args, ICancellationSignal signal)
781 throws RemoteException {
782 Parcel data = Parcel.obtain();
783 Parcel reply = Parcel.obtain();
784 try {
785 data.writeInterfaceToken(IContentProvider.descriptor);
786
787 data.writeString(callingPkg);
788 url.writeToParcel(data, 0);
789 data.writeBundle(args);
790 data.writeStrongBinder(signal != null ? signal.asBinder() : null);
791
792 mRemote.transact(IContentProvider.REFRESH_TRANSACTION, data, reply, 0);
793
794 DatabaseUtils.readExceptionFromParcel(reply);
795 int success = reply.readInt();
796 return (success == 0);
797 } finally {
798 data.recycle();
799 reply.recycle();
800 }
801 }
802
Andrei Oneaf650e3c2019-02-25 13:15:54 +0000803 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800804 private IBinder mRemote;
805}