Fix bug where we constantly cycled network stack when on network with PAC proxy.

This commit is contained in:
andrew-signal
2026-02-23 16:53:22 -05:00
committed by Cody Henthorne
parent 08509f6693
commit e636a94de0
3 changed files with 19 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.push
import android.content.Context
import android.net.ConnectivityManager
import android.net.ProxyInfo
import android.net.Uri
import androidx.core.content.ContextCompat
import com.google.i18n.phonenumbers.PhoneNumberUtil
@@ -143,9 +144,15 @@ class SignalServiceNetworkAccess(context: Context) {
private fun getSystemHttpProxy(context: Context): HttpProxy? {
val connectivityManager = ContextCompat.getSystemService(context, ConnectivityManager::class.java) ?: return null
return connectivityManager
val proxyInfo = connectivityManager
.activeNetwork
?.let { connectivityManager.getLinkProperties(it)?.httpProxy }
return proxyInfo.toApplicableSystemHttpProxy()
}
fun ProxyInfo?.toApplicableSystemHttpProxy(): HttpProxy? {
return this
?.takeIf { !it.exclusionList.contains(BuildConfig.SIGNAL_URL.stripProtocol()) }
// NB: Edit carefully, dear reader, as the line below is written from hard won experience.
// It turns out, that despite being documented *nowhere*, if a PAC file is set
@@ -156,7 +163,7 @@ class SignalServiceNetworkAccess(context: Context) {
// So, if we do not explicitly check that a PAC file is not set, the proxy
// we pass to libsignal may be syntactically invalid, and the user may be
// rendered unable to connect.
?.takeIf { proxyInfo -> proxyInfo.pacFileUrl.equals(Uri.EMPTY) }
?.takeIf { it.pacFileUrl == Uri.EMPTY }
?.let { proxy -> HttpProxy(proxy.host, proxy.port) }
}
}