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

Commit e1e3ae86 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski
Browse files

Do not close streams prematurely.

Detach the FD from ParcelFileDescriptor to avoid the FD being closed by
the PFD's finalizer.

Test: Tested with some sample archives with images. Thumbnails show up.
Bug: 32838482
Change-Id: I8dff9b84bbabd19f1fc1a7af545781444c5f889f
parent 041eff91
Loading
Loading
Loading
Loading
+48 −34
Original line number Diff line number Diff line
@@ -199,6 +199,9 @@ public class Archive implements Closeable {
     *
     * If the file descriptor is not seekable, then a snapshot will be created.
     *
     * This method takes ownership for the passed descriptor. The caller must
     * not close it.
     *
     * @param context Context of the provider.
     * @param descriptor File descriptor for the archive's contents.
     * @param archiveUri Uri of the archive document.
@@ -208,8 +211,12 @@ public class Archive implements Closeable {
            Context context, ParcelFileDescriptor descriptor, Uri archiveUri,
            @Nullable Uri notificationUri)
            throws IOException {
        FileDescriptor fd = null;
        try {
            if (canSeek(descriptor)) {
            return new Archive(context, null, descriptor.getFileDescriptor(), archiveUri,
                fd = new FileDescriptor();
                fd.setInt$(descriptor.detachFd());
                return new Archive(context, null, fd, archiveUri,
                        notificationUri);
            }

@@ -246,6 +253,13 @@ public class Archive implements Closeable {
                    snapshotFile.delete();
                }
            }
        } catch (Exception e) {
            // Since the method takes ownership of the passed descriptor, close it
            // on exception.
            IoUtils.closeQuietly(descriptor);
            IoUtils.closeQuietly(fd);
            throw e;
        }
    }

    /**