use of android.content.ContentProviderClient in project platform_frameworks_base by android.
the class DirectoryLoader method loadInBackground.
@Override
public final DirectoryResult loadInBackground() {
synchronized (this) {
if (isLoadInBackgroundCanceled()) {
throw new OperationCanceledException();
}
mSignal = new CancellationSignal();
}
final ContentResolver resolver = getContext().getContentResolver();
final String authority = mUri.getAuthority();
final DirectoryResult result = new DirectoryResult();
result.doc = mDoc;
// Use default document when searching
if (mSearchMode) {
final Uri docUri = DocumentsContract.buildDocumentUri(mRoot.authority, mRoot.documentId);
try {
mDoc = DocumentInfo.fromUri(resolver, docUri);
} catch (FileNotFoundException e) {
Log.w(TAG, "Failed to query", e);
result.exception = e;
return result;
}
}
if (mUserSortOrder != State.SORT_ORDER_UNKNOWN) {
result.sortOrder = mUserSortOrder;
} else {
if ((mDoc.flags & Document.FLAG_DIR_PREFERS_LAST_MODIFIED) != 0) {
result.sortOrder = State.SORT_ORDER_LAST_MODIFIED;
} else {
result.sortOrder = State.SORT_ORDER_DISPLAY_NAME;
}
}
// Search always uses ranking from provider
if (mSearchMode) {
result.sortOrder = State.SORT_ORDER_UNKNOWN;
}
if (DEBUG)
Log.d(TAG, "userSortOrder=" + mUserSortOrder + ", sortOrder=" + result.sortOrder);
ContentProviderClient client = null;
Cursor cursor = null;
try {
client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, authority);
cursor = client.query(mUri, null, null, null, getQuerySortOrder(result.sortOrder), mSignal);
if (cursor == null) {
throw new RemoteException("Provider returned null");
}
cursor.registerContentObserver(mObserver);
cursor = new RootCursorWrapper(mUri.getAuthority(), mRoot.rootId, cursor, -1);
if (mSearchMode) {
// Filter directories out of search results, for now
cursor = new FilteringCursorWrapper(cursor, null, SEARCH_REJECT_MIMES);
}
result.client = client;
result.cursor = cursor;
} catch (Exception e) {
Log.w(TAG, "Failed to query", e);
result.exception = e;
ContentProviderClient.releaseQuietly(client);
} finally {
synchronized (this) {
mSignal = null;
}
}
return result;
}
use of android.content.ContentProviderClient in project robolectric by robolectric.
the class ShadowContentProviderClientTest method shouldDelegateToContentProvider.
@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void shouldDelegateToContentProvider() throws Exception {
ContentProviderClient client = contentResolver.acquireContentProviderClient(AUTHORITY);
client.query(URI, PROJECTION, SELECTION, SELECTION_ARGS, SORT_ORDER);
verify(provider).query(URI, PROJECTION, SELECTION, SELECTION_ARGS, SORT_ORDER);
CancellationSignal signal = new CancellationSignal();
client.query(URI, PROJECTION, SELECTION, SELECTION_ARGS, SORT_ORDER, signal);
verify(provider).query(URI, PROJECTION, SELECTION, SELECTION_ARGS, SORT_ORDER, signal);
client.insert(URI, VALUES);
verify(provider).insert(URI, VALUES);
client.update(URI, VALUES, SELECTION, SELECTION_ARGS);
verify(provider).update(URI, VALUES, SELECTION, SELECTION_ARGS);
client.delete(URI, SELECTION, SELECTION_ARGS);
verify(provider).delete(URI, SELECTION, SELECTION_ARGS);
client.getType(URI);
verify(provider).getType(URI);
client.openFile(URI, "rw");
verify(provider).openFile(URI, "rw");
client.openAssetFile(URI, "r");
verify(provider).openAssetFile(URI, "r");
final Bundle opts = new Bundle();
client.openTypedAssetFileDescriptor(URI, MIME_TYPE, opts);
verify(provider).openTypedAssetFile(URI, MIME_TYPE, opts);
client.getStreamTypes(URI, MIME_TYPE);
verify(provider).getStreamTypes(URI, MIME_TYPE);
final ArrayList<ContentProviderOperation> ops = new ArrayList<>();
client.applyBatch(ops);
verify(provider).applyBatch(ops);
final ContentValues[] values = { VALUES };
client.bulkInsert(URI, values);
verify(provider).bulkInsert(URI, values);
final String method = "method";
final String arg = "arg";
final Bundle extras = new Bundle();
client.call(method, arg, extras);
verify(provider).call(method, arg, extras);
}
use of android.content.ContentProviderClient in project robolectric by robolectric.
the class ShadowContentProviderClientTest method acquireContentProviderClient_isStable.
@Test
public void acquireContentProviderClient_isStable() {
ContentProviderClient client = contentResolver.acquireContentProviderClient(AUTHORITY);
assertThat(shadowOf(client).isStable()).isTrue();
}
use of android.content.ContentProviderClient in project apps-android-wikipedia by wikimedia.
the class MainPageReadMoreTopicTask method getInterestedHistoryEntry.
private Cursor getInterestedHistoryEntry() {
Context context = WikipediaApp.getInstance();
ContentProviderClient client = HistoryEntry.DATABASE_TABLE.acquireClient(context);
try {
Uri uri = PageHistoryContract.PageWithImage.URI;
final String[] projection = null;
String selection = ":sourceCol != ? and :sourceCol != ? and :sourceCol != ? and :timeSpentCol >= ?".replaceAll(":sourceCol", PageHistoryContract.Page.SOURCE.qualifiedName()).replaceAll(":timeSpentCol", PageHistoryContract.Page.TIME_SPENT.qualifiedName());
String[] selectionArgs = new String[] { Integer.toString(HistoryEntry.SOURCE_MAIN_PAGE), Integer.toString(HistoryEntry.SOURCE_RANDOM), Integer.toString(HistoryEntry.SOURCE_FEED_MAIN_PAGE), Integer.toString(context.getResources().getInteger(R.integer.article_engagement_threshold_sec)) };
String order = PageHistoryContract.PageWithImage.ORDER_MRU;
return client.query(uri, projection, selection, selectionArgs, order);
} catch (RemoteException e) {
throw new RuntimeException(e);
} finally {
ContentProviderClientCompat.close(client);
}
}
use of android.content.ContentProviderClient in project android by nextcloud.
the class FileDataStorageManager method deleteFileInMediaScan.
public void deleteFileInMediaScan(String path) {
String mimetypeString = FileStorageUtils.getMimeTypeFromName(path);
ContentResolver contentResolver = getContentResolver();
if (contentResolver != null) {
if (MimeTypeUtil.isImage(mimetypeString)) {
// Images
contentResolver.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.DATA + "=?", new String[] { path });
} else if (MimeTypeUtil.isAudio(mimetypeString)) {
// Audio
contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MediaStore.Audio.Media.DATA + "=?", new String[] { path });
} else if (MimeTypeUtil.isVideo(mimetypeString)) {
// Video
contentResolver.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.DATA + "=?", new String[] { path });
}
} else {
ContentProviderClient contentProviderClient = getContentProviderClient();
try {
if (MimeTypeUtil.isImage(mimetypeString)) {
// Images
contentProviderClient.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.DATA + "=?", new String[] { path });
} else if (MimeTypeUtil.isAudio(mimetypeString)) {
// Audio
contentProviderClient.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, MediaStore.Audio.Media.DATA + "=?", new String[] { path });
} else if (MimeTypeUtil.isVideo(mimetypeString)) {
// Video
contentProviderClient.delete(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, MediaStore.Video.Media.DATA + "=?", new String[] { path });
}
} catch (RemoteException e) {
Log_OC.e(TAG, "Exception deleting media file in MediaStore " + e.getMessage(), e);
}
}
}
Aggregations