Search in sources :

Example 51 with ContentProvider

use of android.content.ContentProvider in project robolectric by robolectric.

the class ShadowContentResolverTest method call_shouldCallProvider.

@Test
public void call_shouldCallProvider() {
    final String METHOD = "method";
    final String ARG = "arg";
    final Bundle EXTRAS = new Bundle();
    final Uri uri = Uri.parse("content://" + AUTHORITY);
    ContentProvider provider = mock(ContentProvider.class);
    doReturn(null).when(provider).call(METHOD, ARG, EXTRAS);
    ShadowContentResolver.registerProviderInternal(AUTHORITY, provider);
    contentResolver.call(uri, METHOD, ARG, EXTRAS);
    verify(provider).call(METHOD, ARG, EXTRAS);
}
Also used : Bundle(android.os.Bundle) ContentProvider(android.content.ContentProvider) Uri(android.net.Uri) Test(org.junit.Test)

Example 52 with ContentProvider

use of android.content.ContentProvider in project robolectric by robolectric.

the class ShadowContentResolver method createAndInitialize.

private static ContentProvider createAndInitialize(ProviderInfo providerInfo) {
    try {
        ContentProvider provider = (ContentProvider) Class.forName(providerInfo.name).getDeclaredConstructor().newInstance();
        provider.attachInfo(RuntimeEnvironment.application, providerInfo);
        return provider;
    } catch (InstantiationException | ClassNotFoundException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        throw new RuntimeException("Error instantiating class " + providerInfo.name, e);
    }
}
Also used : IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 53 with ContentProvider

use of android.content.ContentProvider in project VirtualAPK by didi.

the class RemoteContentProvider method applyBatch.

@NonNull
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
    try {
        Field uriField = ContentProviderOperation.class.getDeclaredField("mUri");
        uriField.setAccessible(true);
        for (ContentProviderOperation operation : operations) {
            Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(KEY_URI));
            uriField.set(operation, pluginUri);
        }
    } catch (Exception e) {
        return new ContentProviderResult[0];
    }
    if (operations.size() > 0) {
        ContentProvider provider = getContentProvider(operations.get(0).getUri());
        if (provider != null) {
            return provider.applyBatch(operations);
        }
    }
    return new ContentProviderResult[0];
}
Also used : Field(java.lang.reflect.Field) ContentProviderResult(android.content.ContentProviderResult) ContentProviderOperation(android.content.ContentProviderOperation) ContentProvider(android.content.ContentProvider) Uri(android.net.Uri) OperationApplicationException(android.content.OperationApplicationException) NonNull(android.support.annotation.NonNull)

Example 54 with ContentProvider

use of android.content.ContentProvider in project VirtualAPK by didi.

the class RemoteContentProvider method update.

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    ContentProvider provider = getContentProvider(uri);
    Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
    if (provider != null) {
        return provider.update(pluginUri, values, selection, selectionArgs);
    }
    return 0;
}
Also used : ContentProvider(android.content.ContentProvider) Uri(android.net.Uri)

Aggregations

ContentProvider (android.content.ContentProvider)54 Uri (android.net.Uri)29 IContentProvider (android.content.IContentProvider)16 Test (org.junit.Test)13 Implementation (org.robolectric.annotation.Implementation)11 ContentValues (android.content.ContentValues)8 Context (android.content.Context)7 ApplicationInfo (android.content.pm.ApplicationInfo)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 RemoteException (android.os.RemoteException)7 AndroidRuntimeException (android.util.AndroidRuntimeException)7 ComponentName (android.content.ComponentName)6 IBinder (android.os.IBinder)6 BaseCursor (org.robolectric.fakes.BaseCursor)6 ContentProviderOperation (android.content.ContentProviderOperation)4 OperationApplicationException (android.content.OperationApplicationException)4 ContentResolver (android.content.ContentResolver)3 ProviderInfo (android.content.pm.ProviderInfo)3 Cursor (android.database.Cursor)3 MatrixCursor (android.database.MatrixCursor)3