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

Commit 6f903389 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by android-build-merger
Browse files

Fix copying files from archives with a keyboard shortcut.

am: a0115862

Change-Id: I8d40dc22bea29b2d5d72aca6abbabceb35f97e5b
parents 42a54d28 a0115862
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -181,21 +181,25 @@ abstract public class Job implements Runnable {
        return Uri.parse(String.format("data,%s-%s", tag, id));
    }

    ContentProviderClient getClient(DocumentInfo doc) throws RemoteException {
        ContentProviderClient client = mClients.get(doc.authority);
    ContentProviderClient getClient(Uri uri) throws RemoteException {
        ContentProviderClient client = mClients.get(uri.getAuthority());
        if (client == null) {
            // Acquire content providers.
            client = acquireUnstableProviderOrThrow(
                    getContentResolver(),
                    doc.authority);
                    uri.getAuthority());

            mClients.put(doc.authority, client);
            mClients.put(uri.getAuthority(), client);
        }

        assert(client != null);
        return client;
    }

    ContentProviderClient getClient(DocumentInfo doc) throws RemoteException {
        return getClient(doc.derivedUri);
    }

    final void cleanup() {
        for (ContentProviderClient client : mClients.values()) {
            ContentProviderClient.releaseQuietly(client);
+22 −17
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public abstract class ResolvedResourcesJob extends Job {
    private static final String TAG = "ResolvedResourcesJob";

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

    ResolvedResourcesJob(Context service, Listener listener, String id, @OpType int opType,
            DocumentStack destination, UrisSupplier srcs) {
@@ -61,6 +61,25 @@ public abstract class ResolvedResourcesJob extends Job {
            return false;
        }

        // Acquire all source archived documents, so they are not gone while copying from.
        try {
            Iterable<Uri> uris = mResourceUris.getUris(appContext);
            for (Uri uri : uris) {
                try {
                    if (ArchivesProvider.AUTHORITY.equals(uri.getAuthority())) {
                        ArchivesProvider.acquireArchive(getClient(uri), uri);
                        mAcquiredArchivedUris.add(uri);
                    }
                } catch (RemoteException e) {
                    Log.e(TAG, "Failed to acquire an archive.");
                    return false;
                }
            }
        } catch (IOException e) {
            Log.e(TAG, "Failed to read list of target resource Uris. Cannot continue.", e);
            return false;
        }

        int docsResolved = buildDocumentList();
        if (!isCanceled() && docsResolved < mResourceUris.getItemCount()) {
            if (docsResolved == 0) {
@@ -71,29 +90,15 @@ public abstract class ResolvedResourcesJob extends Job {
            }
        }

        // Acquire all source archived documents, so they are not gone while copying from.
        try {
            for (DocumentInfo doc : mResolvedDocs) {
                if (doc.isInArchive()) {
                    final ContentProviderClient client = getClient(doc);
                    ArchivesProvider.acquireArchive(client, doc.derivedUri);
                    mAcquiredArchivedDocs.add(doc);
                }
            }
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to acquire an archive.");
            return false;
        }

        return true;
    }

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