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
This commit is contained in:
Jeff Sharkey
2014-08-28 20:38:10 -07:00
parent 932a07cefe
commit 9a1507aa10
2 changed files with 5 additions and 3 deletions

View File

@@ -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;

View File

@@ -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