Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 36723eae authored by Manish Singh's avatar Manish Singh Committed by Android (Google) Code Review
Browse files

Merge "Pass the media capabilities uid when opening media" into sc-dev

parents ba5fbd7a 2ca39c02
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.database.MatrixCursor;
import android.database.MatrixCursor.RowBuilder;
import android.graphics.Point;
import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.FileObserver;
@@ -504,7 +505,7 @@ public abstract class FileSystemProvider extends DocumentsProvider {

        final int pfdMode = ParcelFileDescriptor.parseMode(mode);
        if (pfdMode == ParcelFileDescriptor.MODE_READ_ONLY || visibleFile == null) {
            return ParcelFileDescriptor.open(file, pfdMode);
            return openFileForRead(file);
        } else {
            try {
                // When finished writing, kick off media scanner
@@ -519,6 +520,24 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        }
    }

    private ParcelFileDescriptor openFileForRead(final File target) throws FileNotFoundException {
        final Uri uri = MediaStore.scanFile(getContext().getContentResolver(), target);

        // Passing the calling uid via EXTRA_MEDIA_CAPABILITIES_UID, so that the decision to
        // transcode or not transcode can be made based upon the calling app's uid, and not based
        // upon the Provider's uid.
        final Bundle opts = new Bundle();
        opts.putInt(MediaStore.EXTRA_MEDIA_CAPABILITIES_UID, Binder.getCallingUid());

        final AssetFileDescriptor afd =
                getContext().getContentResolver().openTypedAssetFileDescriptor(uri, "*/*", opts);
        if (afd == null) {
            return null;
        }

        return afd.getParcelFileDescriptor();
    }

    /**
     * Test if the file matches the query arguments.
     *