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

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

源代码1 项目: FimiX8-RE   文件: FimiMediaPlayer.java
@TargetApi(13)
public void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException {
    if (VERSION.SDK_INT < 12) {
        try {
            Field f = fd.getClass().getDeclaredField("descriptor");
            f.setAccessible(true);
            _setDataSourceFd(f.getInt(fd));
            return;
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e2) {
            throw new RuntimeException(e2);
        }
    }
    ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(fd);
    try {
        _setDataSourceFd(pfd.getFd());
    } finally {
        pfd.close();
    }
}
 
源代码2 项目: FimiX8-RE   文件: FimiMediaPlayer.java
@TargetApi(13)
public void setDataSource(FileDescriptor fd) throws IOException, IllegalArgumentException, IllegalStateException {
    if (VERSION.SDK_INT < 12) {
        try {
            Field f = fd.getClass().getDeclaredField("descriptor");
            f.setAccessible(true);
            _setDataSourceFd(f.getInt(fd));
            return;
        } catch (NoSuchFieldException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e2) {
            throw new RuntimeException(e2);
        }
    }
    ParcelFileDescriptor pfd = ParcelFileDescriptor.dup(fd);
    try {
        _setDataSourceFd(pfd.getFd());
    } finally {
        pfd.close();
    }
}
 
源代码3 项目: container   文件: PackageInstallerSession.java
private ParcelFileDescriptor openReadInternal(String name) throws IOException {
    assertPreparedAndNotSealed("openRead");

    try {
        if (!FileUtils.isValidExtFilename(name)) {
            throw new IllegalArgumentException("Invalid name: " + name);
        }
        final File target = new File(resolveStageDir(), name);

        final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0);
        return ParcelFileDescriptor.dup(targetFd);

    } catch (ErrnoException e) {
        throw new IOException(e);
    }
}
 
源代码4 项目: AndroidComponentPlugin   文件: ActivityThread.java
public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) {
    DumpComponentInfo data = new DumpComponentInfo();
    try {
        data.fd = ParcelFileDescriptor.dup(fd);
        data.token = servicetoken;
        data.args = args;
        queueOrSendMessage(H.DUMP_SERVICE, data);
    } catch (IOException e) {
        Slog.w(TAG, "dumpService failed", e);
    }
}
 
源代码5 项目: AndroidComponentPlugin   文件: ActivityThread.java
public void dumpActivity(FileDescriptor fd, IBinder activitytoken,
        String prefix, String[] args) {
    DumpComponentInfo data = new DumpComponentInfo();
    try {
        data.fd = ParcelFileDescriptor.dup(fd);
        data.token = activitytoken;
        data.prefix = prefix;
        data.args = args;
        queueOrSendMessage(H.DUMP_ACTIVITY, data);
    } catch (IOException e) {
        Slog.w(TAG, "dumpActivity failed", e);
    }
}
 
源代码6 项目: AndroidComponentPlugin   文件: ActivityThread.java
public void dumpProvider(FileDescriptor fd, IBinder providertoken,
        String[] args) {
    DumpComponentInfo data = new DumpComponentInfo();
    try {
        data.fd = ParcelFileDescriptor.dup(fd);
        data.token = providertoken;
        data.args = args;
        queueOrSendMessage(H.DUMP_PROVIDER, data);
    } catch (IOException e) {
        Slog.w(TAG, "dumpProvider failed", e);
    }
}
 
源代码7 项目: AndroidComponentPlugin   文件: ActivityThread.java
public void dumpService(FileDescriptor fd, IBinder servicetoken, String[] args) {
    DumpComponentInfo data = new DumpComponentInfo();
    try {
        data.fd = ParcelFileDescriptor.dup(fd);
        data.token = servicetoken;
        data.args = args;
        queueOrSendMessage(H.DUMP_SERVICE, data);
    } catch (IOException e) {
        Slog.w(TAG, "dumpService failed", e);
    }
}
 
源代码8 项目: AndroidComponentPlugin   文件: ActivityThread.java
public void dumpActivity(FileDescriptor fd, IBinder activitytoken,
        String prefix, String[] args) {
    DumpComponentInfo data = new DumpComponentInfo();
    try {
        data.fd = ParcelFileDescriptor.dup(fd);
        data.token = activitytoken;
        data.prefix = prefix;
        data.args = args;
        queueOrSendMessage(H.DUMP_ACTIVITY, data);
    } catch (IOException e) {
        Slog.w(TAG, "dumpActivity failed", e);
    }
}
 
@Override
public void onSuccess(ParcelFileDescriptor profileReadFd) {
    mSuccess = true;
    try {
        // We need to dup the descriptor. We are in the same process as system server
        // and we will be receiving the same object (which will be closed on the
        // server side).
        mProfileReadFd = profileReadFd.dup();
    } catch (IOException e) {
        e.printStackTrace();
    }
    mDoneSignal.countDown();
}
 
源代码10 项目: android_9.0.0_r45   文件: IpSecUdpEncapResponse.java
public IpSecUdpEncapResponse(int inStatus, int inResourceId, int inPort, FileDescriptor inFd)
        throws IOException {
    if (inStatus == IpSecManager.Status.OK && inFd == null) {
        throw new IllegalArgumentException("Valid status implies FD must be non-null");
    }
    status = inStatus;
    resourceId = inResourceId;
    port = inPort;
    fileDescriptor = (status == IpSecManager.Status.OK) ? ParcelFileDescriptor.dup(inFd) : null;
}
 
源代码11 项目: FontProvider   文件: ParcelFileDescriptorUtils.java
public static ParcelFileDescriptor dupSilently(FileDescriptor fd) {
    try {
        return ParcelFileDescriptor.dup(fd);
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
 
源代码12 项目: container   文件: PackageInstallerSession.java
private ParcelFileDescriptor openWriteInternal(String name, long offsetBytes, long lengthBytes)
        throws IOException {
    // Quick sanity check of state, and allocate a pipe for ourselves. We
    // then do heavy disk allocation outside the lock, but this open pipe
    // will block any attempted install transitions.
    final FileBridge bridge;
    synchronized (mLock) {
        assertPreparedAndNotSealed("openWrite");

        bridge = new FileBridge();
        mBridges.add(bridge);
    }
    try {
        final File target = new File(resolveStageDir(), name);
        // TODO: this should delegate to DCS so the system process avoids
        // holding open FDs into containers.
        final FileDescriptor targetFd = Os.open(target.getAbsolutePath(),
                O_CREAT | O_WRONLY, 0644);
        // If caller specified a total length, allocate it for them. Free up
        // cache space to grow, if needed.
        if (lengthBytes > 0) {
            Os.posix_fallocate(targetFd, 0, lengthBytes);
        }
        if (offsetBytes > 0) {
            Os.lseek(targetFd, offsetBytes, OsConstants.SEEK_SET);
        }
        bridge.setTargetFile(targetFd);
        bridge.start();
        return ParcelFileDescriptor.dup(bridge.getClientSocket());

    } catch (ErrnoException e) {
        throw new IOException(e);
    }
}
 
源代码13 项目: AppOpsX   文件: ParamsFixer.java
private static Object marshallParamater(Class type,Object obj) {
    if (FileDescriptor.class.equals(type)  && obj instanceof FileDescriptor) {
        try {
            return ParcelFileDescriptor.dup(((FileDescriptor) obj));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return obj;
}