android.os.ParcelFileDescriptor#detachFd ( )源码实例Demo

下面列出了android.os.ParcelFileDescriptor#detachFd ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: MemoryIntArray.java
private MemoryIntArray(Parcel parcel) throws IOException {
    mIsOwner = false;
    ParcelFileDescriptor pfd = parcel.readParcelable(null);
    if (pfd == null) {
        throw new IOException("No backing file descriptor");
    }
    mFd = pfd.detachFd();
    mMemoryAddr = nativeOpen(mFd, mIsOwner);
    mCloseGuard.open("close");
}
 
源代码2 项目: android_9.0.0_r45   文件: MemoryIntArray.java
@Override
public void writeToParcel(Parcel parcel, int flags) {
    ParcelFileDescriptor pfd = ParcelFileDescriptor.adoptFd(mFd);
    try {
        // Don't let writing to a parcel to close our fd - plz
        parcel.writeParcelable(pfd, flags & ~Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
    } finally {
        pfd.detachFd();
    }
}
 
源代码3 项目: 365browser   文件: Linker.java
public LibInfo(Parcel in) {
    mLoadAddress = in.readLong();
    mLoadSize = in.readLong();
    mRelroStart = in.readLong();
    mRelroSize = in.readLong();
    ParcelFileDescriptor fd = ParcelFileDescriptor.CREATOR.createFromParcel(in);
    // If CreateSharedRelro fails, the OS file descriptor will be -1 and |fd| will be null.
    mRelroFd = (fd == null) ? -1 : fd.detachFd();
}
 
源代码4 项目: android-chromium   文件: Linker.java
public LibInfo(Parcel in) {
    mLoadAddress = in.readLong();
    mLoadSize = in.readLong();
    mRelroStart = in.readLong();
    mRelroSize = in.readLong();
    ParcelFileDescriptor fd = in.readFileDescriptor();
    mRelroFd = fd.detachFd();
}
 
源代码5 项目: android-chromium   文件: Linker.java
public LibInfo(Parcel in) {
    mLoadAddress = in.readLong();
    mLoadSize = in.readLong();
    mRelroStart = in.readLong();
    mRelroSize = in.readLong();
    ParcelFileDescriptor fd = in.readFileDescriptor();
    mRelroFd = fd.detachFd();
}
 
源代码6 项目: cronet   文件: AndroidNetworkLibrary.java
/**
 * Tag socket referenced by {@code ifd} with {@code tag} for UID {@code uid}.
 *
 * Assumes thread UID tag isn't set upon entry, and ensures thread UID tag isn't set upon exit.
 * Unfortunately there is no TrafficStatis.getThreadStatsUid().
 */
@CalledByNative
private static void tagSocket(int ifd, int uid, int tag) throws IOException {
    // Set thread tags.
    int oldTag = TrafficStats.getThreadStatsTag();
    if (tag != oldTag) {
        TrafficStats.setThreadStatsTag(tag);
    }
    if (uid != TrafficStatsUid.UNSET) {
        ThreadStatsUid.set(uid);
    }

    // Apply thread tags to socket.

    // First, convert integer file descriptor (ifd) to FileDescriptor.
    final ParcelFileDescriptor pfd;
    final FileDescriptor fd;
    // The only supported way to generate a FileDescriptor from an integer file
    // descriptor is via ParcelFileDescriptor.adoptFd(). Unfortunately prior to Android
    // Marshmallow ParcelFileDescriptor.detachFd() didn't actually detach from the
    // FileDescriptor, so use reflection to set {@code fd} into the FileDescriptor for
    // versions prior to Marshmallow. Here's the fix that went into Marshmallow:
    // https://android.googlesource.com/platform/frameworks/base/+/b30ad6f
    if (Build.VERSION.SDK_INT < VERSION_CODES.M) {
        pfd = null;
        fd = SetFileDescriptor.createWithFd(ifd);
    } else {
        pfd = ParcelFileDescriptor.adoptFd(ifd);
        fd = pfd.getFileDescriptor();
    }
    // Second, convert FileDescriptor to Socket.
    Socket s = new SocketFd(fd);
    // Third, tag the Socket.
    TrafficStats.tagSocket(s);
    s.close(); // No-op but always good to close() Closeables.
    // Have ParcelFileDescriptor relinquish ownership of the file descriptor.
    if (pfd != null) {
        pfd.detachFd();
    }

    // Restore prior thread tags.
    if (tag != oldTag) {
        TrafficStats.setThreadStatsTag(oldTag);
    }
    if (uid != TrafficStatsUid.UNSET) {
        ThreadStatsUid.clear();
    }
}