mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-27 12:15:50 +01:00
Add system HTTP proxy support to libsignal-net.
Co-authored-by: Cody Henthorne <cody@signal.org>
This commit is contained in:
committed by
Cody Henthorne
parent
8e880fe117
commit
74c6e76808
@@ -0,0 +1,6 @@
|
||||
package org.whispersystems.signalservice.internal.configuration
|
||||
|
||||
/**
|
||||
* HTTP Proxy configuration from Android OS configuration.
|
||||
*/
|
||||
class HttpProxy(val host: String, val port: Int)
|
||||
@@ -17,6 +17,7 @@ data class SignalServiceConfiguration(
|
||||
val networkInterceptors: List<Interceptor>,
|
||||
val dns: Optional<Dns>,
|
||||
val signalProxy: Optional<SignalProxy>,
|
||||
val systemHttpProxy: Optional<HttpProxy>,
|
||||
val zkGroupServerPublicParams: ByteArray,
|
||||
val genericServerPublicParams: ByteArray,
|
||||
val backupServerPublicParams: ByteArray,
|
||||
|
||||
@@ -30,16 +30,27 @@ fun Network.transformAndSetRemoteConfig(remoteConfig: Map<String, Any>) {
|
||||
* Helper method to apply settings from the SignalServiceConfiguration.
|
||||
*/
|
||||
fun Network.applyConfiguration(config: SignalServiceConfiguration) {
|
||||
val proxy = config.signalProxy.orNull()
|
||||
val signalProxy = config.signalProxy.orNull()
|
||||
val systemHttpProxy = config.systemHttpProxy.orNull()
|
||||
|
||||
if (proxy == null) {
|
||||
this.clearProxy()
|
||||
} else {
|
||||
try {
|
||||
this.setProxy(proxy.host, proxy.port)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Invalid proxy configuration set! Failing connections until changed.")
|
||||
this.setInvalidProxy()
|
||||
when {
|
||||
(signalProxy != null) -> {
|
||||
try {
|
||||
this.setProxy(signalProxy.host, signalProxy.port)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Invalid proxy configuration set! Failing connections until changed.")
|
||||
this.setInvalidProxy()
|
||||
}
|
||||
}
|
||||
(systemHttpProxy != null) -> {
|
||||
try {
|
||||
this.setProxy("http", systemHttpProxy.host, systemHttpProxy.port, "", "")
|
||||
} catch (e: IOException) {
|
||||
// The Android settings screen where this is set explicitly calls out that apps are allowed to
|
||||
// ignore the HTTP Proxy setting, so if using the specified proxy would cause us to break, let's
|
||||
// try just ignoring it and seeing if that still lets us connect.
|
||||
Log.w(TAG, "Failed to set system HTTP proxy, ignoring and continuing...")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user