Skip to content

Commit

Permalink
fix: allow write access to parcelFileDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcohn committed Jul 28, 2020
1 parent 609d0b9 commit 1a22a83
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,12 @@ static List<FFmpegExecution> listFFmpegExecutions() {
public static String getCommandParameter(Context context, Uri uri) {

String displayName = "unknown";
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
int flags = 0;
final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
displayName = cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME));
flags = cursor.getInt(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_FLAGS));
}
} catch (Throwable ex) {
Log.e(TAG, "failed to get column", ex);
Expand All @@ -774,12 +776,13 @@ public static String getCommandParameter(Context context, Uri uri) {
cursor.close();
}

final String openMode = (flags & DocumentsContract.Document.FLAG_SUPPORTS_WRITE) == 0 ? "r" : "rw";
int fd = -1;
try {
ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, "r");
ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver().openFileDescriptor(uri, openMode);
fd = parcelFileDescriptor.detachFd();
} catch (Throwable e) {
Log.e(TAG, "obtaining ParcelFileDescriptor for " + uri, e);
Log.e(TAG, "obtaining " + openMode + " ParcelFileDescriptor for " + uri, e);
}

return "file:/proc/self/" + fd + "/" + displayName;
Expand Down

0 comments on commit 1a22a83

Please sign in to comment.