Integration with old SDK - make it works

This commit is contained in:
ganfra 2018-10-11 09:05:32 +02:00
parent 108fae2f28
commit f9e6f4b533
11 changed files with 52 additions and 13 deletions

View File

@ -32,6 +32,7 @@ class LoginActivity : RiotActivity() {
val homeServerConnectionConfig = HomeServerConnectionConfig.Builder()
.withHomeServerUri("https://matrix.org/")
.withIdentityServerUri("https://vector.im")
.withAntiVirusServerUri("https://matrix.org/")
.build()
authenticator.authenticate(homeServerConnectionConfig, login, password, object : MatrixCallback<Session> {

View File

@ -43,7 +43,7 @@ data class HomeServerConnectionConfig(
*/
fun withHomeServerUri(hsUri: Uri): Builder {
if (hsUri.scheme != "http" && hsUri.scheme != "https") {
throw RuntimeException("Invalid home server URI: " + hsUri!!)
throw RuntimeException("Invalid home server URI: " + hsUri)
}
// remove trailing /
homeServerUri = if (hsUri.toString().endsWith("/")) {
@ -148,6 +148,10 @@ data class HomeServerConnectionConfig(
return this
}
fun withAntiVirusServerUri(antivirusServerUriString: String?): Builder {
return withAntiVirusServerUri(antivirusServerUriString?.let { Uri.parse(it) })
}
/**
* Update the anti-virus server URI.
*
@ -211,7 +215,18 @@ data class HomeServerConnectionConfig(
* @return the [HomeServerConnectionConfig]
*/
fun build(): HomeServerConnectionConfig {
return HomeServerConnectionConfig(homeServerUri, identityServerUri, antiVirusServerUri, allowedFingerprints, shouldPin, tlsVersions, tlsCipherSuites, shouldAcceptTlsExtensions, allowHttpExtension, forceUsageTlsVersions)
return HomeServerConnectionConfig(
homeServerUri,
identityServerUri,
antiVirusServerUri,
allowedFingerprints,
shouldPin,
tlsVersions,
tlsCipherSuites,
shouldAcceptTlsExtensions,
allowHttpExtension,
forceUsageTlsVersions
)
}
}

View File

@ -1,7 +1,9 @@
package im.vector.matrix.android.internal.di
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import com.squareup.moshi.Moshi
import im.vector.matrix.android.internal.network.AccessTokenInterceptor
import im.vector.matrix.android.internal.network.parsing.UriMoshiAdapter
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.dsl.context.ModuleDefinition
@ -38,7 +40,7 @@ class NetworkModule : Module {
}
single {
MoshiProvider.providesMoshi()
Moshi.Builder().add(UriMoshiAdapter()).build()
}
single {

View File

@ -13,10 +13,11 @@ import retrofit2.Retrofit
class SessionModule(private val sessionParams: SessionParams) : Module {
override fun invoke(): ModuleDefinition = module(override = true) {
scope(DefaultSession.SCOPE) {
val retrofitBuilder = get() as Retrofit.Builder
retrofitBuilder
.baseUrl(sessionParams.homeServerConnectionConfig?.homeServerUri.toString())
.baseUrl(sessionParams.homeServerConnectionConfig.homeServerUri.toString())
.build()
}
@ -24,6 +25,8 @@ class SessionModule(private val sessionParams: SessionParams) : Module {
val store = MXFileStore(sessionParams.credentials, false, get())
val dataHandler = MXDataHandler(store, sessionParams.credentials)
MXSession.Builder(sessionParams, dataHandler, get()).build()
store.setDataHandler(dataHandler)
dataHandler
}
}.invoke()

View File

@ -16,7 +16,7 @@ class SyncModule : Module {
}
scope(DefaultSession.SCOPE) {
SyncResponseHandler(get(), get())
SyncResponseHandler(get())
}
scope(DefaultSession.SCOPE) {

View File

@ -22,9 +22,9 @@ import kotlin.collections.emptyList
import kotlin.collections.isNotEmpty
import kotlin.collections.set
class SyncResponseHandler(private val dataHandler: MXDataHandler,
private val store: IMXStore) {
class SyncResponseHandler(private val dataHandler: MXDataHandler) {
private val store = dataHandler.store
private val leftRoomsStore = MXMemoryStore()
private var isStartingCryptoWithInitialSync = false
private var areLeftRoomsSynced = false

View File

@ -74,9 +74,9 @@ public class ContentManager {
public void configureAntiVirusScanner(boolean isEnabled) {
mIsAvScannerEnabled = isEnabled;
if (isEnabled) {
mDownloadUrlPrefix = mHsConfig.getAntiVirusServerUri().toString() + "/" + RestClient.URI_API_PREFIX_PATH_MEDIA_PROXY_UNSTABLE;
mDownloadUrlPrefix = mHsConfig.getAntiVirusServerUri() + "/" + RestClient.URI_API_PREFIX_PATH_MEDIA_PROXY_UNSTABLE;
} else {
mDownloadUrlPrefix = mHsConfig.getHomeServerUri().toString() + URI_PREFIX_CONTENT_API;
mDownloadUrlPrefix = mHsConfig.getHomeServerUri() + URI_PREFIX_CONTENT_API;
}
}

View File

@ -28,7 +28,6 @@ import com.google.gson.JsonObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

View File

@ -0,0 +1,19 @@
package im.vector.matrix.android.internal.network.parsing
import android.net.Uri
import com.squareup.moshi.FromJson
import com.squareup.moshi.ToJson
class UriMoshiAdapter {
@ToJson
fun toJson(uri: Uri): String {
return uri.toString()
}
@FromJson
fun fromJson(uriString: String): Uri {
return Uri.parse(uriString)
}
}

View File

@ -141,7 +141,7 @@ object CertUtil {
try {
tf = TrustManagerFactory.getInstance("PKIX")
} catch (e: Exception) {
Timber.e("## newPinnedSSLSocketFactory() : TrustManagerFactory.getInstance failed " + e.message, e)
Timber.e(e, "## newPinnedSSLSocketFactory() : TrustManagerFactory.getInstance failed " + e.message)
}
// it doesn't exist, use the default one.
@ -149,7 +149,7 @@ object CertUtil {
try {
tf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
} catch (e: Exception) {
Timber.e("## addRule : onBingRuleUpdateFailure failed " + e.message, e)
Timber.e(e, "## addRule : onBingRuleUpdateFailure failed " + e.message)
}
}
@ -197,7 +197,7 @@ object CertUtil {
return HostnameVerifier { hostname, session ->
if (defaultVerifier.verify(hostname, session)) return@HostnameVerifier true
if (trustedFingerprints == null || trustedFingerprints.size == 0) return@HostnameVerifier false
if (trustedFingerprints.isEmpty()) return@HostnameVerifier false
// If remote cert matches an allowed fingerprint, just accept it.
try {