Commit c1c15f53 authored by Mygod's avatar Mygod

Refine connection test feature

parent e33adc4f
...@@ -127,6 +127,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -127,6 +127,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
if (state == State.CONNECTED) fab.setBackgroundTintList(greenTint) else { if (state == State.CONNECTED) fab.setBackgroundTintList(greenTint) else {
fab.setBackgroundTintList(greyTint) fab.setBackgroundTintList(greyTint)
updateTraffic(0, 0, 0, 0) updateTraffic(0, 0, 0, 0)
testCount += 1 // suppress previous test messages
} }
fab.setEnabled(false) fab.setEnabled(false)
if (state == State.CONNECTED || state == State.STOPPED) if (state == State.CONNECTED || state == State.STOPPED)
...@@ -211,12 +212,10 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -211,12 +212,10 @@ 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(R.id.stat).setOnClickListener(_ => { findViewById(R.id.stat).setOnClickListener(_ => if (state == State.CONNECTED && app.isVpnEnabled) {
val id = synchronized {
testCount += 1 testCount += 1
handler.post(() => statusText.setText(R.string.connection_test_testing)) statusText.setText(R.string.connection_test_testing)
testCount 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", "www.google.com", "/generate_204").openConnection() autoDisconnect(new URL("https", "www.google.com", "/generate_204").openConnection()
...@@ -241,11 +240,10 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -241,11 +240,10 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
success = false success = false
result = getString(R.string.connection_test_error, e.getMessage) result = getString(R.string.connection_test_error, e.getMessage)
} }
synchronized(if (state == State.CONNECTED && testCount == id && app.isVpnEnabled) handler.post(() => if (testCount == id) handler.post(() => if (success) statusText.setText(result) else {
if (success) statusText.setText(result) else {
statusText.setText(R.string.connection_test_fail) statusText.setText(R.string.connection_test_fail)
Snackbar.make(findViewById(R.id.snackbar), result, Snackbar.LENGTH_LONG).show() Snackbar.make(findViewById(R.id.snackbar), result, Snackbar.LENGTH_LONG).show()
})) })
} }
} }
} }
......
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