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

Commit cd144b47 authored by Garfield Tan's avatar Garfield Tan Committed by android-build-merger
Browse files

Merge "Merge "Clear calling id before updating MediaStore." into oc-dr1-dev...

Merge "Merge "Clear calling id before updating MediaStore." into oc-dr1-dev am: 28042d09" into oc-dr1-dev-plus-aosp
am: 083a491f

Change-Id: I293ca3e7765629a1f04e14aad2841bcb7d1f763a
parents 3dcc20f2 083a491f
Loading
Loading
Loading
Loading
+54 −35
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import android.database.MatrixCursor;
import android.database.MatrixCursor.RowBuilder;
import android.database.MatrixCursor.RowBuilder;
import android.graphics.Point;
import android.graphics.Point;
import android.net.Uri;
import android.net.Uri;
import android.os.Binder;
import android.os.CancellationSignal;
import android.os.CancellationSignal;
import android.os.FileObserver;
import android.os.FileObserver;
import android.os.FileUtils;
import android.os.FileUtils;
@@ -156,11 +157,17 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        if (visibleFolder != null) {
        if (visibleFolder != null) {
            assert (visibleFolder.isDirectory());
            assert (visibleFolder.isDirectory());


            final long token = Binder.clearCallingIdentity();

            try {
                final ContentResolver resolver = getContext().getContentResolver();
                final ContentResolver resolver = getContext().getContentResolver();
                final Uri uri = MediaStore.Files.getDirectoryUri("external");
                final Uri uri = MediaStore.Files.getDirectoryUri("external");
                ContentValues values = new ContentValues();
                ContentValues values = new ContentValues();
                values.put(MediaStore.Files.FileColumns.DATA, visibleFolder.getAbsolutePath());
                values.put(MediaStore.Files.FileColumns.DATA, visibleFolder.getAbsolutePath());
                resolver.insert(uri, values);
                resolver.insert(uri, values);
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }
        }
    }
    }


@@ -214,6 +221,9 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        // They should be all null or not null at the same time. File#renameTo() doesn't work across
        // They should be all null or not null at the same time. File#renameTo() doesn't work across
        // volumes so an exception will be thrown before calling this method.
        // volumes so an exception will be thrown before calling this method.
        if (oldVisibleFile != null && newVisibleFile != null) {
        if (oldVisibleFile != null && newVisibleFile != null) {
            final long token = Binder.clearCallingIdentity();

            try {
                final ContentResolver resolver = getContext().getContentResolver();
                final ContentResolver resolver = getContext().getContentResolver();
                final Uri externalUri = newVisibleFile.isDirectory()
                final Uri externalUri = newVisibleFile.isDirectory()
                        ? MediaStore.Files.getDirectoryUri("external")
                        ? MediaStore.Files.getDirectoryUri("external")
@@ -230,6 +240,9 @@ public abstract class FileSystemProvider extends DocumentsProvider {
                        values,
                        values,
                        "_data LIKE ? AND lower(_data)=lower(?)",
                        "_data LIKE ? AND lower(_data)=lower(?)",
                        new String[]{path, path});
                        new String[]{path, path});
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }
        }
    }
    }


@@ -253,6 +266,9 @@ public abstract class FileSystemProvider extends DocumentsProvider {
            throws FileNotFoundException {
            throws FileNotFoundException {
        // visibleFolder is null if we're removing a document from external thumb drive or SD card.
        // visibleFolder is null if we're removing a document from external thumb drive or SD card.
        if (visibleFile != null) {
        if (visibleFile != null) {
            final long token = Binder.clearCallingIdentity();

            try {
                final ContentResolver resolver = getContext().getContentResolver();
                final ContentResolver resolver = getContext().getContentResolver();
                final Uri externalUri = MediaStore.Files.getContentUri("external");
                final Uri externalUri = MediaStore.Files.getContentUri("external");


@@ -270,6 +286,9 @@ public abstract class FileSystemProvider extends DocumentsProvider {
                resolver.delete(externalUri,
                resolver.delete(externalUri,
                        "_data LIKE ?1 AND lower(_data)=lower(?2)",
                        "_data LIKE ?1 AND lower(_data)=lower(?2)",
                        new String[]{path, path});
                        new String[]{path, path});
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }
        }
    }
    }