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

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

Merge "Add a null check for visibleFile." into oc-dev am: 1fb3e569

am: 8a9a686c

Change-Id: I7ed34f0644cd219e5a1f295c91f3b81605526b15
parents 7d68da20 8a9a686c
Loading
Loading
Loading
Loading
+19 −10
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.content;

import android.annotation.CallSuper;
import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
@@ -150,7 +151,9 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        return childId;
    }

    private void addFolderToMediaStore(File visibleFolder) {
    private void addFolderToMediaStore(@Nullable File visibleFolder) {
        // visibleFolder is null if we're adding a folder to external thumb drive or SD card.
        if (visibleFolder != null) {
            assert (visibleFolder.isDirectory());

            final ContentResolver resolver = getContext().getContentResolver();
@@ -159,6 +162,7 @@ public abstract class FileSystemProvider extends DocumentsProvider {
            values.put(MediaStore.Files.FileColumns.DATA, visibleFolder.getAbsolutePath());
            resolver.insert(uri, values);
        }
    }

    @Override
    public String renameDocument(String docId, String displayName) throws FileNotFoundException {
@@ -204,8 +208,12 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        return docId;
    }

    private void moveInMediaStore(File oldVisibleFile, File newVisibleFile) {
        if (newVisibleFile != null) {
    private void moveInMediaStore(@Nullable File oldVisibleFile, @Nullable File newVisibleFile) {
        // visibleFolders are null if we're moving a document in external thumb drive or SD card.
        //
        // 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.
        if (oldVisibleFile != null && newVisibleFile != null) {
            final ContentResolver resolver = getContext().getContentResolver();
            final Uri externalUri = newVisibleFile.isDirectory()
                    ? MediaStore.Files.getDirectoryUri("external")
@@ -241,8 +249,9 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        removeFromMediaStore(visibleFile, isDirectory);
    }

    private void removeFromMediaStore(File visibleFile, boolean isFolder)
    private void removeFromMediaStore(@Nullable File visibleFile, boolean isFolder)
            throws FileNotFoundException {
        // visibleFolder is null if we're removing a document from external thumb drive or SD card.
        if (visibleFile != null) {
            final ContentResolver resolver = getContext().getContentResolver();
            final Uri externalUri = MediaStore.Files.getContentUri("external");