Merge changes I9350ec13,I809d9191,I235f727d,I1930f3ba

am: a0c949d5de

Change-Id: I1633d9eae6f162e338990766e62e3aa3873df606
This commit is contained in:
Josh Gao
2019-07-31 21:46:23 -07:00
committed by android-build-merger
2 changed files with 13 additions and 8 deletions

View File

@@ -25,6 +25,8 @@ import android.system.OsConstants;
import dalvik.system.VMRuntime;
import libcore.io.IoUtils;
import java.io.Closeable;
import java.io.FileDescriptor;
import java.nio.ByteBuffer;
@@ -293,21 +295,24 @@ public final class SharedMemory implements Parcelable, Closeable {
* Cleaner that closes the FD
*/
private static final class Closer implements Runnable {
private int mFd;
// This is a copy of the FileDescriptor we're attached to, in order to avoid a reference
// cycle.
private FileDescriptor mFd;
private MemoryRegistration mMemoryReference;
private Closer(int fd, MemoryRegistration memoryReference) {
mFd = fd;
mFd = new FileDescriptor();
mFd.setInt$(fd);
IoUtils.setFdOwner(mFd, this);
mMemoryReference = memoryReference;
}
@Override
public void run() {
try {
FileDescriptor fd = new FileDescriptor();
fd.setInt$(mFd);
Os.close(fd);
} catch (ErrnoException e) { /* swallow error */ }
IoUtils.closeQuietly(mFd);
mFd = null;
mMemoryReference.release();
mMemoryReference = null;
}

View File

@@ -191,7 +191,7 @@ public class GraphicsStatsService extends IGraphicsStats.Stub {
if (!file.getFileDescriptor().valid()) {
throw new IllegalStateException("Invalid file descriptor");
}
return new ParcelFileDescriptor(file.getFileDescriptor());
return ParcelFileDescriptor.dup(file.getFileDescriptor());
} catch (IOException ex) {
throw new IllegalStateException("Failed to get PFD from memory file", ex);
}