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

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

Merge "Release only acquired docs in DocumentsUI." into arc-apps

parents d2d654c7 13d8dee3
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public abstract class ResolvedResourcesJob extends Job {
    private static final String TAG = "ResolvedResourcesJob";

    final List<DocumentInfo> mResolvedDocs;
    final List<DocumentInfo> mAcquiredArchivedDocs = new ArrayList<>();

    ResolvedResourcesJob(Context service, Listener listener, String id, @OpType int opType,
            DocumentStack destination, UrisSupplier srcs) {
@@ -51,9 +52,8 @@ public abstract class ResolvedResourcesJob extends Job {

        assert(srcs.getItemCount() > 0);

        // delay the initialization of it to setUp() because it may be IO extensive.
        // Delay the initialization of it to setUp() because it may be IO extensive.
        mResolvedDocs = new ArrayList<>(srcs.getItemCount());

    }

    boolean setUp() {
@@ -71,11 +71,13 @@ public abstract class ResolvedResourcesJob extends Job {
            }
        }

        // Acquire all source archives, so they are not gone while copying from.
        // Acquire all source archived documents, so they are not gone while copying from.
        try {
            for (DocumentInfo doc : mResolvedDocs) {
                if (doc.isInArchive()) {
                    ArchivesProvider.acquireArchive(getClient(doc), doc.derivedUri);
                    final ContentProviderClient client = getClient(doc);
                    ArchivesProvider.acquireArchive(client, doc.derivedUri);
                    mAcquiredArchivedDocs.add(doc);
                }
            }
        } catch (RemoteException e) {
@@ -88,14 +90,12 @@ public abstract class ResolvedResourcesJob extends Job {

    @Override
    void finish() {
        // Release all archives.
        for (DocumentInfo doc : mResolvedDocs) {
            if (doc.isInArchive()) {
        // Release all archived documents.
        for (DocumentInfo doc : mAcquiredArchivedDocs) {
            try {
                ArchivesProvider.releaseArchive(getClient(doc), doc.derivedUri);
            } catch (RemoteException e) {
                    Log.e(TAG, "Failed to release an archive.");
                }
                Log.e(TAG, "Failed to release an archived document.");
            }
        }
    }