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