Skip to content
Snippets Groups Projects
Unverified Commit 355dc5ec authored by Jakob Möller's avatar Jakob Möller Committed by GitHub
Browse files

Fix/no urls (#242)

parent 4b4fb981
No related branches found
No related tags found
No related merge requests found
package de.rki.coronawarnapp.exception.http
class ServiceFactoryException(cause: Throwable) :
Exception("error inside the service factory", cause)
package de.rki.coronawarnapp.http
import android.webkit.URLUtil
import de.rki.coronawarnapp.BuildConfig
import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.exception.http.ServiceFactoryException
import de.rki.coronawarnapp.http.service.DistributionService
import de.rki.coronawarnapp.http.service.SubmissionService
import de.rki.coronawarnapp.http.service.VerificationService
......@@ -90,34 +92,50 @@ class ServiceFactory {
clientBuilder.build()
}
private val downloadCdnUrl
get() = getValidUrl(DynamicURLs.DOWNLOAD_CDN_URL)
fun distributionService(): DistributionService = distributionService
private val distributionService by lazy {
Retrofit.Builder()
.client(okHttpClient)
.baseUrl(DynamicURLs.DOWNLOAD_CDN_URL)
.baseUrl(downloadCdnUrl)
.addConverterFactory(gsonConverterFactory)
.build()
.create(DistributionService::class.java)
}
private val verificationCdnUrl
get() = getValidUrl(DynamicURLs.VERIFICATION_CDN_URL)
fun verificationService(): VerificationService = verificationService
private val verificationService by lazy {
Retrofit.Builder()
.client(okHttpClient)
.baseUrl(DynamicURLs.VERIFICATION_CDN_URL)
.baseUrl(verificationCdnUrl)
.addConverterFactory(gsonConverterFactory)
.build()
.create(VerificationService::class.java)
}
private val submissionCdnUrl
get() = getValidUrl(DynamicURLs.SUBMISSION_CDN_URL)
fun submissionService(): SubmissionService = submissionService
private val submissionService by lazy {
Retrofit.Builder()
.client(okHttpClient)
.baseUrl(DynamicURLs.SUBMISSION_CDN_URL)
.baseUrl(submissionCdnUrl)
.addConverterFactory(protoConverterFactory)
.addConverterFactory(gsonConverterFactory)
.build()
.create(SubmissionService::class.java)
}
private fun getValidUrl(url: String): String {
if (!URLUtil.isHttpsUrl(url)) {
throw ServiceFactoryException(IllegalArgumentException("the url is invalid"))
}
return url
}
}
......@@ -48,9 +48,9 @@ object WebRequestBuilder {
private val serviceFactory = ServiceFactory()
private val distributionService = serviceFactory.distributionService()
private val verificationService = serviceFactory.verificationService()
private val submissionService = serviceFactory.submissionService()
private val distributionService by lazy { serviceFactory.distributionService() }
private val verificationService by lazy { serviceFactory.verificationService() }
private val submissionService by lazy { serviceFactory.submissionService() }
suspend fun asyncGetDateIndex(): List<String> = withContext(Dispatchers.IO) {
return@withContext distributionService
......
......@@ -31,12 +31,13 @@ class UpdateChecker(private val activity: LauncherActivity) {
suspend fun checkForUpdate() {
// check if an update is needed based on server config
// TODO replace with signature exception
val updateNeededFromServer: Boolean = try {
checkIfUpdatesNeededFromServer()
}
// TODO replace with signature exception
catch (exception: Exception) {
true
} catch (exception: Exception) {
Log.e(TAG, exception.localizedMessage ?: "unknown error")
exception.printStackTrace()
false
}
// get AppUpdateManager
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment