2009-03-03 19:31:44 -08:00
|
|
|
/*
|
2009-10-22 08:36:42 +09:00
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
2009-03-03 19:31:44 -08:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
import android.content.ContentProvider;
|
|
|
|
import android.content.ContentProviderOperation;
|
|
|
|
import android.content.ContentProviderResult;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.content.ContentValues;
|
2009-10-22 08:36:42 +09:00
|
|
|
import android.content.Context;
|
2012-01-25 19:37:13 -08:00
|
|
|
import android.content.ICancelationSignal;
|
2009-10-22 08:36:42 +09:00
|
|
|
import android.content.IContentProvider;
|
2009-05-15 15:10:40 -07:00
|
|
|
import android.content.OperationApplicationException;
|
2009-10-22 08:36:42 +09:00
|
|
|
import android.content.pm.PathPermission;
|
|
|
|
import android.content.pm.ProviderInfo;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.content.res.AssetFileDescriptor;
|
|
|
|
import android.database.Cursor;
|
|
|
|
import android.net.Uri;
|
2010-03-04 17:48:13 -08:00
|
|
|
import android.os.Bundle;
|
2009-03-03 19:31:44 -08:00
|
|
|
import android.os.IBinder;
|
|
|
|
import android.os.ParcelFileDescriptor;
|
2009-10-22 08:36:42 +09:00
|
|
|
import android.os.RemoteException;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
2009-05-22 14:23:31 -07:00
|
|
|
import java.util.ArrayList;
|
2009-03-03 19:31:44 -08:00
|
|
|
|
|
|
|
/**
|
2009-10-22 08:36:42 +09:00
|
|
|
* Mock implementation of ContentProvider. All methods are non-functional and throw
|
|
|
|
* {@link java.lang.UnsupportedOperationException}. Tests can extend this class to
|
2009-03-03 19:31:44 -08:00
|
|
|
* implement behavior needed for tests.
|
|
|
|
*/
|
2009-10-22 08:36:42 +09:00
|
|
|
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 {
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
|
|
|
|
throws RemoteException, OperationApplicationException {
|
|
|
|
return MockContentProvider.this.applyBatch(operations);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public int bulkInsert(Uri url, ContentValues[] initialValues) throws RemoteException {
|
|
|
|
return MockContentProvider.this.bulkInsert(url, initialValues);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public int delete(Uri url, String selection, String[] selectionArgs)
|
|
|
|
throws RemoteException {
|
|
|
|
return MockContentProvider.this.delete(url, selection, selectionArgs);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public String getType(Uri url) throws RemoteException {
|
|
|
|
return MockContentProvider.this.getType(url);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public Uri insert(Uri url, ContentValues initialValues) throws RemoteException {
|
|
|
|
return MockContentProvider.this.insert(url, initialValues);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public AssetFileDescriptor openAssetFile(Uri url, String mode) throws RemoteException,
|
|
|
|
FileNotFoundException {
|
|
|
|
return MockContentProvider.this.openAssetFile(url, mode);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public ParcelFileDescriptor openFile(Uri url, String mode) throws RemoteException,
|
|
|
|
FileNotFoundException {
|
|
|
|
return MockContentProvider.this.openFile(url, mode);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs,
|
2012-01-25 19:37:13 -08:00
|
|
|
String sortOrder, ICancelationSignal cancelationSignal) throws RemoteException {
|
2009-10-22 08:36:42 +09:00
|
|
|
return MockContentProvider.this.query(url, projection, selection,
|
|
|
|
selectionArgs, sortOrder);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public int update(Uri url, ContentValues values, String selection, String[] selectionArgs)
|
|
|
|
throws RemoteException {
|
|
|
|
return MockContentProvider.this.update(url, values, selection, selectionArgs);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2010-03-04 17:48:13 -08:00
|
|
|
public Bundle call(String method, String request, Bundle args)
|
|
|
|
throws RemoteException {
|
|
|
|
return MockContentProvider.this.call(method, request, args);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
2009-10-22 08:36:42 +09:00
|
|
|
public IBinder asBinder() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
Add new ContentProvider for doing conversions to data streams.
This introduces basic infrastructure that should allow content
providers holding complex data to perform on-demand conversion
of their data to streams of various types. It is achieved through
two new content provider APIs, one to interrogate the possible
stream MIME types the provider can return, and the other to
request a stream of data in a particular MIME type.
Because implementations of this will often need to do on-demand
data conversion, there is also a utility intoduced in ContentProvider
for subclasses to easily run a function to write data into a
pipe that is read by the client.
This feature is mostly intended for cut and paste and drag and
drop, as the complex data interchange allowing the source and
destination to negotiate data types and copy (possible large)
data between them. However because it is fundamental facility
of ContentProvider, it can be used in other places, such as for
more advanced GET_CONTENT data exchanges.
An example implementation of this would be in ContactsProvider,
which can now provider a data stream when a client opens certain
pieces of it data, to return data as flat text, a vcard, or other
format.
Change-Id: I58627ea4ed359aa7cf2c66274adb18306c209cb2
2010-08-06 12:16:55 -07:00
|
|
|
public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException {
|
|
|
|
return MockContentProvider.this.getStreamTypes(url, mimeTypeFilter);
|
|
|
|
}
|
|
|
|
|
2011-10-09 12:39:53 -07:00
|
|
|
@Override
|
Add new ContentProvider for doing conversions to data streams.
This introduces basic infrastructure that should allow content
providers holding complex data to perform on-demand conversion
of their data to streams of various types. It is achieved through
two new content provider APIs, one to interrogate the possible
stream MIME types the provider can return, and the other to
request a stream of data in a particular MIME type.
Because implementations of this will often need to do on-demand
data conversion, there is also a utility intoduced in ContentProvider
for subclasses to easily run a function to write data into a
pipe that is read by the client.
This feature is mostly intended for cut and paste and drag and
drop, as the complex data interchange allowing the source and
destination to negotiate data types and copy (possible large)
data between them. However because it is fundamental facility
of ContentProvider, it can be used in other places, such as for
more advanced GET_CONTENT data exchanges.
An example implementation of this would be in ContactsProvider,
which can now provider a data stream when a client opens certain
pieces of it data, to return data as flat text, a vcard, or other
format.
Change-Id: I58627ea4ed359aa7cf2c66274adb18306c209cb2
2010-08-06 12:16:55 -07:00
|
|
|
public AssetFileDescriptor openTypedAssetFile(Uri url, String mimeType, Bundle opts)
|
|
|
|
throws RemoteException, FileNotFoundException {
|
|
|
|
return MockContentProvider.this.openTypedAssetFile(url, mimeType, opts);
|
|
|
|
}
|
2012-01-25 19:37:13 -08:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ICancelationSignal createCancelationSignal() throws RemoteException {
|
|
|
|
return null;
|
|
|
|
}
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
2009-10-22 08:36:42 +09:00
|
|
|
private final InversionIContentProvider mIContentProvider = new InversionIContentProvider();
|
2009-03-03 19:31:44 -08:00
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
/**
|
|
|
|
* A constructor using {@link MockContext} instance as a Context in it.
|
|
|
|
*/
|
|
|
|
protected MockContentProvider() {
|
|
|
|
super(new MockContext(), "", "", null);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
/**
|
|
|
|
* A constructor accepting a Context instance, which is supposed to be the subclasss of
|
|
|
|
* {@link MockContext}.
|
|
|
|
*/
|
|
|
|
public MockContentProvider(Context context) {
|
|
|
|
super(context, "", "", null);
|
2009-03-03 19:31:44 -08:00
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
/**
|
|
|
|
* 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) {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public String getType(Uri uri) {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public Uri insert(Uri uri, ContentValues values) {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public boolean onCreate() {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
2009-05-15 15:10:40 -07:00
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
|
|
|
String sortOrder) {
|
2009-05-15 15:10:40 -07:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2009-10-05 14:21:12 -07:00
|
|
|
/**
|
2009-10-22 08:36:42 +09:00
|
|
|
* If you're reluctant to implement this manually, please just call super.bulkInsert().
|
2009-10-05 14:21:12 -07:00
|
|
|
*/
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public int bulkInsert(Uri uri, ContentValues[] values) {
|
2009-05-07 17:35:38 -07:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public void attachInfo(Context context, ProviderInfo info) {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
@Override
|
|
|
|
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) {
|
2009-03-03 19:31:44 -08:00
|
|
|
throw new UnsupportedOperationException("unimplemented mock method");
|
|
|
|
}
|
|
|
|
|
2010-03-04 17:48:13 -08:00
|
|
|
/**
|
|
|
|
* @hide
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public Bundle call(String method, String request, Bundle args) {
|
|
|
|
throw new UnsupportedOperationException("unimplemented mock method call");
|
|
|
|
}
|
|
|
|
|
Add new ContentProvider for doing conversions to data streams.
This introduces basic infrastructure that should allow content
providers holding complex data to perform on-demand conversion
of their data to streams of various types. It is achieved through
two new content provider APIs, one to interrogate the possible
stream MIME types the provider can return, and the other to
request a stream of data in a particular MIME type.
Because implementations of this will often need to do on-demand
data conversion, there is also a utility intoduced in ContentProvider
for subclasses to easily run a function to write data into a
pipe that is read by the client.
This feature is mostly intended for cut and paste and drag and
drop, as the complex data interchange allowing the source and
destination to negotiate data types and copy (possible large)
data between them. However because it is fundamental facility
of ContentProvider, it can be used in other places, such as for
more advanced GET_CONTENT data exchanges.
An example implementation of this would be in ContactsProvider,
which can now provider a data stream when a client opens certain
pieces of it data, to return data as flat text, a vcard, or other
format.
Change-Id: I58627ea4ed359aa7cf2c66274adb18306c209cb2
2010-08-06 12:16:55 -07:00
|
|
|
public String[] getStreamTypes(Uri url, String mimeTypeFilter) {
|
|
|
|
throw new UnsupportedOperationException("unimplemented mock method call");
|
|
|
|
}
|
|
|
|
|
|
|
|
public AssetFileDescriptor openTypedAssetFile(Uri url, String mimeType, Bundle opts) {
|
|
|
|
throw new UnsupportedOperationException("unimplemented mock method call");
|
|
|
|
}
|
|
|
|
|
2009-10-22 08:36:42 +09:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2009-12-09 16:00:40 -08:00
|
|
|
}
|