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);
}
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);
}
}
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];
}
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;
}
Aggregations