Fix file descriptor ownership.

Previously, we attempt to pass ownership of the fd owned by a
ParcelFileDescriptor to a FileInputStream, which explodes when we try to
close it.

Bug: http://b/156867945
Bug: http://b/159264419
Test: treehugger
Change-Id: I9d5124658beb50f0a08499ed09e652037cb9ae66
(cherry picked from commit 3e29e4a39c)
This commit is contained in:
Josh Gao
2020-06-12 15:00:01 -07:00
parent 85cf423804
commit ead6dacf40

View File

@@ -1,10 +1,10 @@
package com.android.server.backup.restore;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor.AutoCloseInputStream;
import libcore.io.IoUtils;
import java.io.FileInputStream;
import java.io.InputStream;
class FullRestoreEngineThread implements Runnable {
@@ -19,7 +19,7 @@ class FullRestoreEngineThread implements Runnable {
// We *do* want this FileInputStream to own the underlying fd, so that
// when we are finished with it, it closes this end of the pipe in a way
// that signals its other end.
mEngineStream = new FileInputStream(engineSocket.getFileDescriptor(), true);
mEngineStream = new AutoCloseInputStream(engineSocket);
// Tell it to be sure to leave the agent instance up after finishing
mMustKillAgent = false;
}