This source file includes following definitions.
- openContentUriForRead
- contentUriExists
- getParcelFileDescriptor
package org.chromium.base;
import android.content.ContentResolver;
import android.content.Context;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.util.Log;
abstract class ContentUriUtils {
private static final String TAG = "ContentUriUtils";
private ContentUriUtils() {}
@CalledByNative
public static int openContentUriForRead(Context context, String uriString) {
ParcelFileDescriptor pfd = getParcelFileDescriptor(context, uriString);
if (pfd != null) {
return pfd.detachFd();
}
return -1;
}
@CalledByNative
public static boolean contentUriExists(Context context, String uriString) {
ParcelFileDescriptor pfd = getParcelFileDescriptor(context, uriString);
if (pfd == null) {
return false;
}
return true;
}
private static ParcelFileDescriptor getParcelFileDescriptor(Context context, String uriString) {
ContentResolver resolver = context.getContentResolver();
Uri uri = Uri.parse(uriString);
ParcelFileDescriptor pfd = null;
try {
pfd = resolver.openFileDescriptor(uri, "r");
} catch (java.io.FileNotFoundException e) {
Log.w(TAG, "Cannot find content uri: " + uriString, e);
}
return pfd;
}
}