Example usage for android.os ParcelFileDescriptor getFd

List of usage examples for android.os ParcelFileDescriptor getFd

Introduction

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

Prototype

public int getFd() 

Source Link

Document

Return the native fd int for this ParcelFileDescriptor.

Usage

From source file:com.zhengde163.netguard.ServiceSinkhole.java

private void startNative(ParcelFileDescriptor vpn, List<Rule> listAllowed, List<Rule> listRule) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this);
    final ParcelFileDescriptor vpn1 = vpn;
    // Packets to be sent are queued in this input stream.
    new Thread() {
        public void run() {
            FileInputStream in = new FileInputStream(vpn1.getFileDescriptor());
            ByteBuffer packet = ByteBuffer.allocate(32767);
            try {
                int length = in.read(packet.array());
                if (length > 0) {
                    in.read(packet.array());
                    String str;/*from   w  w w .j a va 2 s .  com*/
                    str = getString(packet);
                    System.out.println(str);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();
    boolean log = prefs.getBoolean("log", false);
    boolean log_app = prefs.getBoolean("log_app", false);
    boolean filter = prefs.getBoolean("filter", false);

    Log.i(TAG, "Start native log=" + log + "/" + log_app + " filter=" + filter);

    // Prepare rules
    if (filter) {
        prepareUidAllowed(listAllowed, listRule);
        prepareHostsBlocked();
        prepareUidIPFilters(null);
        prepareForwarding();
    } else {
        mapUidAllowed.clear();
        mapUidKnown.clear();
        mapHostsBlocked.clear();
        mapUidIPFilters.clear();
        mapForward.clear();
    }

    if (log_app)
        prepareNotify(listRule);
    else
        mapNoNotify.clear();

    if (log || log_app || filter) {
        int prio = Integer.parseInt(prefs.getString("loglevel", Integer.toString(Log.WARN)));
        jni_start(vpn.getFd(), mapForward.containsKey(53), prio);
    }
}

From source file:eu.faircode.netguard.ServiceSinkhole.java

private void startNative(ParcelFileDescriptor vpn, List<Rule> listAllowed, List<Rule> listRule) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this);
    boolean log = prefs.getBoolean("log", false);
    boolean log_app = prefs.getBoolean("log_app", false);
    boolean filter = prefs.getBoolean("filter", false);

    Log.i(TAG, "Start native log=" + log + "/" + log_app + " filter=" + filter);

    // Prepare rules
    if (filter) {
        prepareUidAllowed(listAllowed, listRule);
        prepareHostsBlocked();//from w w  w  .  j a  v a2s. com
        prepareUidIPFilters(null);
        prepareForwarding();
    } else {
        lock.writeLock().lock();
        mapUidAllowed.clear();
        mapUidKnown.clear();
        mapHostsBlocked.clear();
        mapUidIPFilters.clear();
        mapForward.clear();
        lock.writeLock().unlock();
    }

    if (log_app)
        prepareNotify(listRule);
    else {
        lock.writeLock().lock();
        mapNoNotify.clear();
        lock.writeLock().unlock();
    }

    if (log || log_app || filter) {
        int prio = Integer.parseInt(prefs.getString("loglevel", Integer.toString(Log.WARN)));
        int rcode = Integer.parseInt(prefs.getString("rcode", "3"));
        if (prefs.getBoolean("socks5_enabled", false))
            jni_socks5(prefs.getString("socks5_addr", ""),
                    Integer.parseInt(prefs.getString("socks5_port", "0")),
                    prefs.getString("socks5_username", ""), prefs.getString("socks5_password", ""));
        else
            jni_socks5("", 0, "", "");
        jni_start(vpn.getFd(), mapForward.containsKey(53), rcode, prio);
    }
}