Search in sources :

Example 41 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 42 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)

Example 43 with ContentProvider

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

the class ShadowContentProviderTest method testSetCallingPackage.

@Config(minSdk = KITKAT)
@Test
public void testSetCallingPackage() {
    ContentProvider provider = new TestContentProvider1();
    shadowOf(provider).setCallingPackage("calling-package");
    assertThat(provider.getCallingPackage()).isEqualTo("calling-package");
}
Also used : ContentProvider(android.content.ContentProvider) TestContentProvider1(org.robolectric.shadows.testing.TestContentProvider1) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 44 with ContentProvider

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

the class ShadowContentResolver method bulkInsert.

/**
 * If a {@link ContentProvider} is registered for the given {@link Uri}, its {@link
 * ContentProvider#bulkInsert(Uri, ContentValues[])} method will be invoked.
 *
 * Tests can verify that this method was called using {@link #getStatements()} or {@link
 * #getInsertStatements()}.
 *
 * If no appropriate {@link ContentProvider} is found, no action will be taken and the number
 * of rows in {@code values} will be returned.
 */
@Implementation
protected final int bulkInsert(Uri url, ContentValues[] values) {
    ContentProvider provider = getProvider(url, getContext());
    InsertStatement insertStatement = new InsertStatement(url, provider, values);
    statements.add(insertStatement);
    insertStatements.add(insertStatement);
    if (provider != null) {
        return provider.bulkInsert(url, values);
    } else {
        return values.length;
    }
}
Also used : IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Example 45 with ContentProvider

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

the class ShadowContentResolver method query.

@Implementation
protected final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    ContentProvider provider = getProvider(uri, getContext());
    if (provider != null) {
        return provider.query(uri, projection, selection, selectionArgs, sortOrder);
    } else {
        BaseCursor returnCursor = getCursor(uri);
        if (returnCursor == null) {
            return null;
        }
        returnCursor.setQuery(uri, projection, selection, selectionArgs, sortOrder);
        return returnCursor;
    }
}
Also used : BaseCursor(org.robolectric.fakes.BaseCursor) IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Aggregations

ContentProvider (android.content.ContentProvider)53 Uri (android.net.Uri)28 IContentProvider (android.content.IContentProvider)16 Test (org.junit.Test)12 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 ProviderInfo (android.content.pm.ProviderInfo)3 Cursor (android.database.Cursor)3 MatrixCursor (android.database.MatrixCursor)3 ContentProviderResult (android.content.ContentProviderResult)2