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