Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 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 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 20 | import android.content.ContentProviderOperation; |
| 21 | import android.content.ContentProviderResult; |
Dmitri Plotnikov | d55a387 | 2020-01-16 17:00:02 -0800 | [diff] [blame] | 22 | import android.content.ContentResolver; |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 23 | import android.content.ContentValues; |
| 24 | import android.content.EntityIterator; |
| 25 | import android.content.IContentProvider; |
| 26 | import android.content.res.AssetFileDescriptor; |
| 27 | import android.database.Cursor; |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 28 | import android.net.Uri; |
Dmitri Plotnikov | d55a387 | 2020-01-16 17:00:02 -0800 | [diff] [blame] | 29 | import android.os.AsyncTask; |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 30 | import android.os.Bundle; |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 31 | import android.os.IBinder; |
Jeff Brown | a7771df | 2012-05-07 20:06:46 -0700 | [diff] [blame] | 32 | import android.os.ICancellationSignal; |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 33 | import android.os.ParcelFileDescriptor; |
Dmitri Plotnikov | d55a387 | 2020-01-16 17:00:02 -0800 | [diff] [blame] | 34 | import android.os.RemoteCallback; |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 35 | import android.os.RemoteException; |
| 36 | |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 37 | import java.io.FileNotFoundException; |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 38 | import 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 Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 45 | * @hide - @hide because this exposes bulkQuery() and call(), which must also be hidden. |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 46 | */ |
| 47 | public class MockIContentProvider implements IContentProvider { |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 48 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 49 | public int bulkInsert(String callingPackage, @Nullable String featureId, Uri url, |
| 50 | ContentValues[] initialValues) { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 51 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 52 | } |
| 53 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 54 | @Override |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 55 | @SuppressWarnings("unused") |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 56 | public int delete(String callingPackage, @Nullable String featureId, Uri url, |
Jeff Sharkey | e9fe152 | 2019-11-15 12:45:15 -0700 | [diff] [blame] | 57 | Bundle extras) throws RemoteException { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 58 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 59 | } |
| 60 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 61 | @Override |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 62 | public String getType(Uri url) { |
| 63 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 64 | } |
| 65 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 66 | @Override |
Dmitri Plotnikov | d55a387 | 2020-01-16 17:00:02 -0800 | [diff] [blame] | 67 | @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 Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 77 | @SuppressWarnings("unused") |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 78 | public Uri insert(String callingPackage, @Nullable String featureId, Uri url, |
Jeff Sharkey | e9fe152 | 2019-11-15 12:45:15 -0700 | [diff] [blame] | 79 | ContentValues initialValues, Bundle extras) throws RemoteException { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 80 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 81 | } |
| 82 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 83 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 84 | public ParcelFileDescriptor openFile(String callingPackage, @Nullable String featureId, |
| 85 | Uri url, String mode, ICancellationSignal signal, IBinder callerToken) { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 86 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 87 | } |
| 88 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 89 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 90 | public AssetFileDescriptor openAssetFile(String callingPackage, @Nullable String featureId, |
| 91 | Uri uri, String mode, ICancellationSignal signal) { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 92 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 93 | } |
| 94 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 95 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 96 | public ContentProviderResult[] applyBatch(String callingPackage, @Nullable String featureId, |
| 97 | String authority, ArrayList<ContentProviderOperation> operations) { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 98 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 99 | } |
| 100 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 101 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 102 | public Cursor query(String callingPackage, @Nullable String featureId, Uri url, |
| 103 | @Nullable String[] projection, @Nullable Bundle queryArgs, |
| 104 | @Nullable ICancellationSignal cancellationSignal) { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 105 | 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 McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 113 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 114 | public int update(String callingPackage, @Nullable String featureId, Uri url, |
Jeff Sharkey | e9fe152 | 2019-11-15 12:45:15 -0700 | [diff] [blame] | 115 | ContentValues values, Bundle extras) throws RemoteException { |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 116 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 117 | } |
| 118 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 119 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 120 | public Bundle call(String callingPackage, @Nullable String featureId, String authority, |
| 121 | String method, String request, Bundle args) throws RemoteException { |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 122 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 123 | } |
| 124 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 125 | @Override |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 126 | public IBinder asBinder() { |
| 127 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 128 | } |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 129 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 130 | @Override |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 131 | public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException { |
| 132 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 133 | } |
| 134 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 135 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 136 | public AssetFileDescriptor openTypedAssetFile(String callingPackage, |
| 137 | @Nullable String featureId, Uri url, String mimeType, Bundle opts, |
| 138 | ICancellationSignal signal) throws RemoteException, FileNotFoundException { |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 139 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 140 | } |
Jeff Brown | 75ea64f | 2012-01-25 19:37:13 -0800 | [diff] [blame] | 141 | |
| 142 | @Override |
Jeff Brown | 4c1241d | 2012-02-02 17:05:00 -0800 | [diff] [blame] | 143 | public ICancellationSignal createCancellationSignal() throws RemoteException { |
Jeff Brown | 75ea64f | 2012-01-25 19:37:13 -0800 | [diff] [blame] | 144 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 145 | } |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 146 | |
| 147 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 148 | public Uri canonicalize(String callingPkg, @Nullable String featureId, Uri uri) |
| 149 | throws RemoteException { |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 150 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 151 | } |
| 152 | |
| 153 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 154 | public Uri uncanonicalize(String callingPkg, @Nullable String featureId, Uri uri) |
| 155 | throws RemoteException { |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 156 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 157 | } |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 158 | |
| 159 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 160 | public boolean refresh(String callingPkg, @Nullable String featureId, Uri url, Bundle args, |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 161 | ICancellationSignal cancellationSignal) throws RemoteException { |
| 162 | throw new UnsupportedOperationException("unimplemented mock method"); |
| 163 | } |
Jeff Sharkey | 9edef25 | 2019-05-20 14:00:17 -0600 | [diff] [blame] | 164 | |
| 165 | /** {@hide} */ |
| 166 | @Override |
Philip P. Moltmann | 128b703 | 2019-09-27 08:44:12 -0700 | [diff] [blame] | 167 | public int checkUriPermission(String callingPkg, @Nullable String featureId, Uri uri, int uid, |
| 168 | int modeFlags) { |
Jeff Sharkey | 9edef25 | 2019-05-20 14:00:17 -0600 | [diff] [blame] | 169 | throw new UnsupportedOperationException("unimplemented mock method call"); |
| 170 | } |
Daisuke Miyakawa | 8280c2b | 2009-10-22 08:36:42 +0900 | [diff] [blame] | 171 | } |