1 /*
2  * Copyright (C) 2009 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.test.mock;
18 
19 import android.annotation.Nullable;
20 import android.content.ContentProviderOperation;
21 import android.content.ContentProviderResult;
22 import android.content.ContentValues;
23 import android.content.EntityIterator;
24 import android.content.IContentProvider;
25 import android.content.res.AssetFileDescriptor;
26 import android.database.Cursor;
27 import android.net.Uri;
28 import android.os.Bundle;
29 import android.os.IBinder;
30 import android.os.ICancellationSignal;
31 import android.os.ParcelFileDescriptor;
32 import android.os.RemoteException;
33 
34 import java.io.FileNotFoundException;
35 import java.util.ArrayList;
36 
37 /**
38  * Mock implementation of IContentProvider.  All methods are non-functional and throw
39  * {@link java.lang.UnsupportedOperationException}.  Tests can extend this class to
40  * implement behavior needed for tests.
41  *
42  * @hide - @hide because this exposes bulkQuery() and call(), which must also be hidden.
43  */
44 public class MockIContentProvider implements IContentProvider {
45     @Override
bulkInsert(String callingPackage, Uri url, ContentValues[] initialValues)46     public int bulkInsert(String callingPackage, Uri url, ContentValues[] initialValues) {
47         throw new UnsupportedOperationException("unimplemented mock method");
48     }
49 
50     @Override
51     @SuppressWarnings("unused")
delete(String callingPackage, Uri url, String selection, String[] selectionArgs)52     public int delete(String callingPackage, Uri url, String selection, String[] selectionArgs)
53             throws RemoteException {
54         throw new UnsupportedOperationException("unimplemented mock method");
55     }
56 
57     @Override
getType(Uri url)58     public String getType(Uri url) {
59         throw new UnsupportedOperationException("unimplemented mock method");
60     }
61 
62     @Override
63     @SuppressWarnings("unused")
insert(String callingPackage, Uri url, ContentValues initialValues)64     public Uri insert(String callingPackage, Uri url, ContentValues initialValues)
65             throws RemoteException {
66         throw new UnsupportedOperationException("unimplemented mock method");
67     }
68 
69     @Override
openFile( String callingPackage, Uri url, String mode, ICancellationSignal signal, IBinder callerToken)70     public ParcelFileDescriptor openFile(
71             String callingPackage, Uri url, String mode, ICancellationSignal signal,
72             IBinder callerToken) {
73         throw new UnsupportedOperationException("unimplemented mock method");
74     }
75 
76     @Override
openAssetFile( String callingPackage, Uri uri, String mode, ICancellationSignal signal)77     public AssetFileDescriptor openAssetFile(
78             String callingPackage, Uri uri, String mode, ICancellationSignal signal) {
79         throw new UnsupportedOperationException("unimplemented mock method");
80     }
81 
82     @Override
applyBatch(String callingPackage, ArrayList<ContentProviderOperation> operations)83     public ContentProviderResult[] applyBatch(String callingPackage,
84             ArrayList<ContentProviderOperation> operations) {
85         throw new UnsupportedOperationException("unimplemented mock method");
86     }
87 
88     @Override
query(String callingPackage, Uri url, @Nullable String[] projection, @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal)89     public Cursor query(String callingPackage, Uri url, @Nullable String[] projection,
90             @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal) {
91         throw new UnsupportedOperationException("unimplemented mock method");
92     }
93 
queryEntities(Uri url, String selection, String[] selectionArgs, String sortOrder)94     public EntityIterator queryEntities(Uri url, String selection, String[] selectionArgs,
95             String sortOrder) {
96         throw new UnsupportedOperationException("unimplemented mock method");
97     }
98 
99     @Override
update(String callingPackage, Uri url, ContentValues values, String selection, String[] selectionArgs)100     public int update(String callingPackage, Uri url, ContentValues values, String selection,
101             String[] selectionArgs) throws RemoteException {
102         throw new UnsupportedOperationException("unimplemented mock method");
103     }
104 
105     @Override
call(String callingPackage, String method, String request, Bundle args)106     public Bundle call(String callingPackage, String method, String request, Bundle args)
107             throws RemoteException {
108         throw new UnsupportedOperationException("unimplemented mock method");
109     }
110 
111     @Override
asBinder()112     public IBinder asBinder() {
113         throw new UnsupportedOperationException("unimplemented mock method");
114     }
115 
116     @Override
getStreamTypes(Uri url, String mimeTypeFilter)117     public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException {
118         throw new UnsupportedOperationException("unimplemented mock method");
119     }
120 
121     @Override
openTypedAssetFile(String callingPackage, Uri url, String mimeType, Bundle opts, ICancellationSignal signal)122     public AssetFileDescriptor openTypedAssetFile(String callingPackage, Uri url, String mimeType,
123             Bundle opts, ICancellationSignal signal) throws RemoteException, FileNotFoundException {
124         throw new UnsupportedOperationException("unimplemented mock method");
125     }
126 
127     @Override
createCancellationSignal()128     public ICancellationSignal createCancellationSignal() throws RemoteException {
129         throw new UnsupportedOperationException("unimplemented mock method");
130     }
131 
132     @Override
canonicalize(String callingPkg, Uri uri)133     public Uri canonicalize(String callingPkg, Uri uri) throws RemoteException {
134         throw new UnsupportedOperationException("unimplemented mock method");
135     }
136 
137     @Override
uncanonicalize(String callingPkg, Uri uri)138     public Uri uncanonicalize(String callingPkg, Uri uri) throws RemoteException {
139         throw new UnsupportedOperationException("unimplemented mock method");
140     }
141 
142     @Override
refresh(String callingPkg, Uri url, Bundle args, ICancellationSignal cancellationSignal)143     public boolean refresh(String callingPkg, Uri url, Bundle args,
144             ICancellationSignal cancellationSignal) throws RemoteException {
145         throw new UnsupportedOperationException("unimplemented mock method");
146     }
147 }
148