Search in sources :

Example 76 with ContentProviderClient

use of android.content.ContentProviderClient in project MiMangaNu by raulhaag.

the class ExifUtils method getExifOrientation.

/**
 * Try to get the exif orientation of the passed image uri
 *
 * @param context
 * @param uri
 * @return
 */
public static int getExifOrientation(Context context, Uri uri) {
    final String scheme = uri.getScheme();
    ContentProviderClient provider = null;
    if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) {
        return getExifOrientation(uri.getPath());
    } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
        try {
            provider = context.getContentResolver().acquireContentProviderClient(uri);
        } catch (SecurityException e) {
            if (provider != null) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    provider.close();
                } else {
                    provider.release();
                }
            }
            return 0;
        }
        if (provider != null) {
            Cursor result;
            try {
                result = provider.query(uri, new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null, null);
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }
            if (result == null) {
                return 0;
            }
            int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION);
            int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA);
            try {
                if (result.getCount() > 0) {
                    result.moveToFirst();
                    int rotation = 0;
                    if (orientationColumnIndex > -1) {
                        rotation = result.getInt(orientationColumnIndex);
                    }
                    if (dataColumnIndex > -1) {
                        String path = result.getString(dataColumnIndex);
                        rotation |= getExifOrientation(path);
                    }
                    return rotation;
                }
            } finally {
                result.close();
            }
        }
    }
    if (provider != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            provider.close();
        } else {
            provider.release();
        }
    }
    return 0;
}
Also used : Cursor(android.database.Cursor) ContentProviderClient(android.content.ContentProviderClient) IOException(java.io.IOException)

Example 77 with ContentProviderClient

use of android.content.ContentProviderClient in project GomoTest by suReZj.

the class ExifUtils method getExifOrientation.

/**
 * Try to get the exif orientation of the passed image uri
 *
 * @param context
 * @param uri
 * @return
 */
public static int getExifOrientation(Context context, Uri uri) {
    final String scheme = uri.getScheme();
    ContentProviderClient provider = null;
    if (scheme == null || ContentResolver.SCHEME_FILE.equals(scheme)) {
        return getExifOrientation(uri.getPath());
    } else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
        try {
            provider = context.getContentResolver().acquireContentProviderClient(uri);
        } catch (SecurityException e) {
            return 0;
        }
        if (provider != null) {
            Cursor result;
            try {
                result = provider.query(uri, new String[] { Images.ImageColumns.ORIENTATION, Images.ImageColumns.DATA }, null, null, null);
            } catch (Exception e) {
                e.printStackTrace();
                return 0;
            }
            if (result == null) {
                return 0;
            }
            int orientationColumnIndex = result.getColumnIndex(Images.ImageColumns.ORIENTATION);
            int dataColumnIndex = result.getColumnIndex(Images.ImageColumns.DATA);
            try {
                if (result.getCount() > 0) {
                    result.moveToFirst();
                    int rotation = 0;
                    if (orientationColumnIndex > -1) {
                        rotation = result.getInt(orientationColumnIndex);
                    }
                    if (dataColumnIndex > -1) {
                        String path = result.getString(dataColumnIndex);
                        rotation |= getExifOrientation(path);
                    }
                    return rotation;
                }
            } finally {
                result.close();
            }
        }
    }
    return 0;
}
Also used : Cursor(android.database.Cursor) ContentProviderClient(android.content.ContentProviderClient) IOException(java.io.IOException)

Example 78 with ContentProviderClient

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

the class VClientImpl method acquireProviderClient.

@Override
public IBinder acquireProviderClient(ProviderInfo info) {
    if (mTempLock != null) {
        mTempLock.block();
    }
    if (!isBound()) {
        VClientImpl.get().bindApplication(info.packageName, info.processName);
    }
    IInterface provider = null;
    String[] authorities = info.authority.split(";");
    String authority = authorities.length == 0 ? info.authority : authorities[0];
    ContentResolver resolver = VirtualCore.get().getContext().getContentResolver();
    ContentProviderClient client = null;
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            client = resolver.acquireUnstableContentProviderClient(authority);
        } else {
            client = resolver.acquireContentProviderClient(authority);
        }
    } catch (Throwable e) {
        VLog.e(TAG, "", e);
    }
    if (client != null) {
        provider = mirror.android.content.ContentProviderClient.mContentProvider.get(client);
        client.release();
    }
    return provider != null ? provider.asBinder() : null;
}
Also used : IInterface(android.os.IInterface) ContentProviderClient(android.content.ContentProviderClient) ContentResolver(android.content.ContentResolver)

Example 79 with ContentProviderClient

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

the class DocumentsContract method uncompressDocument.

public static boolean uncompressDocument(ContentResolver resolver, Uri fromDocumentUri) {
    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);
        resolver.call(fromDocumentUri, METHOD_UNCOMPRESS_DOCUMENT, null, in);
        return true;
    } catch (Exception e) {
        Log.w(TAG, "Failed to uncompress 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 80 with ContentProviderClient

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

the class RootsCache method loadRootsForAuthority.

/**
 * Bring up requested provider and query for all active roots.
 */
private Collection<RootInfo> loadRootsForAuthority(ContentResolver resolver, String authority) {
    if (LOGD)
        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 List<RootInfo> roots = new ArrayList<>();
    final Uri rootsUri = DocumentsContract.buildRootsUri(authority);
    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);
        ContentProviderClientCompat.releaseQuietly(client);
    }
    return roots;
}
Also used : RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Uri(android.net.Uri) ContentProviderClient(android.content.ContentProviderClient)

Aggregations

ContentProviderClient (android.content.ContentProviderClient)94 RemoteException (android.os.RemoteException)30 Cursor (android.database.Cursor)28 Uri (android.net.Uri)24 Bundle (android.os.Bundle)19 ContentResolver (android.content.ContentResolver)18 FileNotFoundException (java.io.FileNotFoundException)15 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)10 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