Example usage for android.os ParcelFileDescriptor detachFd

List of usage examples for android.os ParcelFileDescriptor detachFd

Introduction

In this page you can find the example usage for android.os ParcelFileDescriptor detachFd.

Prototype

public int detachFd() 

Source Link

Document

Return the native fd int for this ParcelFileDescriptor and detach it from the object here.

Usage

From source file:com.frostwire.android.LollipopFileSystem.java

private static OutputStream openOutputStream(Context context, DocumentFile f) throws IOException {
    ContentResolver cr = context.getContentResolver();
    ParcelFileDescriptor pfd = cr.openFileDescriptor(f.getUri(), "rw");

    int fd = pfd.detachFd(); // this trick the internal system to trigger the media scanner on nothing
    pfd = ParcelFileDescriptor.adoptFd(fd);

    return new AutoSyncOutputStream(pfd);
}

From source file:com.frostwire.android.LollipopFileSystem.java

public int openFD(File file, String mode) {
    if (!("r".equals(mode) || "w".equals(mode) || "rw".equals(mode))) {
        LOG.error("Only r, w or rw modes supported");
        return -1;
    }/*from w  w  w . ja v  a2  s  .c  o  m*/

    DocumentFile f = getFile(app, file, true);
    if (f == null) {
        LOG.error("Unable to obtain or create document for file: " + file);
        return -1;
    }

    try {
        ContentResolver cr = app.getContentResolver();
        ParcelFileDescriptor fd = cr.openFileDescriptor(f.getUri(), mode);
        if (fd == null) {
            return -1;
        }
        return fd.detachFd();
    } catch (Throwable e) {
        LOG.error("Unable to get native fd", e);
        return -1;
    }
}

From source file:ca.psiphon.PsiphonTunnel.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
private void startTun2Socks(final ParcelFileDescriptor vpnInterfaceFileDescriptor, final int vpnInterfaceMTU,
        final String vpnIpAddress, final String vpnNetMask, final String socksServerAddress,
        final String udpgwServerAddress, final boolean udpgwTransparentDNS) {
    if (mTun2SocksThread != null) {
        return;// w  w  w .j  a va 2  s. c o m
    }
    mTun2SocksThread = new Thread(new Runnable() {
        @Override
        public void run() {
            runTun2Socks(vpnInterfaceFileDescriptor.detachFd(), vpnInterfaceMTU, vpnIpAddress, vpnNetMask,
                    socksServerAddress, udpgwServerAddress, udpgwTransparentDNS ? 1 : 0);
        }
    });
    mTun2SocksThread.start();
    mHostService.onDiagnosticMessage("tun2socks started");
}