Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions core/src/main/java/com/github/shadowsocks/net/HttpsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ class HttpsTest : ViewModel() {
fun testConnection() {
cancelTest()
status.value = Status.Testing
val url = URL("https://cp.cloudflare.com")
val conn = url.openConnection(DataStore.proxy) as HttpURLConnection
val conn = try {
URL(DataStore.connectionTestUrl).openConnection(DataStore.proxy) as? HttpURLConnection
?: throw IOException("URL is not HTTP(S)")
} catch (e: IOException) {
status.value = Status.Error.IOFailure(e)
return
}
Comment on lines +83 to +89
conn.setRequestProperty("Connection", "close")
conn.instanceFollowRedirects = false
conn.useCaches = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import java.net.InetSocketAddress
import java.net.Proxy

object DataStore : OnPreferenceDataStoreChangeListener {
private const val DEFAULT_CONNECTION_TEST_URL = "https://cp.cloudflare.com"

val publicStore = RoomPreferenceDataStore(PublicDatabase.kvPairDao)
// privateStore will only be used as temp storage for ProfileConfigFragment
val privateStore = RoomPreferenceDataStore(PrivateDatabase.kvPairDao)
Expand Down Expand Up @@ -76,6 +78,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var portTransproxy: Int
get() = getLocalPort(Key.portTransproxy, 8200)
set(value) = publicStore.putString(Key.portTransproxy, value.toString())
val connectionTestUrl get() = publicStore.getString(Key.connectionTestUrl) ?: DEFAULT_CONNECTION_TEST_URL

/**
* Initialize settings that have complicated default values.
Expand All @@ -85,6 +88,9 @@ object DataStore : OnPreferenceDataStoreChangeListener {
if (publicStore.getString(Key.portProxy) == null) portProxy = portProxy
if (publicStore.getString(Key.portLocalDns) == null) portLocalDns = portLocalDns
if (publicStore.getString(Key.portTransproxy) == null) portTransproxy = portTransproxy
if (publicStore.getString(Key.connectionTestUrl) == null) {
publicStore.putString(Key.connectionTestUrl, connectionTestUrl)
}
}

var editingId: Long?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.github.shadowsocks.preference

import android.graphics.Typeface
import android.text.InputFilter
import android.text.InputType
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import androidx.preference.EditTextPreference
Expand All @@ -43,4 +44,12 @@ object EditTextPreferenceModifiers {
editText.setSelection(editText.text.length)
}
}

object Url : EditTextPreference.OnBindEditTextListener {
override fun onBindEditText(editText: EditText) {
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_URI
editText.setSingleLine()
editText.setSelection(editText.text.length)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ object Key {
const val portProxy = "portProxy"
const val portLocalDns = "portLocalDns"
const val portTransproxy = "portTransproxy"
const val connectionTestUrl = "connectionTestUrl"

const val route = "route"

Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<string name="port_proxy">SOCKS5 proxy port</string>
<string name="port_local_dns">Local DNS port</string>
<string name="port_transproxy">Transproxy port</string>
<string name="connection_test_url">Connection test URL</string>

<string name="remote_dns">Remote DNS</string>
<string name="traffic">%1$s↑\t%2$s↓</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
portLocalDns.setOnBindEditTextListener(EditTextPreferenceModifiers.Port)
val portTransproxy = findPreference<EditTextPreference>(Key.portTransproxy)!!
portTransproxy.setOnBindEditTextListener(EditTextPreferenceModifiers.Port)
val connectionTestUrl = findPreference<EditTextPreference>(Key.connectionTestUrl)!!
connectionTestUrl.setOnBindEditTextListener(EditTextPreferenceModifiers.Url)
val onServiceModeChange = Preference.OnPreferenceChangeListener { _, newValue ->
portTransproxy.isEnabled = newValue as String? == Key.modeTransproxy
true
Expand Down
4 changes: 4 additions & 0 deletions mobile/src/main/res/xml/pref_global.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
app:key="portTransproxy"
app:title="@string/port_transproxy"
app:useSimpleSummaryProvider="true"/>
<EditTextPreference
app:key="connectionTestUrl"
app:title="@string/connection_test_url"
app:useSimpleSummaryProvider="true"/>
</PreferenceScreen>
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
portLocalDns.setOnBindEditTextListener(EditTextPreferenceModifiers.Port)
portTransproxy = findPreference(Key.portTransproxy)!!
portTransproxy.setOnBindEditTextListener(EditTextPreferenceModifiers.Port)
findPreference<EditTextPreference>(Key.connectionTestUrl)!!
.setOnBindEditTextListener(EditTextPreferenceModifiers.Url)
serviceMode.onPreferenceChangeListener = onServiceModeChange
findPreference<Preference>(Key.about)!!.summary = getString(R.string.about_title, BuildConfig.VERSION_NAME)

Expand Down
4 changes: 4 additions & 0 deletions tv/src/main/res/xml/pref_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
app:key="portTransproxy"
app:title="@string/port_transproxy"
app:useSimpleSummaryProvider="true"/>
<EditTextPreference
app:key="connectionTestUrl"
app:title="@string/connection_test_url"
app:useSimpleSummaryProvider="true"/>
</PreferenceCategory>

<Preference
Expand Down