use of android.content.ContentProviderClient in project android_frameworks_base by DirtyUnicorns.
the class DocumentClipper method getDocumentsFromClipData.
/**
* Returns a list of Documents as decoded in clipData.
* This should be run from inside an AsyncTask.
*/
public List<DocumentInfo> getDocumentsFromClipData(ClipData clipData) {
assert (clipData != null);
final List<DocumentInfo> srcDocs = new ArrayList<>();
int count = clipData.getItemCount();
if (count == 0) {
return srcDocs;
}
ContentResolver resolver = mContext.getContentResolver();
for (int i = 0; i < count; ++i) {
ClipData.Item item = clipData.getItemAt(i);
Uri itemUri = item.getUri();
if (itemUri != null && DocumentsContract.isDocumentUri(mContext, itemUri)) {
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, itemUri.getAuthority());
cursor = client.query(itemUri, null, null, null, null);
cursor.moveToPosition(0);
srcDocs.add(DocumentInfo.fromCursor(cursor, itemUri.getAuthority()));
} catch (Exception e) {
Log.e(TAG, e.getMessage());
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
}
}
return srcDocs;
}
use of android.content.ContentProviderClient in project android_frameworks_base by AOSPA.
the class MediaInserterTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
mMockProvider = EasyMock.createMock(IContentProvider.class);
final ContentProviderClient client = new ContentProviderClient(getInstrumentation().getContext().getContentResolver(), mMockProvider, true);
mMediaInserter = new MediaInserter(client, TEST_BUFFER_SIZE);
mPackageName = getInstrumentation().getContext().getPackageName();
mFilesCounter = 0;
mAudioCounter = 0;
mVideoCounter = 0;
mImagesCounter = 0;
}
use of android.content.ContentProviderClient in project android_frameworks_base by AOSPA.
the class RootsCache method loadRootsForAuthority.
/**
* Bring up requested provider and query for all active roots.
*/
private Collection<RootInfo> loadRootsForAuthority(ContentResolver resolver, String authority, boolean forceRefresh) {
if (DEBUG)
Log.d(TAG, "Loading roots for " + authority);
synchronized (mObservedAuthorities) {
if (mObservedAuthorities.add(authority)) {
// Watch for any future updates
final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
mContext.getContentResolver().registerContentObserver(rootsUri, true, mObserver);
}
}
final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
if (!forceRefresh) {
// Look for roots data that we might have cached for ourselves in the
// long-lived system process.
final Bundle systemCache = resolver.getCache(rootsUri);
if (systemCache != null) {
if (DEBUG)
Log.d(TAG, "System cache hit for " + authority);
return systemCache.getParcelableArrayList(TAG);
}
}
final ArrayList<RootInfo> roots = new ArrayList<>();
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
cursor = client.query(rootsUri, null, null, null, null);
while (cursor.moveToNext()) {
final RootInfo root = RootInfo.fromRootsCursor(authority, cursor);
roots.add(root);
}
} catch (Exception e) {
Log.w(TAG, "Failed to load some roots from " + authority + ": " + e);
} finally {
IoUtils.closeQuietly(cursor);
ContentProviderClient.releaseQuietly(client);
}
// Cache these freshly parsed roots over in the long-lived system
// process, in case our process goes away. The system takes care of
// invalidating the cache if the package or Uri changes.
final Bundle systemCache = new Bundle();
systemCache.putParcelableArrayList(TAG, roots);
resolver.putCache(rootsUri, systemCache);
return roots;
}
use of android.content.ContentProviderClient in project android_frameworks_base by AOSPA.
the class Job method getClient.
ContentProviderClient getClient(DocumentInfo doc) throws RemoteException {
ContentProviderClient client = mClients.get(doc.authority);
if (client == null) {
// Acquire content providers.
client = acquireUnstableProviderOrThrow(getContentResolver(), doc.authority);
mClients.put(doc.authority, client);
}
assert (client != null);
return client;
}
use of android.content.ContentProviderClient in project robolectric by robolectric.
the class ShadowContentProviderClientTest method acquireUnstableContentProviderClient_isUnstable.
@Test
public void acquireUnstableContentProviderClient_isUnstable() {
ContentProviderClient client = contentResolver.acquireUnstableContentProviderClient(AUTHORITY);
assertThat(shadowOf(client).isStable()).isFalse();
}
Aggregations