mirror of https://git.sr.ht/~oppen/ariane
add default tls option
This commit is contained in:
parent
3e0c9e9728
commit
5c97768bec
|
@ -24,8 +24,12 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
tlsCategory.title = "TLS Config"
|
tlsCategory.title = "TLS Config"
|
||||||
screen.addPreference(tlsCategory)
|
screen.addPreference(tlsCategory)
|
||||||
|
|
||||||
//todo - need to add the default "TLS" option here,
|
val tlsDefaultPreference = SwitchPreferenceCompat(context)
|
||||||
// otherwise once set in this screen user can't get that default back
|
tlsDefaultPreference.key = "tls_Default"
|
||||||
|
tlsDefaultPreference.title = "TLS Default"
|
||||||
|
tlsDefaultPreference.onPreferenceChangeListener = this
|
||||||
|
tlsCategory.addPreference(tlsDefaultPreference)
|
||||||
|
|
||||||
val sslContext = SSLContext.getInstance("TLS")
|
val sslContext = SSLContext.getInstance("TLS")
|
||||||
sslContext.init(null, null, SecureRandom())
|
sslContext.init(null, null, SecureRandom())
|
||||||
val factory: SSLSocketFactory = sslContext.socketFactory
|
val factory: SSLSocketFactory = sslContext.socketFactory
|
||||||
|
@ -45,19 +49,30 @@ class SettingsFragment: PreferenceFragmentCompat(), Preference.OnPreferenceChang
|
||||||
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
|
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
|
||||||
if(preference is SwitchPreferenceCompat && newValue is Boolean && newValue == true) {
|
if(preference is SwitchPreferenceCompat && newValue is Boolean && newValue == true) {
|
||||||
preference.key?.let { key ->
|
preference.key?.let { key ->
|
||||||
if (key.startsWith("tls_")) {
|
when {
|
||||||
protocols.forEach { protocol ->
|
key.startsWith("tls_") -> {
|
||||||
val tlsSwitchKey = "tls_${protocol.toLowerCase(Locale.getDefault())}"
|
if(key != "tls_Default"){
|
||||||
if (tlsSwitchKey != key) {
|
val default = preferenceScreen.findPreference<SwitchPreferenceCompat>("tls_Default")
|
||||||
val otherTLSSwitch =
|
default?.isChecked = false
|
||||||
preferenceScreen.findPreference<SwitchPreferenceCompat>(tlsSwitchKey)
|
}
|
||||||
otherTLSSwitch?.isChecked = false
|
protocols.forEach { protocol ->
|
||||||
|
val tlsSwitchKey = "tls_${protocol.toLowerCase(Locale.getDefault())}"
|
||||||
|
if (tlsSwitchKey != key) {
|
||||||
|
val otherTLSSwitch = preferenceScreen.findPreference<SwitchPreferenceCompat>(tlsSwitchKey)
|
||||||
|
otherTLSSwitch?.isChecked = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setTLSProtocol(preference.title.toString())
|
val prefTitle = preference.title.toString()
|
||||||
|
|
||||||
|
if(prefTitle.toLowerCase().contains("default")){
|
||||||
|
setTLSProtocol("TLS")
|
||||||
|
}else{
|
||||||
|
setTLSProtocol(prefTitle)
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue