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

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

Merge "Wire removeDocument() to Jobs." into nyc-dev

parents 1142b265 db87543d
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -376,7 +376,7 @@ class CopyJob extends Job {
        if (Document.MIME_TYPE_DIR.equals(src.mimeType)) {
            copyDirectoryHelper(src, dstInfo);
        } else {
            copyFileHelper(src, dstInfo, dstMimeType);
            copyFileHelper(src, dstInfo, dest, dstMimeType);
        }
    }

@@ -439,13 +439,14 @@ class CopyJob extends Job {
    /**
     * Handles copying a single file.
     *
     * @param srcUriInfo Info of the file to copy from.
     * @param dstUriInfo Info of the *file* to copy to. Must be created beforehand.
     * @param src Info of the file to copy from.
     * @param dest Info of the *file* to copy to. Must be created beforehand.
     * @param destParent Info of the parent of the destination.
     * @param mimeType Mime type for the target. Can be different than source for virtual files.
     * @throws ResourceException
     */
    private void copyFileHelper(DocumentInfo src, DocumentInfo dest, String mimeType)
            throws ResourceException {
    private void copyFileHelper(DocumentInfo src, DocumentInfo dest, DocumentInfo destParent,
            String mimeType) throws ResourceException {
        CancellationSignal canceller = new CancellationSignal();
        AssetFileDescriptor srcFileAsAsset = null;
        ParcelFileDescriptor srcFile = null;
@@ -527,8 +528,8 @@ class CopyJob extends Job {
                if (DEBUG) Log.d(TAG, "Cleaning up failed operation leftovers.");
                canceller.cancel();
                try {
                    DocumentsContract.deleteDocument(getClient(dest), dest.derivedUri);
                } catch (RemoteException | RuntimeException e) {
                    deleteDocument(dest, destParent);
                } catch (ResourceException e) {
                    Log.w(TAG, "Failed to cleanup after copy error: " + src.derivedUri, e);
                }
            }
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ final class DeleteJob extends Job {
        for (DocumentInfo doc : mSrcs) {
            if (DEBUG) Log.d(TAG, "Deleting document @ " + doc.derivedUri);
            try {
                deleteDocument(doc);
                deleteDocument(doc, mSrcParent);
            } catch (ResourceException e) {
                Log.e(TAG, "Failed to delete document @ " + doc.derivedUri);
                onFileFailed(doc);
+10 −3
Original line number Diff line number Diff line
@@ -184,10 +184,17 @@ abstract public class Job implements Runnable {
        return false;
    }

    final void deleteDocument(DocumentInfo doc) throws ResourceException {
    final void deleteDocument(DocumentInfo doc, DocumentInfo parent) throws ResourceException {
        try {
            if (doc.isRemoveSupported()) {
                DocumentsContract.removeDocument(getClient(doc), doc.derivedUri, parent.derivedUri);
            } else if (doc.isDeleteSupported()) {
                DocumentsContract.deleteDocument(getClient(doc), doc.derivedUri);
        } catch (Exception e) {
            } else {
                throw new ResourceException("Unable to delete source document as the file is " +
                        "not deletable nor removable: %s.", doc.derivedUri);
            }
        } catch (RemoteException | RuntimeException e) {
            throw new ResourceException("Failed to delete file %s due to an exception.",
                    doc.derivedUri, e);
        }
+3 −0
Original line number Diff line number Diff line
@@ -115,6 +115,9 @@ final class MoveJob extends CopyJob {

        // If we couldn't do an optimized copy...we fall back to vanilla byte copy.
        byteCopyDocument(src, dest);

        // Remove the source document.
        deleteDocument(src, srcParent);
    }

    @Override