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

Commit a4583a4d authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by Android (Google) Code Review
Browse files

Merge "Add StubProvider::isChildDocument()."

parents 8772936e 78699be5
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.database.MatrixCursor.RowBuilder;
import android.database.MatrixCursor;
import android.graphics.Point;
import android.os.CancellationSignal;
import android.os.FileUtils;
import android.os.ParcelFileDescriptor;
import android.provider.DocumentsContract.Document;
import android.provider.DocumentsContract.Root;
@@ -66,7 +67,7 @@ public class StubProvider extends DocumentsProvider {
        final MatrixCursor result = new MatrixCursor(projection != null ? projection : DEFAULT_ROOT_PROJECTION);
        final RowBuilder row = result.newRow();
        row.add(Root.COLUMN_ROOT_ID, MY_ROOT_ID);
        row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE);
        row.add(Root.COLUMN_FLAGS, Root.FLAG_SUPPORTS_CREATE | Root.FLAG_SUPPORTS_IS_CHILD);
        row.add(Root.COLUMN_TITLE, "Foobar SD 4GB");
        row.add(Root.COLUMN_DOCUMENT_ID, mRootDocumentId);
        row.add(Root.COLUMN_AVAILABLE_BYTES, STORAGE_SIZE - mStorageUsedBytes);
@@ -84,6 +85,17 @@ public class StubProvider extends DocumentsProvider {
        return result;
    }

    @Override
    public boolean isChildDocument(String parentDocId, String docId) {
        try {
            final File parentFile = getFileForDocumentId(parentDocId).getCanonicalFile();
            final File childFile = getFileForDocumentId(docId).getCanonicalFile();
            return FileUtils.contains(parentFile, childFile);
        } catch (IOException e) {
            throw new IllegalArgumentException();
        }
    }

    @Override
    public String createDocument(String parentDocumentId, String mimeType, String displayName)
            throws FileNotFoundException {
@@ -170,6 +182,10 @@ public class StubProvider extends DocumentsProvider {
        return file.getAbsolutePath();
    }

    private File getFileForDocumentId(String documentId) {
        return new File(documentId);
    }

    private void removeRecursively(File file) {
        for (File childFile : file.listFiles()) {
            if (childFile.isDirectory()) {