blob: 1831bcdf9df7a2b50c0353707fa7f6ce466e6177 [file] [log] [blame]
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +09001/*
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
17package android.test.mock;
18
Steve McKayea93fe72016-12-02 11:35:35 -080019import android.annotation.Nullable;
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090020import android.content.ContentProviderOperation;
21import android.content.ContentProviderResult;
Dmitri Plotnikovd55a3872020-01-16 17:00:02 -080022import android.content.ContentResolver;
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090023import android.content.ContentValues;
24import android.content.EntityIterator;
25import android.content.IContentProvider;
26import android.content.res.AssetFileDescriptor;
27import android.database.Cursor;
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090028import android.net.Uri;
Dmitri Plotnikovd55a3872020-01-16 17:00:02 -080029import android.os.AsyncTask;
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080030import android.os.Bundle;
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090031import android.os.IBinder;
Jeff Browna7771df2012-05-07 20:06:46 -070032import android.os.ICancellationSignal;
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090033import android.os.ParcelFileDescriptor;
Dmitri Plotnikovd55a3872020-01-16 17:00:02 -080034import android.os.RemoteCallback;
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090035import android.os.RemoteException;
36
Dianne Hackborn23fdaf62010-08-06 12:16:55 -070037import java.io.FileNotFoundException;
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090038import java.util.ArrayList;
39
40/**
41 * Mock implementation of IContentProvider. All methods are non-functional and throw
42 * {@link java.lang.UnsupportedOperationException}. Tests can extend this class to
43 * implement behavior needed for tests.
44 *
Brad Fitzpatrick1877d012010-03-04 17:48:13 -080045 * @hide - @hide because this exposes bulkQuery() and call(), which must also be hidden.
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090046 */
47public class MockIContentProvider implements IContentProvider {
Steve McKayea93fe72016-12-02 11:35:35 -080048 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -070049 public int bulkInsert(String callingPackage, @Nullable String featureId, Uri url,
50 ContentValues[] initialValues) {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090051 throw new UnsupportedOperationException("unimplemented mock method");
52 }
53
Steve McKayea93fe72016-12-02 11:35:35 -080054 @Override
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090055 @SuppressWarnings("unused")
Philip P. Moltmann128b7032019-09-27 08:44:12 -070056 public int delete(String callingPackage, @Nullable String featureId, Uri url,
Jeff Sharkeye9fe1522019-11-15 12:45:15 -070057 Bundle extras) throws RemoteException {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090058 throw new UnsupportedOperationException("unimplemented mock method");
59 }
60
Steve McKayea93fe72016-12-02 11:35:35 -080061 @Override
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090062 public String getType(Uri url) {
63 throw new UnsupportedOperationException("unimplemented mock method");
64 }
65
Steve McKayea93fe72016-12-02 11:35:35 -080066 @Override
Dmitri Plotnikovd55a3872020-01-16 17:00:02 -080067 @SuppressWarnings("deprecation")
68 public void getTypeAsync(Uri uri, RemoteCallback remoteCallback) {
69 AsyncTask.SERIAL_EXECUTOR.execute(() -> {
70 final Bundle bundle = new Bundle();
71 bundle.putString(ContentResolver.REMOTE_CALLBACK_RESULT, getType(uri));
72 remoteCallback.sendResult(bundle);
73 });
74 }
75
76 @Override
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090077 @SuppressWarnings("unused")
Philip P. Moltmann128b7032019-09-27 08:44:12 -070078 public Uri insert(String callingPackage, @Nullable String featureId, Uri url,
Jeff Sharkeye9fe1522019-11-15 12:45:15 -070079 ContentValues initialValues, Bundle extras) throws RemoteException {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090080 throw new UnsupportedOperationException("unimplemented mock method");
81 }
82
Steve McKayea93fe72016-12-02 11:35:35 -080083 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -070084 public ParcelFileDescriptor openFile(String callingPackage, @Nullable String featureId,
85 Uri url, String mode, ICancellationSignal signal, IBinder callerToken) {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090086 throw new UnsupportedOperationException("unimplemented mock method");
87 }
88
Steve McKayea93fe72016-12-02 11:35:35 -080089 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -070090 public AssetFileDescriptor openAssetFile(String callingPackage, @Nullable String featureId,
91 Uri uri, String mode, ICancellationSignal signal) {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090092 throw new UnsupportedOperationException("unimplemented mock method");
93 }
94
Steve McKayea93fe72016-12-02 11:35:35 -080095 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -070096 public ContentProviderResult[] applyBatch(String callingPackage, @Nullable String featureId,
97 String authority, ArrayList<ContentProviderOperation> operations) {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +090098 throw new UnsupportedOperationException("unimplemented mock method");
99 }
100
Steve McKayea93fe72016-12-02 11:35:35 -0800101 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700102 public Cursor query(String callingPackage, @Nullable String featureId, Uri url,
103 @Nullable String[] projection, @Nullable Bundle queryArgs,
104 @Nullable ICancellationSignal cancellationSignal) {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +0900105 throw new UnsupportedOperationException("unimplemented mock method");
106 }
107
108 public EntityIterator queryEntities(Uri url, String selection, String[] selectionArgs,
109 String sortOrder) {
110 throw new UnsupportedOperationException("unimplemented mock method");
111 }
112
Steve McKayea93fe72016-12-02 11:35:35 -0800113 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700114 public int update(String callingPackage, @Nullable String featureId, Uri url,
Jeff Sharkeye9fe1522019-11-15 12:45:15 -0700115 ContentValues values, Bundle extras) throws RemoteException {
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +0900116 throw new UnsupportedOperationException("unimplemented mock method");
117 }
118
Steve McKayea93fe72016-12-02 11:35:35 -0800119 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700120 public Bundle call(String callingPackage, @Nullable String featureId, String authority,
121 String method, String request, Bundle args) throws RemoteException {
Brad Fitzpatrick1877d012010-03-04 17:48:13 -0800122 throw new UnsupportedOperationException("unimplemented mock method");
123 }
124
Steve McKayea93fe72016-12-02 11:35:35 -0800125 @Override
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +0900126 public IBinder asBinder() {
127 throw new UnsupportedOperationException("unimplemented mock method");
128 }
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700129
Steve McKayea93fe72016-12-02 11:35:35 -0800130 @Override
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700131 public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException {
132 throw new UnsupportedOperationException("unimplemented mock method");
133 }
134
Steve McKayea93fe72016-12-02 11:35:35 -0800135 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700136 public AssetFileDescriptor openTypedAssetFile(String callingPackage,
137 @Nullable String featureId, Uri url, String mimeType, Bundle opts,
138 ICancellationSignal signal) throws RemoteException, FileNotFoundException {
Dianne Hackborn23fdaf62010-08-06 12:16:55 -0700139 throw new UnsupportedOperationException("unimplemented mock method");
140 }
Jeff Brown75ea64f2012-01-25 19:37:13 -0800141
142 @Override
Jeff Brown4c1241d2012-02-02 17:05:00 -0800143 public ICancellationSignal createCancellationSignal() throws RemoteException {
Jeff Brown75ea64f2012-01-25 19:37:13 -0800144 throw new UnsupportedOperationException("unimplemented mock method");
145 }
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700146
147 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700148 public Uri canonicalize(String callingPkg, @Nullable String featureId, Uri uri)
149 throws RemoteException {
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700150 throw new UnsupportedOperationException("unimplemented mock method");
151 }
152
153 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700154 public Uri uncanonicalize(String callingPkg, @Nullable String featureId, Uri uri)
155 throws RemoteException {
Dianne Hackborn38ed2a42013-09-06 16:17:22 -0700156 throw new UnsupportedOperationException("unimplemented mock method");
157 }
Ben Lin1cf454f2016-11-10 13:50:54 -0800158
159 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700160 public boolean refresh(String callingPkg, @Nullable String featureId, Uri url, Bundle args,
Ben Lin1cf454f2016-11-10 13:50:54 -0800161 ICancellationSignal cancellationSignal) throws RemoteException {
162 throw new UnsupportedOperationException("unimplemented mock method");
163 }
Jeff Sharkey9edef252019-05-20 14:00:17 -0600164
165 /** {@hide} */
166 @Override
Philip P. Moltmann128b7032019-09-27 08:44:12 -0700167 public int checkUriPermission(String callingPkg, @Nullable String featureId, Uri uri, int uid,
168 int modeFlags) {
Jeff Sharkey9edef252019-05-20 14:00:17 -0600169 throw new UnsupportedOperationException("unimplemented mock method call");
170 }
Daisuke Miyakawa8280c2b2009-10-22 08:36:42 +0900171}