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

Commit 26ea29a2 authored by Manish Singh's avatar Manish Singh Committed by Automerger Merge Worker
Browse files

Merge "Pass the media capabilities uid when opening media" into sc-dev am: 36723eae

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13454823

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I430bd2d4678549e27f21777b33b7771bbdae4337
parents a25b9589 36723eae
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.
     *