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

Commit 9a1507aa authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

FileBridge needs to keep strong reference to PFD.

Even though we've grabbed the underlying FD, the PFD could be GC'ed
and when finalized it would end up closing the underlying FD.  This
fix ties the PFD object lifecycle to the returned OutputStream.

Bug: 17183379
Change-Id: Ibee8f4cf78fee357181a250d15f2a653294b2877
parent 932a07ce
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -623,7 +623,7 @@ public class PackageInstaller {
            try {
                final ParcelFileDescriptor clientSocket = mSession.openWrite(name,
                        offsetBytes, lengthBytes);
                return new FileBridge.FileBridgeOutputStream(clientSocket.getFileDescriptor());
                return new FileBridge.FileBridgeOutputStream(clientSocket);
            } catch (RuntimeException e) {
                ExceptionUtils.maybeUnwrapIOException(e);
                throw e;
+4 −2
Original line number Diff line number Diff line
@@ -131,11 +131,13 @@ public class FileBridge extends Thread {
    }

    public static class FileBridgeOutputStream extends OutputStream {
        private final ParcelFileDescriptor mClientPfd;
        private final FileDescriptor mClient;
        private final byte[] mTemp = new byte[MSG_LENGTH];

        public FileBridgeOutputStream(FileDescriptor client) {
            mClient = client;
        public FileBridgeOutputStream(ParcelFileDescriptor clientPfd) {
            mClientPfd = clientPfd;
            mClient = clientPfd.getFileDescriptor();
        }

        @Override