Commit 79f40b88 authored by Mygod's avatar Mygod

Implement connection test for proxy modes

parent 13ef297a
...@@ -127,7 +127,6 @@ ...@@ -127,7 +127,6 @@
<string name="received">Received:</string> <string name="received">Received:</string>
<string name="connecting">Connecting…</string> <string name="connecting">Connecting…</string>
<string name="vpn_connected">Connected, tap to check connection</string> <string name="vpn_connected">Connected, tap to check connection</string>
<string name="nat_connected">Connected</string>
<string name="not_connected">Not connected</string> <string name="not_connected">Not connected</string>
<!-- acl --> <!-- acl -->
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
package com.github.shadowsocks package com.github.shadowsocks
import java.lang.System.currentTimeMillis import java.lang.System.currentTimeMillis
import java.net.{HttpURLConnection, URL} import java.net.{HttpURLConnection, InetSocketAddress, URL, Proxy => JavaProxy}
import java.util.Locale import java.util.Locale
import android.app.Activity import android.app.Activity
...@@ -119,7 +119,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -119,7 +119,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
if (state == ServiceState.CONNECTING) fabProgressCircle.beginFinalAnimation() if (state == ServiceState.CONNECTING) fabProgressCircle.beginFinalAnimation()
else fabProgressCircle.postDelayed(hideCircle, 1000) else fabProgressCircle.postDelayed(hideCircle, 1000)
fab.setImageResource(R.drawable.ic_start_connected) fab.setImageResource(R.drawable.ic_start_connected)
statusText.setText(if (app.usingVpnMode) R.string.vpn_connected else R.string.nat_connected) statusText.setText(R.string.vpn_connected)
case ServiceState.STOPPING => case ServiceState.STOPPING =>
fab.setImageResource(R.drawable.ic_start_busy) fab.setImageResource(R.drawable.ic_start_busy)
if (state == ServiceState.CONNECTED) fabProgressCircle.show() // ignore for stopped if (state == ServiceState.CONNECTED) fabProgressCircle.show() // ignore for stopped
...@@ -242,17 +242,21 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -242,17 +242,21 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
txRateText = findViewById(R.id.txRate).asInstanceOf[TextView] txRateText = findViewById(R.id.txRate).asInstanceOf[TextView]
rxText = findViewById(R.id.rx).asInstanceOf[TextView] rxText = findViewById(R.id.rx).asInstanceOf[TextView]
rxRateText = findViewById(R.id.rxRate).asInstanceOf[TextView] rxRateText = findViewById(R.id.rxRate).asInstanceOf[TextView]
findViewById[View](R.id.stat).setOnClickListener(_ => if (state == ServiceState.CONNECTED && app.usingVpnMode) { findViewById[View](R.id.stat).setOnClickListener(_ => if (state == ServiceState.CONNECTED) {
testCount += 1 testCount += 1
statusText.setText(R.string.connection_test_testing) statusText.setText(R.string.connection_test_testing)
val id = testCount // it would change by other code val id = testCount // it would change by other code
Utils.ThrowableFuture { Utils.ThrowableFuture {
// Based on: https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/connectivity/NetworkMonitor.java#640 // Based on: https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/connectivity/NetworkMonitor.java#640
autoDisconnect(new URL("https", app.currentProfile.get.route match { autoDisconnect {
case Acl.CHINALIST => "www.qualcomm.cn" val url = new URL("https", app.currentProfile.get.route match {
case _ => "www.google.com" case Acl.CHINALIST => "www.qualcomm.cn"
}, "/generate_204").openConnection() case _ => "www.google.com"
.asInstanceOf[HttpURLConnection]) { conn => }, "/generate_204")
(if (app.usingVpnMode) url.openConnection() else url.openConnection(
new JavaProxy(JavaProxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", app.dataStore.portProxy))))
.asInstanceOf[HttpURLConnection]
} { conn =>
conn.setConnectTimeout(5 * 1000) conn.setConnectTimeout(5 * 1000)
conn.setReadTimeout(5 * 1000) conn.setReadTimeout(5 * 1000)
conn.setInstanceFollowRedirects(false) conn.setInstanceFollowRedirects(false)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment