diff options
author | 2017-11-15 11:39:14 +0000 | |
---|---|---|
committer | 2017-11-16 13:15:29 +0000 | |
commit | e254526f0fe5d22681555bd4a00b7ee96fee1dc1 (patch) | |
tree | c8e450764c8d6704bdac446117634951822f7675 /test-mock/src | |
parent | 42753a512e2719ca078851a62760a19890641e6f (diff) |
Separate android.test.mock from test-runner source
Extracts the source for the android.test.mock library from the
frameworks/base/test-runner directory into its own
frameworks/base/test-mock directory. They are already treated separately
at runtime and compile time so this just makes the separation complete.
Bug: 30188076
Test: make checkbuild
Change-Id: I20e5b06ba79677e76117c82e9f9e2ecd15e5fed6
Diffstat (limited to 'test-mock/src')
-rw-r--r-- | test-mock/src/android/test/mock/MockApplication.java | 51 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockContentProvider.java | 280 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockContentResolver.java | 146 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockContext.java | 847 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockCursor.java | 247 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockDialogInterface.java | 39 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockIContentProvider.java | 147 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockPackageManager.java | 1187 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/MockResources.java | 227 | ||||
-rw-r--r-- | test-mock/src/android/test/mock/package.html | 10 |
10 files changed, 3181 insertions, 0 deletions
diff --git a/test-mock/src/android/test/mock/MockApplication.java b/test-mock/src/android/test/mock/MockApplication.java new file mode 100644 index 000000000000..3257ecf11066 --- /dev/null +++ b/test-mock/src/android/test/mock/MockApplication.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.app.Application; +import android.content.res.Configuration; + +/** + * A mock {@link android.app.Application} class. All methods are non-functional and throw + * {@link java.lang.UnsupportedOperationException}. Override it as necessary to provide the + * operations that you need. + * + * @deprecated Use a mocking framework like <a href="https://github.com/mockito/mockito">Mockito</a>. + * New tests should be written using the + * <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>. + */ +@Deprecated +public class MockApplication extends Application { + + public MockApplication() { + } + + @Override + public void onCreate() { + throw new UnsupportedOperationException(); + } + + @Override + public void onTerminate() { + throw new UnsupportedOperationException(); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + throw new UnsupportedOperationException(); + } +} diff --git a/test-mock/src/android/test/mock/MockContentProvider.java b/test-mock/src/android/test/mock/MockContentProvider.java new file mode 100644 index 000000000000..d5f3ce880b8f --- /dev/null +++ b/test-mock/src/android/test/mock/MockContentProvider.java @@ -0,0 +1,280 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.annotation.Nullable; +import android.content.ContentProvider; +import android.content.ContentProviderOperation; +import android.content.ContentProviderResult; +import android.content.ContentValues; +import android.content.Context; +import android.content.IContentProvider; +import android.content.OperationApplicationException; +import android.content.pm.PathPermission; +import android.content.pm.ProviderInfo; +import android.content.res.AssetFileDescriptor; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.os.IBinder; +import android.os.ICancellationSignal; +import android.os.ParcelFileDescriptor; +import android.os.RemoteException; + +import java.io.FileNotFoundException; +import java.util.ArrayList; + +/** + * Mock implementation of ContentProvider. All methods are non-functional and throw + * {@link java.lang.UnsupportedOperationException}. Tests can extend this class to + * implement behavior needed for tests. + */ +public class MockContentProvider extends ContentProvider { + /* + * Note: if you add methods to ContentProvider, you must add similar methods to + * MockContentProvider. + */ + + /** + * IContentProvider that directs all calls to this MockContentProvider. + */ + private class InversionIContentProvider implements IContentProvider { + @Override + public ContentProviderResult[] applyBatch(String callingPackage, + ArrayList<ContentProviderOperation> operations) + throws RemoteException, OperationApplicationException { + return MockContentProvider.this.applyBatch(operations); + } + + @Override + public int bulkInsert(String callingPackage, Uri url, ContentValues[] initialValues) + throws RemoteException { + return MockContentProvider.this.bulkInsert(url, initialValues); + } + + @Override + public int delete(String callingPackage, Uri url, String selection, String[] selectionArgs) + throws RemoteException { + return MockContentProvider.this.delete(url, selection, selectionArgs); + } + + @Override + public String getType(Uri url) throws RemoteException { + return MockContentProvider.this.getType(url); + } + + @Override + public Uri insert(String callingPackage, Uri url, ContentValues initialValues) + throws RemoteException { + return MockContentProvider.this.insert(url, initialValues); + } + + @Override + public AssetFileDescriptor openAssetFile( + String callingPackage, Uri url, String mode, ICancellationSignal signal) + throws RemoteException, FileNotFoundException { + return MockContentProvider.this.openAssetFile(url, mode); + } + + @Override + public ParcelFileDescriptor openFile( + String callingPackage, Uri url, String mode, ICancellationSignal signal, + IBinder callerToken) throws RemoteException, FileNotFoundException { + return MockContentProvider.this.openFile(url, mode); + } + + @Override + public Cursor query(String callingPackage, Uri url, @Nullable String[] projection, + @Nullable Bundle queryArgs, + @Nullable ICancellationSignal cancellationSignal) + throws RemoteException { + return MockContentProvider.this.query(url, projection, queryArgs, null); + } + + @Override + public int update(String callingPackage, Uri url, ContentValues values, String selection, + String[] selectionArgs) throws RemoteException { + return MockContentProvider.this.update(url, values, selection, selectionArgs); + } + + @Override + public Bundle call(String callingPackage, String method, String request, Bundle args) + throws RemoteException { + return MockContentProvider.this.call(method, request, args); + } + + @Override + public IBinder asBinder() { + throw new UnsupportedOperationException(); + } + + @Override + public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException { + return MockContentProvider.this.getStreamTypes(url, mimeTypeFilter); + } + + @Override + public AssetFileDescriptor openTypedAssetFile(String callingPackage, Uri url, + String mimeType, Bundle opts, ICancellationSignal signal) + throws RemoteException, FileNotFoundException { + return MockContentProvider.this.openTypedAssetFile(url, mimeType, opts); + } + + @Override + public ICancellationSignal createCancellationSignal() throws RemoteException { + return null; + } + + @Override + public Uri canonicalize(String callingPkg, Uri uri) throws RemoteException { + return MockContentProvider.this.canonicalize(uri); + } + + @Override + public Uri uncanonicalize(String callingPkg, Uri uri) throws RemoteException { + return MockContentProvider.this.uncanonicalize(uri); + } + + @Override + public boolean refresh(String callingPkg, Uri url, Bundle args, + ICancellationSignal cancellationSignal) throws RemoteException { + return MockContentProvider.this.refresh(url, args); + } + } + private final InversionIContentProvider mIContentProvider = new InversionIContentProvider(); + + /** + * A constructor using {@link MockContext} instance as a Context in it. + */ + protected MockContentProvider() { + super(new MockContext(), "", "", null); + } + + /** + * A constructor accepting a Context instance, which is supposed to be the subclasss of + * {@link MockContext}. + */ + public MockContentProvider(Context context) { + super(context, "", "", null); + } + + /** + * A constructor which initialize four member variables which + * {@link android.content.ContentProvider} have internally. + * + * @param context A Context object which should be some mock instance (like the + * instance of {@link android.test.mock.MockContext}). + * @param readPermission The read permision you want this instance should have in the + * test, which is available via {@link #getReadPermission()}. + * @param writePermission The write permission you want this instance should have + * in the test, which is available via {@link #getWritePermission()}. + * @param pathPermissions The PathPermissions you want this instance should have + * in the test, which is available via {@link #getPathPermissions()}. + */ + public MockContentProvider(Context context, + String readPermission, + String writePermission, + PathPermission[] pathPermissions) { + super(context, readPermission, writePermission, pathPermissions); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public String getType(Uri uri) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean onCreate() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, + String sortOrder) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + /** + * If you're reluctant to implement this manually, please just call super.bulkInsert(). + */ + @Override + public int bulkInsert(Uri uri, ContentValues[] values) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void attachInfo(Context context, ProviderInfo info) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + /** + * @hide + */ + @Override + public Bundle call(String method, String request, Bundle args) { + throw new UnsupportedOperationException("unimplemented mock method call"); + } + + @Override + public String[] getStreamTypes(Uri url, String mimeTypeFilter) { + throw new UnsupportedOperationException("unimplemented mock method call"); + } + + @Override + public AssetFileDescriptor openTypedAssetFile(Uri url, String mimeType, Bundle opts) { + throw new UnsupportedOperationException("unimplemented mock method call"); + } + + /** + * @hide + */ + public boolean refresh(Uri url, Bundle args) { + throw new UnsupportedOperationException("unimplemented mock method call"); + } + + /** + * Returns IContentProvider which calls back same methods in this class. + * By overriding this class, we avoid the mechanism hidden behind ContentProvider + * (IPC, etc.) + * + * @hide + */ + @Override + public final IContentProvider getIContentProvider() { + return mIContentProvider; + } +} diff --git a/test-mock/src/android/test/mock/MockContentResolver.java b/test-mock/src/android/test/mock/MockContentResolver.java new file mode 100644 index 000000000000..a70152c8b732 --- /dev/null +++ b/test-mock/src/android/test/mock/MockContentResolver.java @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.content.ContentProvider; +import android.content.ContentResolver; +import android.content.Context; +import android.content.IContentProvider; +import android.database.ContentObserver; +import android.net.Uri; + +import java.util.HashMap; +import java.util.Map; + +/** + * <p> + * An extension of {@link android.content.ContentResolver} that is designed for + * testing. + * </p> + * <p> + * MockContentResolver overrides Android's normal way of resolving providers by + * authority. To have access to a provider based on its authority, users of + * MockContentResolver first instantiate the provider and + * use {@link MockContentResolver#addProvider(String, ContentProvider)}. Resolution of an + * authority occurs entirely within MockContentResolver. + * </p> + * <p> + * Users can also set an authority's entry in the map to null, so that a provider is completely + * mocked out. + * </p> + * + * <div class="special reference"> + * <h3>Developer Guides</h3> + * <p>For more information about application testing, read the + * <a href="{@docRoot}guide/topics/testing/index.html">Testing</a> developer guide.</p> + * </div> + */ +public class MockContentResolver extends ContentResolver { + Map<String, ContentProvider> mProviders; + + /** + * Creates a local map of providers. This map is used instead of the global + * map when an API call tries to acquire a provider. + */ + public MockContentResolver() { + this(null); + } + + /** + * Creates a local map of providers. This map is used instead of the global + * map when an API call tries to acquire a provider. + */ + public MockContentResolver(Context context) { + super(context); + mProviders = new HashMap<>(); + } + + /** + * Adds access to a provider based on its authority + * + * @param name The authority name associated with the provider. + * @param provider An instance of {@link android.content.ContentProvider} or one of its + * subclasses, or null. + */ + public void addProvider(String name, ContentProvider provider) { + + /* + * Maps the authority to the provider locally. + */ + mProviders.put(name, provider); + } + + /** @hide */ + @Override + protected IContentProvider acquireProvider(Context context, String name) { + return acquireExistingProvider(context, name); + } + + /** @hide */ + @Override + protected IContentProvider acquireExistingProvider(Context context, String name) { + + /* + * Gets the content provider from the local map + */ + final ContentProvider provider = mProviders.get(name); + + if (provider != null) { + return provider.getIContentProvider(); + } else { + return null; + } + } + + /** @hide */ + @Override + public boolean releaseProvider(IContentProvider provider) { + return true; + } + + /** @hide */ + @Override + protected IContentProvider acquireUnstableProvider(Context c, String name) { + return acquireProvider(c, name); + } + + /** @hide */ + @Override + public boolean releaseUnstableProvider(IContentProvider icp) { + return releaseProvider(icp); + } + + /** @hide */ + @Override + public void unstableProviderDied(IContentProvider icp) { + } + + /** + * Overrides {@link android.content.ContentResolver#notifyChange(Uri, ContentObserver, boolean) + * ContentResolver.notifChange(Uri, ContentObserver, boolean)}. All parameters are ignored. + * The method hides providers linked to MockContentResolver from other observers in the system. + * + * @param uri (Ignored) The uri of the content provider. + * @param observer (Ignored) The observer that originated the change. + * @param syncToNetwork (Ignored) If true, attempt to sync the change to the network. + */ + @Override + public void notifyChange(Uri uri, + ContentObserver observer, + boolean syncToNetwork) { + } +} diff --git a/test-mock/src/android/test/mock/MockContext.java b/test-mock/src/android/test/mock/MockContext.java new file mode 100644 index 000000000000..5e5ba462cfca --- /dev/null +++ b/test-mock/src/android/test/mock/MockContext.java @@ -0,0 +1,847 @@ +/* + * Copyright (C) 2007 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.annotation.SystemApi; +import android.app.IApplicationThread; +import android.app.IServiceConnection; +import android.app.Notification; +import android.content.ComponentName; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.BroadcastReceiver; +import android.content.IntentSender; +import android.content.ServiceConnection; +import android.content.SharedPreferences; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; +import android.content.res.AssetManager; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.database.DatabaseErrorHandler; +import android.database.sqlite.SQLiteDatabase; +import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.IBinder; +import android.os.Looper; +import android.os.UserHandle; +import android.view.DisplayAdjustments; +import android.view.Display; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * A mock {@link android.content.Context} class. All methods are non-functional and throw + * {@link java.lang.UnsupportedOperationException}. You can use this to inject other dependencies, + * mocks, or monitors into the classes you are testing. + */ +public class MockContext extends Context { + + @Override + public AssetManager getAssets() { + throw new UnsupportedOperationException(); + } + + @Override + public Resources getResources() { + throw new UnsupportedOperationException(); + } + + @Override + public PackageManager getPackageManager() { + throw new UnsupportedOperationException(); + } + + @Override + public ContentResolver getContentResolver() { + throw new UnsupportedOperationException(); + } + + @Override + public Looper getMainLooper() { + throw new UnsupportedOperationException(); + } + + @Override + public Context getApplicationContext() { + throw new UnsupportedOperationException(); + } + + @Override + public void setTheme(int resid) { + throw new UnsupportedOperationException(); + } + + @Override + public Resources.Theme getTheme() { + throw new UnsupportedOperationException(); + } + + @Override + public ClassLoader getClassLoader() { + throw new UnsupportedOperationException(); + } + + @Override + public String getPackageName() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public String getBasePackageName() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public String getOpPackageName() { + throw new UnsupportedOperationException(); + } + + @Override + public ApplicationInfo getApplicationInfo() { + throw new UnsupportedOperationException(); + } + + @Override + public String getPackageResourcePath() { + throw new UnsupportedOperationException(); + } + + @Override + public String getPackageCodePath() { + throw new UnsupportedOperationException(); + } + + @Override + public SharedPreferences getSharedPreferences(String name, int mode) { + throw new UnsupportedOperationException(); + } + + /** @removed */ + @Override + public SharedPreferences getSharedPreferences(File file, int mode) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void reloadSharedPreferences() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean moveSharedPreferencesFrom(Context sourceContext, String name) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean deleteSharedPreferences(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public FileInputStream openFileInput(String name) throws FileNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public FileOutputStream openFileOutput(String name, int mode) throws FileNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public boolean deleteFile(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public File getFileStreamPath(String name) { + throw new UnsupportedOperationException(); + } + + /** @removed */ + @Override + public File getSharedPreferencesPath(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public String[] fileList() { + throw new UnsupportedOperationException(); + } + + @Override + public File getDataDir() { + throw new UnsupportedOperationException(); + } + + @Override + public File getFilesDir() { + throw new UnsupportedOperationException(); + } + + @Override + public File getNoBackupFilesDir() { + throw new UnsupportedOperationException(); + } + + @Override + public File getExternalFilesDir(String type) { + throw new UnsupportedOperationException(); + } + + @Override + public File getObbDir() { + throw new UnsupportedOperationException(); + } + + @Override + public File getCacheDir() { + throw new UnsupportedOperationException(); + } + + @Override + public File getCodeCacheDir() { + throw new UnsupportedOperationException(); + } + + @Override + public File getExternalCacheDir() { + throw new UnsupportedOperationException(); + } + + @Override + public File getDir(String name, int mode) { + throw new UnsupportedOperationException(); + } + + @Override + public SQLiteDatabase openOrCreateDatabase(String file, int mode, + SQLiteDatabase.CursorFactory factory) { + throw new UnsupportedOperationException(); + } + + @Override + public SQLiteDatabase openOrCreateDatabase(String file, int mode, + SQLiteDatabase.CursorFactory factory, DatabaseErrorHandler errorHandler) { + throw new UnsupportedOperationException(); + } + + @Override + public File getDatabasePath(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public String[] databaseList() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean moveDatabaseFrom(Context sourceContext, String name) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean deleteDatabase(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getWallpaper() { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable peekWallpaper() { + throw new UnsupportedOperationException(); + } + + @Override + public int getWallpaperDesiredMinimumWidth() { + throw new UnsupportedOperationException(); + } + + @Override + public int getWallpaperDesiredMinimumHeight() { + throw new UnsupportedOperationException(); + } + + @Override + public void setWallpaper(Bitmap bitmap) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void setWallpaper(InputStream data) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void clearWallpaper() { + throw new UnsupportedOperationException(); + } + + @Override + public void startActivity(Intent intent) { + throw new UnsupportedOperationException(); + } + + @Override + public void startActivity(Intent intent, Bundle options) { + startActivity(intent); + } + + @Override + public void startActivities(Intent[] intents) { + throw new UnsupportedOperationException(); + } + + @Override + public void startActivities(Intent[] intents, Bundle options) { + startActivities(intents); + } + + @Override + public void startIntentSender(IntentSender intent, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags) + throws IntentSender.SendIntentException { + throw new UnsupportedOperationException(); + } + + @Override + public void startIntentSender(IntentSender intent, + Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, + Bundle options) throws IntentSender.SendIntentException { + startIntentSender(intent, fillInIntent, flagsMask, flagsValues, extraFlags); + } + + @Override + public void sendBroadcast(Intent intent) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendBroadcast(Intent intent, String receiverPermission) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void sendBroadcastMultiplePermissions(Intent intent, String[] receiverPermissions) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @SystemApi + @Override + public void sendBroadcast(Intent intent, String receiverPermission, Bundle options) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void sendBroadcast(Intent intent, String receiverPermission, int appOp) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendOrderedBroadcast(Intent intent, + String receiverPermission) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendOrderedBroadcast(Intent intent, String receiverPermission, + BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, + Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @SystemApi + @Override + public void sendOrderedBroadcast(Intent intent, String receiverPermission, + Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, + Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void sendOrderedBroadcast(Intent intent, String receiverPermission, int appOp, + BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, + Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendBroadcastAsUser(Intent intent, UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendBroadcastAsUser(Intent intent, UserHandle user, + String receiverPermission) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @SystemApi + @Override + public void sendBroadcastAsUser(Intent intent, UserHandle user, + String receiverPermission, Bundle options) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void sendBroadcastAsUser(Intent intent, UserHandle user, + String receiverPermission, int appOp) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, + String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, + int initialCode, String initialData, Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, + String receiverPermission, int appOp, BroadcastReceiver resultReceiver, + Handler scheduler, int initialCode, String initialData, Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void sendOrderedBroadcastAsUser(Intent intent, UserHandle user, + String receiverPermission, int appOp, Bundle options, BroadcastReceiver resultReceiver, + Handler scheduler, int initialCode, String initialData, Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendStickyBroadcast(Intent intent) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendStickyOrderedBroadcast(Intent intent, + BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, + Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + @Override + public void removeStickyBroadcast(Intent intent) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendStickyBroadcastAsUser(Intent intent, UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void sendStickyBroadcastAsUser(Intent intent, UserHandle user, Bundle options) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendStickyOrderedBroadcastAsUser(Intent intent, + UserHandle user, BroadcastReceiver resultReceiver, + Handler scheduler, int initialCode, String initialData, + Bundle initialExtras) { + throw new UnsupportedOperationException(); + } + + @Override + public void removeStickyBroadcastAsUser(Intent intent, UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override + public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) { + throw new UnsupportedOperationException(); + } + + @Override + public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, + int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, + String broadcastPermission, Handler scheduler) { + throw new UnsupportedOperationException(); + } + + @Override + public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, + String broadcastPermission, Handler scheduler, int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, + IntentFilter filter, String broadcastPermission, Handler scheduler) { + throw new UnsupportedOperationException(); + } + + @Override + public void unregisterReceiver(BroadcastReceiver receiver) { + throw new UnsupportedOperationException(); + } + + @Override + public ComponentName startService(Intent service) { + throw new UnsupportedOperationException(); + } + + @Override + public ComponentName startForegroundService(Intent service) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean stopService(Intent service) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public ComponentName startServiceAsUser(Intent service, UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public ComponentName startForegroundServiceAsUser(Intent service, UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean stopServiceAsUser(Intent service, UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean bindService(Intent service, ServiceConnection conn, int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean bindServiceAsUser(Intent service, ServiceConnection conn, int flags, + UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override + public void unbindService(ServiceConnection conn) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean startInstrumentation(ComponentName className, + String profileFile, Bundle arguments) { + throw new UnsupportedOperationException(); + } + + @Override + public Object getSystemService(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public String getSystemServiceName(Class<?> serviceClass) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkPermission(String permission, int pid, int uid) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public int checkPermission(String permission, int pid, int uid, IBinder callerToken) { + return checkPermission(permission, pid, uid); + } + + @Override + public int checkCallingPermission(String permission) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkCallingOrSelfPermission(String permission) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkSelfPermission(String permission) { + throw new UnsupportedOperationException(); + } + + @Override + public void enforcePermission( + String permission, int pid, int uid, String message) { + throw new UnsupportedOperationException(); + } + + @Override + public void enforceCallingPermission(String permission, String message) { + throw new UnsupportedOperationException(); + } + + @Override + public void enforceCallingOrSelfPermission(String permission, String message) { + throw new UnsupportedOperationException(); + } + + @Override + public void grantUriPermission(String toPackage, Uri uri, int modeFlags) { + throw new UnsupportedOperationException(); + } + + @Override + public void revokeUriPermission(Uri uri, int modeFlags) { + throw new UnsupportedOperationException(); + } + + @Override + public void revokeUriPermission(String targetPackage, Uri uri, int modeFlags) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public int checkUriPermission(Uri uri, int pid, int uid, int modeFlags, IBinder callerToken) { + return checkUriPermission(uri, pid, uid, modeFlags); + } + + @Override + public int checkCallingUriPermission(Uri uri, int modeFlags) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkCallingOrSelfUriPermission(Uri uri, int modeFlags) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkUriPermission(Uri uri, String readPermission, + String writePermission, int pid, int uid, int modeFlags) { + throw new UnsupportedOperationException(); + } + + @Override + public void enforceUriPermission( + Uri uri, int pid, int uid, int modeFlags, String message) { + throw new UnsupportedOperationException(); + } + + @Override + public void enforceCallingUriPermission( + Uri uri, int modeFlags, String message) { + throw new UnsupportedOperationException(); + } + + @Override + public void enforceCallingOrSelfUriPermission( + Uri uri, int modeFlags, String message) { + throw new UnsupportedOperationException(); + } + + public void enforceUriPermission( + Uri uri, String readPermission, String writePermission, + int pid, int uid, int modeFlags, String message) { + throw new UnsupportedOperationException(); + } + + @Override + public Context createPackageContext(String packageName, int flags) + throws PackageManager.NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public Context createApplicationContext(ApplicationInfo application, int flags) + throws PackageManager.NameNotFoundException { + return null; + } + + /** @hide */ + @Override + public Context createContextForSplit(String splitName) + throws PackageManager.NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public Context createPackageContextAsUser(String packageName, int flags, UserHandle user) + throws PackageManager.NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public int getUserId() { + throw new UnsupportedOperationException(); + } + + @Override + public Context createConfigurationContext(Configuration overrideConfiguration) { + throw new UnsupportedOperationException(); + } + + @Override + public Context createDisplayContext(Display display) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isRestricted() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public DisplayAdjustments getDisplayAdjustments(int displayId) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public Display getDisplay() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void updateDisplay(int displayId) { + throw new UnsupportedOperationException(); + } + + @Override + public File[] getExternalFilesDirs(String type) { + throw new UnsupportedOperationException(); + } + + @Override + public File[] getObbDirs() { + throw new UnsupportedOperationException(); + } + + @Override + public File[] getExternalCacheDirs() { + throw new UnsupportedOperationException(); + } + + @Override + public File[] getExternalMediaDirs() { + throw new UnsupportedOperationException(); + } + + /** @hide **/ + @Override + public File getPreloadsFileCache() { throw new UnsupportedOperationException(); } + + @Override + public Context createDeviceProtectedStorageContext() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @SystemApi + @Override + public Context createCredentialProtectedStorageContext() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isDeviceProtectedStorage() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @SystemApi + @Override + public boolean isCredentialProtectedStorage() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public boolean canLoadUnsafeResources() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public IBinder getActivityToken() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public IServiceConnection getServiceDispatcher(ServiceConnection conn, Handler handler, + int flags) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public IApplicationThread getIApplicationThread() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public Handler getMainThreadHandler() { + throw new UnsupportedOperationException(); + } +} diff --git a/test-mock/src/android/test/mock/MockCursor.java b/test-mock/src/android/test/mock/MockCursor.java new file mode 100644 index 000000000000..576f24ad6384 --- /dev/null +++ b/test-mock/src/android/test/mock/MockCursor.java @@ -0,0 +1,247 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.content.ContentResolver; +import android.database.CharArrayBuffer; +import android.database.ContentObserver; +import android.database.Cursor; +import android.database.DataSetObserver; +import android.net.Uri; +import android.os.Bundle; + +/** + * A mock {@link android.database.Cursor} class that isolates the test code from real + * Cursor implementation. + * + * <p> + * All methods including ones related to querying the state of the cursor are + * are non-functional and throw {@link java.lang.UnsupportedOperationException}. + * + * @deprecated Use a mocking framework like <a href="https://github.com/mockito/mockito">Mockito</a>. + * New tests should be written using the + * <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>. + */ +@Deprecated +public class MockCursor implements Cursor { + @Override + public int getColumnCount() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int getColumnIndex(String columnName) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int getColumnIndexOrThrow(String columnName) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public String getColumnName(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public String[] getColumnNames() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int getCount() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean isNull(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int getInt(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public long getLong(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public short getShort(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public float getFloat(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public double getDouble(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public byte[] getBlob(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public String getString(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void setExtras(Bundle extras) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Bundle getExtras() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int getPosition() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean isAfterLast() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean isBeforeFirst() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean isFirst() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean isLast() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean move(int offset) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean moveToFirst() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean moveToLast() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean moveToNext() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean moveToPrevious() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean moveToPosition(int position) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void copyStringToBuffer(int columnIndex, CharArrayBuffer buffer) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + @Deprecated + public void deactivate() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void close() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean isClosed() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + @Deprecated + public boolean requery() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void registerContentObserver(ContentObserver observer) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void registerDataSetObserver(DataSetObserver observer) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Bundle respond(Bundle extras) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean getWantsAllOnMoveCalls() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void setNotificationUri(ContentResolver cr, Uri uri) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Uri getNotificationUri() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void unregisterContentObserver(ContentObserver observer) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public void unregisterDataSetObserver(DataSetObserver observer) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int getType(int columnIndex) { + throw new UnsupportedOperationException("unimplemented mock method"); + } +}
\ No newline at end of file diff --git a/test-mock/src/android/test/mock/MockDialogInterface.java b/test-mock/src/android/test/mock/MockDialogInterface.java new file mode 100644 index 000000000000..d0a5a097918d --- /dev/null +++ b/test-mock/src/android/test/mock/MockDialogInterface.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.content.DialogInterface; + +/** + * A mock {@link android.content.DialogInterface} class. All methods are non-functional and throw + * {@link java.lang.UnsupportedOperationException}. Override it to provide the operations that you + * need. + * + * @deprecated Use a mocking framework like <a href="https://github.com/mockito/mockito">Mockito</a>. + * New tests should be written using the + * <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>. + */ +@Deprecated +public class MockDialogInterface implements DialogInterface { + public void cancel() { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void dismiss() { + throw new UnsupportedOperationException("not implemented yet"); + } +} diff --git a/test-mock/src/android/test/mock/MockIContentProvider.java b/test-mock/src/android/test/mock/MockIContentProvider.java new file mode 100644 index 000000000000..112d7eef3dbe --- /dev/null +++ b/test-mock/src/android/test/mock/MockIContentProvider.java @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.annotation.Nullable; +import android.content.ContentProviderOperation; +import android.content.ContentProviderResult; +import android.content.ContentValues; +import android.content.EntityIterator; +import android.content.IContentProvider; +import android.content.res.AssetFileDescriptor; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.os.IBinder; +import android.os.ICancellationSignal; +import android.os.ParcelFileDescriptor; +import android.os.RemoteException; + +import java.io.FileNotFoundException; +import java.util.ArrayList; + +/** + * Mock implementation of IContentProvider. All methods are non-functional and throw + * {@link java.lang.UnsupportedOperationException}. Tests can extend this class to + * implement behavior needed for tests. + * + * @hide - @hide because this exposes bulkQuery() and call(), which must also be hidden. + */ +public class MockIContentProvider implements IContentProvider { + @Override + public int bulkInsert(String callingPackage, Uri url, ContentValues[] initialValues) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + @SuppressWarnings("unused") + public int delete(String callingPackage, Uri url, String selection, String[] selectionArgs) + throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public String getType(Uri url) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + @SuppressWarnings("unused") + public Uri insert(String callingPackage, Uri url, ContentValues initialValues) + throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public ParcelFileDescriptor openFile( + String callingPackage, Uri url, String mode, ICancellationSignal signal, + IBinder callerToken) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public AssetFileDescriptor openAssetFile( + String callingPackage, Uri uri, String mode, ICancellationSignal signal) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public ContentProviderResult[] applyBatch(String callingPackage, + ArrayList<ContentProviderOperation> operations) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Cursor query(String callingPackage, Uri url, @Nullable String[] projection, + @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + public EntityIterator queryEntities(Uri url, String selection, String[] selectionArgs, + String sortOrder) { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public int update(String callingPackage, Uri url, ContentValues values, String selection, + String[] selectionArgs) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Bundle call(String callingPackage, String method, String request, Bundle args) + throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public IBinder asBinder() { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public AssetFileDescriptor openTypedAssetFile(String callingPackage, Uri url, String mimeType, + Bundle opts, ICancellationSignal signal) throws RemoteException, FileNotFoundException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public ICancellationSignal createCancellationSignal() throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Uri canonicalize(String callingPkg, Uri uri) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public Uri uncanonicalize(String callingPkg, Uri uri) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } + + @Override + public boolean refresh(String callingPkg, Uri url, Bundle args, + ICancellationSignal cancellationSignal) throws RemoteException { + throw new UnsupportedOperationException("unimplemented mock method"); + } +} diff --git a/test-mock/src/android/test/mock/MockPackageManager.java b/test-mock/src/android/test/mock/MockPackageManager.java new file mode 100644 index 000000000000..7e08f51cd87d --- /dev/null +++ b/test-mock/src/android/test/mock/MockPackageManager.java @@ -0,0 +1,1187 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.app.PackageInstallObserver; +import android.content.ComponentName; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.IntentSender; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.ChangedPackages; +import android.content.pm.InstantAppInfo; +import android.content.pm.FeatureInfo; +import android.content.pm.IPackageDataObserver; +import android.content.pm.IPackageDeleteObserver; +import android.content.pm.IPackageInstallObserver; +import android.content.pm.IPackageStatsObserver; +import android.content.pm.InstrumentationInfo; +import android.content.pm.IntentFilterVerificationInfo; +import android.content.pm.KeySet; +import android.content.pm.PackageInfo; +import android.content.pm.PackageInstaller; +import android.content.pm.PackageItemInfo; +import android.content.pm.PackageManager; +import android.content.pm.PermissionGroupInfo; +import android.content.pm.PermissionInfo; +import android.content.pm.ProviderInfo; +import android.content.pm.ResolveInfo; +import android.content.pm.ServiceInfo; +import android.content.pm.SharedLibraryInfo; +import android.content.pm.VerifierDeviceIdentity; +import android.content.pm.VersionedPackage; +import android.content.res.Resources; +import android.content.res.XmlResourceParser; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.net.Uri; +import android.os.Handler; +import android.os.UserHandle; +import android.os.storage.VolumeInfo; + +import java.util.List; + +/** + * A mock {@link android.content.pm.PackageManager} class. All methods are non-functional and throw + * {@link java.lang.UnsupportedOperationException}. Override it to provide the operations that you + * need. + * + * @deprecated Use a mocking framework like <a href="https://github.com/mockito/mockito">Mockito</a>. + * New tests should be written using the + * <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>. + */ +@Deprecated +public class MockPackageManager extends PackageManager { + + @Override + public PackageInfo getPackageInfo(String packageName, int flags) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public PackageInfo getPackageInfo(VersionedPackage versionedPackage, + int flags) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public String[] currentToCanonicalPackageNames(String[] names) { + throw new UnsupportedOperationException(); + } + + @Override + public String[] canonicalToCurrentPackageNames(String[] names) { + throw new UnsupportedOperationException(); + } + + @Override + public Intent getLaunchIntentForPackage(String packageName) { + throw new UnsupportedOperationException(); + } + + @Override + public Intent getLeanbackLaunchIntentForPackage(String packageName) { + throw new UnsupportedOperationException(); + } + + @Override + public int[] getPackageGids(String packageName) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public int[] getPackageGids(String packageName, int flags) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public int getPackageUid(String packageName, int flags) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public int getPackageUidAsUser(String packageName, int flags, int userHandle) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public int getPackageUidAsUser(String packageName, int userHandle) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public PermissionInfo getPermissionInfo(String name, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isPermissionReviewModeEnabled() { + return false; + } + + @Override + public PermissionGroupInfo getPermissionGroupInfo(String name, + int flags) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public List<PermissionGroupInfo> getAllPermissionGroups(int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public ApplicationInfo getApplicationInfo(String packageName, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public ActivityInfo getActivityInfo(ComponentName className, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public ActivityInfo getReceiverInfo(ComponentName className, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public ServiceInfo getServiceInfo(ComponentName className, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public ProviderInfo getProviderInfo(ComponentName className, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public List<PackageInfo> getInstalledPackages(int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public List<PackageInfo> getPackagesHoldingPermissions(String[] permissions, + int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public List<PackageInfo> getInstalledPackagesAsUser(int flags, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkPermission(String permName, String pkgName) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean canRequestPackageInstalls() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isPermissionRevokedByPolicy(String permName, String pkgName) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public String getPermissionControllerPackageName() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addPermission(PermissionInfo info) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addPermissionAsync(PermissionInfo info) { + throw new UnsupportedOperationException(); + } + + @Override + public void removePermission(String name) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void grantRuntimePermission(String packageName, String permissionName, + UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void revokeRuntimePermission(String packageName, String permissionName, + UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public int getPermissionFlags(String permissionName, String packageName, UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void updatePermissionFlags(String permissionName, String packageName, + int flagMask, int flagValues, UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean shouldShowRequestPermissionRationale(String permission) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void addOnPermissionsChangeListener(OnPermissionsChangedListener listener) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void removeOnPermissionsChangeListener(OnPermissionsChangedListener listener) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkSignatures(String pkg1, String pkg2) { + throw new UnsupportedOperationException(); + } + + @Override + public int checkSignatures(int uid1, int uid2) { + throw new UnsupportedOperationException(); + } + + @Override + public String[] getPackagesForUid(int uid) { + throw new UnsupportedOperationException(); + } + + @Override + public String getNameForUid(int uid) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public String[] getNamesForUids(int uid[]) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public int getUidForSharedUser(String sharedUserName) { + throw new UnsupportedOperationException(); + } + + @Override + public List<ApplicationInfo> getInstalledApplications(int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public List<InstantAppInfo> getInstantApps() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public Drawable getInstantAppIcon(String packageName) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public byte[] getInstantAppCookie() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isInstantApp() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isInstantApp(String packageName) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public int getInstantAppCookieMaxBytes() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public int getInstantAppCookieMaxSize() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void clearInstantAppCookie() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void updateInstantAppCookie(@NonNull byte[] cookie) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean setInstantAppCookie(@NonNull byte[] cookie) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public ChangedPackages getChangedPackages(int sequenceNumber) { + throw new UnsupportedOperationException(); + } + + @Override + public ResolveInfo resolveActivity(Intent intent, int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public List<ResolveInfo> queryIntentActivities(Intent intent, int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent, + int flags, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public List<ResolveInfo> queryIntentActivityOptions(ComponentName caller, + Intent[] specifics, Intent intent, int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public List<ResolveInfo> queryBroadcastReceiversAsUser(Intent intent, int flags, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public ResolveInfo resolveService(Intent intent, int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public List<ResolveInfo> queryIntentServices(Intent intent, int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public List<ResolveInfo> queryIntentContentProvidersAsUser( + Intent intent, int flags, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public ProviderInfo resolveContentProvider(String name, int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public List<ProviderInfo> queryContentProviders(String processName, int uid, int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public InstrumentationInfo getInstrumentationInfo(ComponentName className, int flags) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public List<InstrumentationInfo> queryInstrumentation( + String targetPackage, int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getDrawable(String packageName, int resid, ApplicationInfo appInfo) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getActivityIcon(ComponentName activityName) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getActivityIcon(Intent intent) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getDefaultActivityIcon() { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getActivityBanner(ComponentName activityName) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getActivityBanner(Intent intent) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationBanner(ApplicationInfo info) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationBanner(String packageName) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationIcon(ApplicationInfo info) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationIcon(String packageName) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getActivityLogo(ComponentName activityName) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getActivityLogo(Intent intent) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationLogo(ApplicationInfo info) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getApplicationLogo(String packageName) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override + public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user, + Rect badgeLocation, + int badgeDensity) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public Drawable getUserBadgeForDensity(UserHandle user, int density) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public Drawable getUserBadgeForDensityNoBackground(UserHandle user, int density) { + throw new UnsupportedOperationException(); + } + + @Override + public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) { + throw new UnsupportedOperationException(); + } + + @Override + public CharSequence getText(String packageName, int resid, ApplicationInfo appInfo) { + throw new UnsupportedOperationException(); + } + + @Override + public XmlResourceParser getXml(String packageName, int resid, + ApplicationInfo appInfo) { + throw new UnsupportedOperationException(); + } + + @Override + public CharSequence getApplicationLabel(ApplicationInfo info) { + throw new UnsupportedOperationException(); + } + + @Override + public Resources getResourcesForActivity(ComponentName activityName) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public Resources getResourcesForApplication(ApplicationInfo app) { + throw new UnsupportedOperationException(); + } + + @Override + public Resources getResourcesForApplication(String appPackageName) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public PackageInfo getPackageArchiveInfo(String archiveFilePath, int flags) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void installPackage(Uri packageURI, IPackageInstallObserver observer, + int flags, String installerPackageName) { + throw new UnsupportedOperationException(); + } + + @Override + public void setInstallerPackageName(String targetPackage, + String installerPackageName) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void setUpdateAvailable(String packageName, boolean updateAvailable) { + throw new UnsupportedOperationException(); + } + + @Override + public String getInstallerPackageName(String packageName) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public int getMoveStatus(int moveId) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public void registerMoveCallback(MoveCallback callback, Handler handler) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public void unregisterMoveCallback(MoveCallback callback) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public int movePackage(String packageName, VolumeInfo vol) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public VolumeInfo getPackageCurrentVolume(ApplicationInfo app) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public List<VolumeInfo> getPackageCandidateVolumes(ApplicationInfo app) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public int movePrimaryStorage(VolumeInfo vol) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public VolumeInfo getPrimaryStorageCurrentVolume() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public List<VolumeInfo> getPrimaryStorageCandidateVolumes() { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void clearApplicationUserData( + String packageName, IPackageDataObserver observer) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void deleteApplicationCacheFiles( + String packageName, IPackageDataObserver observer) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void deleteApplicationCacheFilesAsUser(String packageName, int userId, + IPackageDataObserver observer) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public void freeStorageAndNotify(String volumeUuid, long idealStorageSize, + IPackageDataObserver observer) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public void freeStorage(String volumeUuid, long idealStorageSize, IntentSender pi) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void deletePackageAsUser(String packageName, IPackageDeleteObserver observer, + int flags, int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public void addPackageToPreferred(String packageName) { + throw new UnsupportedOperationException(); + } + + @Override + public void removePackageFromPreferred(String packageName) { + throw new UnsupportedOperationException(); + } + + @Override + public List<PackageInfo> getPreferredPackages(int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public void setComponentEnabledSetting(ComponentName componentName, + int newState, int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public int getComponentEnabledSetting(ComponentName componentName) { + throw new UnsupportedOperationException(); + } + + @Override + public void setApplicationEnabledSetting(String packageName, int newState, int flags) { + throw new UnsupportedOperationException(); + } + + @Override + public int getApplicationEnabledSetting(String packageName) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void flushPackageRestrictionsAsUser(int userId) { + throw new UnsupportedOperationException(); + } + + @Override + public void addPreferredActivity(IntentFilter filter, + int match, ComponentName[] set, ComponentName activity) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void replacePreferredActivity(IntentFilter filter, + int match, ComponentName[] set, ComponentName activity) { + throw new UnsupportedOperationException(); + } + + + @Override + public void clearPackagePreferredActivities(String packageName) { + throw new UnsupportedOperationException(); + } + + /** + * @hide - to match hiding in superclass + */ + @Override + public void getPackageSizeInfoAsUser(String packageName, int userHandle, + IPackageStatsObserver observer) { + throw new UnsupportedOperationException(); + } + + @Override + public int getPreferredActivities(List<IntentFilter> outFilters, + List<ComponentName> outActivities, String packageName) { + throw new UnsupportedOperationException(); + } + + /** @hide - hidden in superclass */ + @Override + public ComponentName getHomeActivities(List<ResolveInfo> outActivities) { + throw new UnsupportedOperationException(); + } + + @Override + public String[] getSystemSharedLibraryNames() { + throw new UnsupportedOperationException(); + } + + @Override + public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public @NonNull String getServicesSystemSharedLibraryPackageName() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public @NonNull String getSharedSystemSharedLibraryPackageName() { + throw new UnsupportedOperationException(); + } + + @Override + public FeatureInfo[] getSystemAvailableFeatures() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean hasSystemFeature(String name) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean hasSystemFeature(String name, int version) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isSafeMode() { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public KeySet getKeySetByAlias(String packageName, String alias) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public KeySet getSigningKeySet(String packageName) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isSignedBy(String packageName, KeySet ks) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isSignedByExactly(String packageName, KeySet ks) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public String[] setPackagesSuspendedAsUser(String[] packageNames, boolean hidden, int userId) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public boolean isPackageSuspendedForUser(String packageName, int userId) { + throw new UnsupportedOperationException(); + } + + /** @hide */ + @Override + public void setApplicationCategoryHint(String packageName, int categoryHint) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden, + UserHandle user) { + return false; + } + + /** + * @hide + */ + @Override + public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) { + return false; + } + + /** + * @hide + */ + @Override + public int installExistingPackage(String packageName) throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public int installExistingPackage(String packageName, int installReason) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public int installExistingPackageAsUser(String packageName, int userId) + throws NameNotFoundException { + throw new UnsupportedOperationException(); + } + + @Override + public void verifyPendingInstall(int id, int verificationCode) { + throw new UnsupportedOperationException(); + } + + @Override + public void extendVerificationTimeout(int id, int verificationCodeAtTimeout, + long millisecondsToDelay) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void verifyIntentFilter(int id, int verificationCode, List<String> outFailedDomains) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public int getIntentVerificationStatusAsUser(String packageName, int userId) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public boolean updateIntentVerificationStatusAsUser(String packageName, int status, int userId) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) { + throw new UnsupportedOperationException(); + } + + @Override + public List<IntentFilter> getAllIntentFilters(String packageName) { + throw new UnsupportedOperationException(); + } + + /** {@removed} */ + @Deprecated + public String getDefaultBrowserPackageName(int userId) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public String getDefaultBrowserPackageNameAsUser(int userId) { + throw new UnsupportedOperationException(); + } + + /** {@removed} */ + @Deprecated + public boolean setDefaultBrowserPackageName(String packageName, int userId) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public boolean setDefaultBrowserPackageNameAsUser(String packageName, int userId) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public VerifierDeviceIdentity getVerifierDeviceIdentity() { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public boolean isUpgrade() { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void installPackage(Uri packageURI, PackageInstallObserver observer, + int flags, String installerPackageName) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId, + int flags) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void clearCrossProfileIntentFilters(int sourceUserId) { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + public PackageInstaller getPackageInstaller() { + throw new UnsupportedOperationException(); + } + + /** {@hide} */ + @Override + public boolean isPackageAvailable(String packageName) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + public int getInstallReason(String packageName, UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public ComponentName getInstantAppResolverSettingsComponent() { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public ComponentName getInstantAppInstallerComponent() { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + public String getInstantAppAndroidId(String packageName, UserHandle user) { + throw new UnsupportedOperationException(); + } + + /** + * @hide + */ + @Override + public void registerDexModule(String dexModulePath, + @Nullable DexModuleRegisterCallback callback) { + throw new UnsupportedOperationException(); + } +} diff --git a/test-mock/src/android/test/mock/MockResources.java b/test-mock/src/android/test/mock/MockResources.java new file mode 100644 index 000000000000..880343e5e780 --- /dev/null +++ b/test-mock/src/android/test/mock/MockResources.java @@ -0,0 +1,227 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.test.mock; + +import android.content.res.AssetManager; +import android.content.res.Resources; +import android.content.res.Configuration; +import android.content.res.TypedArray; +import android.content.res.ColorStateList; +import android.content.res.XmlResourceParser; +import android.content.res.AssetFileDescriptor; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.util.AttributeSet; +import android.graphics.drawable.Drawable; +import android.graphics.Movie; + +import java.io.InputStream; + +/** + * A mock {@link android.content.res.Resources} class. All methods are non-functional and throw + * {@link java.lang.UnsupportedOperationException}. Override it to provide the operations that you + * need. + * + * @deprecated Use a mocking framework like <a href="https://github.com/mockito/mockito">Mockito</a>. + * New tests should be written using the + * <a href="{@docRoot}tools/testing-support-library/index.html">Android Testing Support Library</a>. + */ +@Deprecated +public class MockResources extends Resources { + + public MockResources() { + super(new AssetManager(), null, null); + } + + @Override + public void updateConfiguration(Configuration config, DisplayMetrics metrics) { + // this method is called from the constructor, so we just do nothing + } + + @Override + public CharSequence getText(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public CharSequence getQuantityText(int id, int quantity) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getString(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getString(int id, Object... formatArgs) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getQuantityString(int id, int quantity, Object... formatArgs) + throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getQuantityString(int id, int quantity) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public CharSequence getText(int id, CharSequence def) { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public CharSequence[] getTextArray(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String[] getStringArray(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public int[] getIntArray(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public TypedArray obtainTypedArray(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public float getDimension(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public int getDimensionPixelOffset(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public int getDimensionPixelSize(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public Drawable getDrawable(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public Movie getMovie(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public int getColor(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public ColorStateList getColorStateList(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public int getInteger(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public XmlResourceParser getLayout(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public XmlResourceParser getAnimation(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public XmlResourceParser getXml(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public InputStream openRawResource(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public AssetFileDescriptor openRawResourceFd(int id) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public void getValue(int id, TypedValue outValue, boolean resolveRefs) + throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public void getValue(String name, TypedValue outValue, boolean resolveRefs) + throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public DisplayMetrics getDisplayMetrics() { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public Configuration getConfiguration() { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public int getIdentifier(String name, String defType, String defPackage) { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getResourceName(int resid) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getResourcePackageName(int resid) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getResourceTypeName(int resid) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } + + @Override + public String getResourceEntryName(int resid) throws NotFoundException { + throw new UnsupportedOperationException("mock object, not implemented"); + } +} diff --git a/test-mock/src/android/test/mock/package.html b/test-mock/src/android/test/mock/package.html new file mode 100644 index 000000000000..c0fcd1ea336a --- /dev/null +++ b/test-mock/src/android/test/mock/package.html @@ -0,0 +1,10 @@ +<HTML> +<BODY> +<p>Utility classes providing stubs or mocks of various Android framework building blocks.</p> + +<p>For more information, see the +<a href="{@docRoot}tools/testing/index.html">Testing</a> guide.</p> +{@more} + +</BODY> +</HTML> |