Merge pull request #8683 from vector-im/giomfo/fix_custom_gateway_check

Unified Push: Ignore the potential SSL error when the custom gateway is testing
This commit is contained in:
giomfo 2023-11-15 22:26:06 +01:00 committed by GitHub
commit fd5530a2f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

1
changelog.d/8683.bugfix Normal file
View File

@ -0,0 +1 @@
Unified Push: Ignore the potential SSL error when the custom gateway is testing locally

View File

@ -26,11 +26,13 @@ import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.getApplicationLabel import im.vector.app.core.utils.getApplicationLabel
import org.matrix.android.sdk.api.Matrix import org.matrix.android.sdk.api.Matrix
import org.matrix.android.sdk.api.cache.CacheStrategy import org.matrix.android.sdk.api.cache.CacheStrategy
import org.matrix.android.sdk.api.failure.Failure
import org.matrix.android.sdk.api.util.MatrixJsonParser import org.matrix.android.sdk.api.util.MatrixJsonParser
import org.unifiedpush.android.connector.UnifiedPush import org.unifiedpush.android.connector.UnifiedPush
import timber.log.Timber import timber.log.Timber
import java.net.URL import java.net.URL
import javax.inject.Inject import javax.inject.Inject
import javax.net.ssl.SSLHandshakeException
class UnifiedPushHelper @Inject constructor( class UnifiedPushHelper @Inject constructor(
private val context: Context, private val context: Context,
@ -104,7 +106,11 @@ class UnifiedPushHelper @Inject constructor(
// else, unifiedpush, and pushkey is an endpoint // else, unifiedpush, and pushkey is an endpoint
val gateway = stringProvider.getString(R.string.default_push_gateway_http_url) val gateway = stringProvider.getString(R.string.default_push_gateway_http_url)
val parsed = URL(endpoint) val parsed = URL(endpoint)
val port = if (parsed.port != -1) { ":${parsed.port}" } else { "" } val port = if (parsed.port != -1) {
":${parsed.port}"
} else {
""
}
val custom = "${parsed.protocol}://${parsed.host}${port}/_matrix/push/v1/notify" val custom = "${parsed.protocol}://${parsed.host}${port}/_matrix/push/v1/notify"
Timber.i("Testing $custom") Timber.i("Testing $custom")
try { try {
@ -120,7 +126,13 @@ class UnifiedPushHelper @Inject constructor(
} }
} }
} catch (e: Throwable) { } catch (e: Throwable) {
Timber.d(e, "Cannot try custom gateway") Timber.e(e, "Cannot try custom gateway")
if (e is Failure.NetworkConnection && e.ioException is SSLHandshakeException) {
Timber.w(e, "SSLHandshakeException, ignore this error")
unifiedPushStore.storePushGateway(custom)
onDoneRunnable?.run()
return
}
} }
unifiedPushStore.storePushGateway(gateway) unifiedPushStore.storePushGateway(gateway)
onDoneRunnable?.run() onDoneRunnable?.run()