1 /* 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 17 package android.content; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.compat.annotation.UnsupportedAppUsage; 22 import android.content.res.AssetFileDescriptor; 23 import android.database.Cursor; 24 import android.net.Uri; 25 import android.os.Binder; 26 import android.os.Build; 27 import android.os.Bundle; 28 import android.os.IBinder; 29 import android.os.ICancellationSignal; 30 import android.os.IInterface; 31 import android.os.ParcelFileDescriptor; 32 import android.os.RemoteCallback; 33 import android.os.RemoteException; 34 35 import java.io.FileNotFoundException; 36 import java.util.ArrayList; 37 38 /** 39 * The ipc interface to talk to a content provider. 40 * @hide 41 */ 42 public interface IContentProvider extends IInterface { query(@onNull AttributionSource attributionSource, Uri url, @Nullable String[] projection, @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal)43 Cursor query(@NonNull AttributionSource attributionSource, Uri url, 44 @Nullable String[] projection, 45 @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal) 46 throws RemoteException; getType(Uri url)47 String getType(Uri url) throws RemoteException; 48 49 /** 50 * A oneway version of getType. The functionality is exactly the same, except that the 51 * call returns immediately, and the resulting type is returned when available via 52 * a binder callback. 53 */ getTypeAsync(Uri uri, RemoteCallback callback)54 void getTypeAsync(Uri uri, RemoteCallback callback) throws RemoteException; 55 56 @Deprecated 57 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " 58 + "ContentProviderClient#insert(android.net.Uri, android.content.ContentValues)} " 59 + "instead") insert(String callingPkg, Uri url, ContentValues initialValues)60 default Uri insert(String callingPkg, Uri url, ContentValues initialValues) 61 throws RemoteException { 62 return insert(new AttributionSource(Binder.getCallingUid(), callingPkg, null), 63 url, initialValues, null); 64 } insert(@onNull AttributionSource attributionSource, Uri url, ContentValues initialValues, Bundle extras)65 Uri insert(@NonNull AttributionSource attributionSource, Uri url, 66 ContentValues initialValues, Bundle extras) throws RemoteException; 67 @Deprecated 68 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " 69 + "ContentProviderClient#bulkInsert(android.net.Uri, android.content.ContentValues[])" 70 + "} instead") bulkInsert(String callingPkg, Uri url, ContentValues[] initialValues)71 default int bulkInsert(String callingPkg, Uri url, ContentValues[] initialValues) 72 throws RemoteException { 73 return bulkInsert(new AttributionSource(Binder.getCallingUid(), callingPkg, null), 74 url, initialValues); 75 } bulkInsert(@onNull AttributionSource attributionSource, Uri url, ContentValues[] initialValues)76 int bulkInsert(@NonNull AttributionSource attributionSource, Uri url, 77 ContentValues[] initialValues) throws RemoteException; 78 @Deprecated 79 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " 80 + "ContentProviderClient#delete(android.net.Uri, java.lang.String, java.lang" 81 + ".String[])} instead") delete(String callingPkg, Uri url, String selection, String[] selectionArgs)82 default int delete(String callingPkg, Uri url, String selection, String[] selectionArgs) 83 throws RemoteException { 84 return delete(new AttributionSource(Binder.getCallingUid(), callingPkg, null), 85 url, ContentResolver.createSqlQueryBundle(selection, selectionArgs)); 86 } delete(@onNull AttributionSource attributionSource, Uri url, Bundle extras)87 int delete(@NonNull AttributionSource attributionSource, Uri url, Bundle extras) 88 throws RemoteException; 89 @Deprecated 90 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " 91 + "ContentProviderClient#update(android.net.Uri, android.content.ContentValues, java" 92 + ".lang.String, java.lang.String[])} instead") update(String callingPkg, Uri url, ContentValues values, String selection, String[] selectionArgs)93 default int update(String callingPkg, Uri url, ContentValues values, String selection, 94 String[] selectionArgs) throws RemoteException { 95 return update(new AttributionSource(Binder.getCallingUid(), callingPkg, null), 96 url, values, ContentResolver.createSqlQueryBundle(selection, selectionArgs)); 97 } update(@onNull AttributionSource attributionSource, Uri url, ContentValues values, Bundle extras)98 int update(@NonNull AttributionSource attributionSource, Uri url, ContentValues values, 99 Bundle extras) throws RemoteException; 100 openFile(@onNull AttributionSource attributionSource, Uri url, String mode, ICancellationSignal signal)101 ParcelFileDescriptor openFile(@NonNull AttributionSource attributionSource, 102 Uri url, String mode, ICancellationSignal signal) 103 throws RemoteException, FileNotFoundException; 104 openAssetFile(@onNull AttributionSource attributionSource, Uri url, String mode, ICancellationSignal signal)105 AssetFileDescriptor openAssetFile(@NonNull AttributionSource attributionSource, 106 Uri url, String mode, ICancellationSignal signal) 107 throws RemoteException, FileNotFoundException; 108 applyBatch(@onNull AttributionSource attributionSource, String authority, ArrayList<ContentProviderOperation> operations)109 ContentProviderResult[] applyBatch(@NonNull AttributionSource attributionSource, 110 String authority, ArrayList<ContentProviderOperation> operations) 111 throws RemoteException, OperationApplicationException; 112 113 @Deprecated 114 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link " 115 + "ContentProviderClient#call(java.lang.String, java.lang.String, android.os.Bundle)} " 116 + "instead") call(String callingPkg, String method, @Nullable String arg, @Nullable Bundle extras)117 public default Bundle call(String callingPkg, String method, 118 @Nullable String arg, @Nullable Bundle extras) throws RemoteException { 119 return call(new AttributionSource(Binder.getCallingUid(), callingPkg, null), 120 "unknown", method, arg, extras); 121 } 122 call(@onNull AttributionSource attributionSource, String authority, String method, @Nullable String arg, @Nullable Bundle extras)123 Bundle call(@NonNull AttributionSource attributionSource, String authority, 124 String method, @Nullable String arg, @Nullable Bundle extras) throws RemoteException; 125 checkUriPermission(@onNull AttributionSource attributionSource, Uri uri, int uid, int modeFlags)126 int checkUriPermission(@NonNull AttributionSource attributionSource, Uri uri, 127 int uid, int modeFlags) throws RemoteException; 128 createCancellationSignal()129 ICancellationSignal createCancellationSignal() throws RemoteException; 130 canonicalize(@onNull AttributionSource attributionSource, Uri uri)131 Uri canonicalize(@NonNull AttributionSource attributionSource, Uri uri) 132 throws RemoteException; 133 134 /** 135 * A oneway version of canonicalize. The functionality is exactly the same, except that the 136 * call returns immediately, and the resulting type is returned when available via 137 * a binder callback. 138 */ canonicalizeAsync(@onNull AttributionSource attributionSource, Uri uri, RemoteCallback callback)139 void canonicalizeAsync(@NonNull AttributionSource attributionSource, Uri uri, 140 RemoteCallback callback) throws RemoteException; 141 uncanonicalize(@onNull AttributionSource attributionSource, Uri uri)142 Uri uncanonicalize(@NonNull AttributionSource attributionSource, Uri uri) 143 throws RemoteException; 144 145 /** 146 * A oneway version of uncanonicalize. The functionality is exactly the same, except that the 147 * call returns immediately, and the resulting type is returned when available via 148 * a binder callback. 149 */ uncanonicalizeAsync(@onNull AttributionSource attributionSource, Uri uri, RemoteCallback callback)150 void uncanonicalizeAsync(@NonNull AttributionSource attributionSource, Uri uri, 151 RemoteCallback callback) throws RemoteException; 152 refresh(@onNull AttributionSource attributionSource, Uri url, @Nullable Bundle extras, ICancellationSignal cancellationSignal)153 public boolean refresh(@NonNull AttributionSource attributionSource, Uri url, 154 @Nullable Bundle extras, ICancellationSignal cancellationSignal) throws RemoteException; 155 156 // Data interchange. getStreamTypes(Uri url, String mimeTypeFilter)157 public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException; 158 openTypedAssetFile(@onNull AttributionSource attributionSource, Uri url, String mimeType, Bundle opts, ICancellationSignal signal)159 public AssetFileDescriptor openTypedAssetFile(@NonNull AttributionSource attributionSource, 160 Uri url, String mimeType, Bundle opts, ICancellationSignal signal) 161 throws RemoteException, FileNotFoundException; 162 163 /* IPC constants */ 164 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) 165 static final String descriptor = "android.content.IContentProvider"; 166 167 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 168 static final int QUERY_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION; 169 static final int GET_TYPE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 1; 170 static final int INSERT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 2; 171 static final int DELETE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 3; 172 static final int UPDATE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 9; 173 static final int BULK_INSERT_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 12; 174 static final int OPEN_FILE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 13; 175 static final int OPEN_ASSET_FILE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 14; 176 static final int APPLY_BATCH_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 19; 177 static final int CALL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 20; 178 static final int GET_STREAM_TYPES_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 21; 179 static final int OPEN_TYPED_ASSET_FILE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 22; 180 static final int CREATE_CANCELATION_SIGNAL_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 23; 181 static final int CANONICALIZE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 24; 182 static final int UNCANONICALIZE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 25; 183 static final int REFRESH_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 26; 184 static final int CHECK_URI_PERMISSION_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 27; 185 int GET_TYPE_ASYNC_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 28; 186 int CANONICALIZE_ASYNC_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 29; 187 int UNCANONICALIZE_ASYNC_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 30; 188 } 189