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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations