Search in sources :

Example 31 with ContentProviderClient

use of android.content.ContentProviderClient in project VirtualXposed by android-hacker.

the class ContentProviderCompat method call.

public static Bundle call(Context context, Uri uri, String method, String arg, Bundle extras) {
    if (VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return context.getContentResolver().call(uri, method, arg, extras);
    }
    ContentProviderClient client = crazyAcquireContentProvider(context, uri);
    Bundle res = null;
    try {
        res = client.call(method, arg, extras);
    } catch (RemoteException e) {
        e.printStackTrace();
    } finally {
        releaseQuietly(client);
    }
    return res;
}
Also used : Bundle(android.os.Bundle) RemoteException(android.os.RemoteException) ContentProviderClient(android.content.ContentProviderClient)

Example 32 with ContentProviderClient

use of android.content.ContentProviderClient in project VirtualXposed by android-hacker.

the class ContentProviderCompat method crazyAcquireContentProvider.

public static ContentProviderClient crazyAcquireContentProvider(Context context, Uri uri) {
    ContentProviderClient client = acquireContentProviderClient(context, uri);
    if (client == null) {
        int retry = 0;
        while (retry < 5 && client == null) {
            SystemClock.sleep(100);
            retry++;
            client = acquireContentProviderClient(context, uri);
        }
    }
    return client;
}
Also used : ContentProviderClient(android.content.ContentProviderClient)

Example 33 with ContentProviderClient

use of android.content.ContentProviderClient in project AnExplorer by 1hakr.

the class DocumentsContract method compressDocument.

public static boolean compressDocument(ContentResolver resolver, Uri fromDocumentUri, ArrayList<String> fromDocumentIds) {
    final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(fromDocumentUri.getAuthority());
    try {
        final Bundle in = new Bundle();
        in.putString(Document.COLUMN_DOCUMENT_ID, getDocumentId(fromDocumentUri));
        in.putParcelable(DocumentsContract.EXTRA_URI, fromDocumentUri);
        in.putStringArrayList(DocumentsContract.EXTRA_DOCUMENTS_COMPRESS, fromDocumentIds);
        resolver.call(fromDocumentUri, METHOD_COMPRESS_DOCUMENT, null, in);
        return true;
    } catch (Exception e) {
        Log.w(TAG, "Failed to compress document", e);
        return false;
    } finally {
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
Also used : Bundle(android.os.Bundle) ContentProviderClient(android.content.ContentProviderClient) RemoteException(android.os.RemoteException) OperationCanceledException(android.os.OperationCanceledException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 34 with ContentProviderClient

use of android.content.ContentProviderClient in project AnExplorer by 1hakr.

the class DocumentInfo method updateFromUri.

public void updateFromUri(ContentResolver resolver, Uri uri) throws FileNotFoundException {
    ContentProviderClient client = null;
    Cursor cursor = null;
    try {
        client = DocumentsApplication.acquireUnstableProviderOrThrow(resolver, uri.getAuthority());
        cursor = client.query(uri, null, null, null, null);
        if (!cursor.moveToFirst()) {
            throw new FileNotFoundException("Missing details for " + uri);
        }
        updateFromCursor(cursor, uri.getAuthority());
    } catch (Throwable t) {
        throw asFileNotFoundException(t);
    } finally {
        IoUtils.closeQuietly(cursor);
        ContentProviderClientCompat.releaseQuietly(client);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) Cursor(android.database.Cursor) ContentProviderClient(android.content.ContentProviderClient)

Example 35 with ContentProviderClient

use of android.content.ContentProviderClient in project AnExplorer by 1hakr.

the class DocumentsApplication method acquireUnstableProviderOrThrow.

public static ContentProviderClient acquireUnstableProviderOrThrow(ContentResolver resolver, String authority) throws RemoteException {
    final ContentProviderClient client = ContentProviderClientCompat.acquireUnstableContentProviderClient(resolver, authority);
    if (client == null) {
        throw new RemoteException("Failed to acquire provider for " + authority);
    }
    ContentProviderClientCompat.setDetectNotResponding(client, PROVIDER_ANR_TIMEOUT);
    return client;
}
Also used : RemoteException(android.os.RemoteException) ContentProviderClient(android.content.ContentProviderClient)

Aggregations

ContentProviderClient (android.content.ContentProviderClient)93 RemoteException (android.os.RemoteException)30 Cursor (android.database.Cursor)28 Uri (android.net.Uri)24 ContentResolver (android.content.ContentResolver)18 Bundle (android.os.Bundle)18 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)9 Test (org.junit.Test)9 OperationCanceledException (android.os.OperationCanceledException)8 CancellationSignal (android.os.CancellationSignal)7 IContentProvider (android.content.IContentProvider)6 ActivityManager (android.app.ActivityManager)5 AlertDialog (android.app.AlertDialog)5 ClipData (android.content.ClipData)5 ComponentName (android.content.ComponentName)5 Intent (android.content.Intent)5 ServiceConnection (android.content.ServiceConnection)5 UriPermission (android.content.UriPermission)5