private void startVpn() { try { if (tunPFD != null) { throw new RuntimeException("another VPN is still running"); } tunPFD = new Builder() .setSession("fqrouter") .addAddress("10.25.1.1", 24) .addRoute("0.0.0.0", 0) .addDnsServer("8.8.8.8") .establish(); if (tunPFD == null) { stopSelf(); return; } final int tunFD = tunPFD.getFd(); LogUtils.i("tunFD is " + tunFD); new Thread( new Runnable() { @Override public void run() { try { listenFdServerSocket(tunPFD); } catch (Exception e) { LogUtils.e("fdsock failed " + e, e); } } }) .start(); updateStatus("Started in VPN mode"); sendBroadcast(new LaunchedIntent(true)); } catch (Exception e) { LogUtils.e("establish failed", e); } }
private void createPeerConnectionInternal(EglBase.Context renderEGLContext) { if (factory == null || isError) { Log.e(TAG, "Peerconnection factory is not created"); return; } Log.d(TAG, "Create peer connection."); Log.d(TAG, "PCConstraints: " + pcConstraints.toString()); queuedRemoteCandidates = new LinkedList<IceCandidate>(); if (videoCallEnabled) { Log.d(TAG, "EGLContext: " + renderEGLContext); factory.setVideoHwAccelerationOptions(renderEGLContext, renderEGLContext); } PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(signalingParameters.iceServers); // TCP candidates are only useful when connecting to a server that supports // ICE-TCP. rtcConfig.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED; rtcConfig.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE; rtcConfig.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE; rtcConfig.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY; // Use ECDSA encryption. rtcConfig.keyType = PeerConnection.KeyType.ECDSA; peerConnection = factory.createPeerConnection(rtcConfig, pcConstraints, pcObserver); isInitiator = false; // Set default WebRTC tracing and INFO libjingle logging. // NOTE: this _must_ happen while |factory| is alive! Logging.enableTracing("logcat:", EnumSet.of(Logging.TraceLevel.TRACE_DEFAULT)); Logging.enableLogToDebugOutput(Logging.Severity.LS_INFO); mediaStream = factory.createLocalMediaStream("ARDAMS"); if (videoCallEnabled) { if (peerConnectionParameters.useCamera2) { if (!peerConnectionParameters.captureToTexture) { reportError(context.getString(R.string.camera2_texture_only_error)); return; } Logging.d(TAG, "Creating capturer using camera2 API."); createCapturer(new Camera2Enumerator(context)); } else { Logging.d(TAG, "Creating capturer using camera1 API."); createCapturer(new Camera1Enumerator(peerConnectionParameters.captureToTexture)); } if (videoCapturer == null) { reportError("Failed to open camera"); return; } mediaStream.addTrack(createVideoTrack(videoCapturer)); } mediaStream.addTrack(createAudioTrack()); peerConnection.addStream(mediaStream); if (peerConnectionParameters.aecDump) { try { aecDumpFileDescriptor = ParcelFileDescriptor.open( new File( Environment.getExternalStorageDirectory().getPath() + File.separator + "Download/audio.aecdump"), ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_CREATE | ParcelFileDescriptor.MODE_TRUNCATE); factory.startAecDump(aecDumpFileDescriptor.getFd(), -1); } catch (IOException e) { Log.e(TAG, "Can not open aecdump file", e); } } Log.d(TAG, "Peer connection created."); }