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

Commit 2ca39c02 authored by Manish Singh's avatar Manish Singh
Browse files

Pass the media capabilities uid when opening media

FileSystemProvider should pass the uid of the calling app by setting
the EXTRA_MEDIA_CAPABILITIES_UID when opening a media, so that
TranscodeHelper can make decision to transcode or not transcode based on
the calling uid, and not based upon the Provider's uid.

BUG=176157500
Test: manual testing.

Change-Id: Ie08b94cf79c86e9f87639e4fbdd82b2732771187
parent c7e7d693
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.
     *