Safe access to url or IP 0
This commit is contained in:
parent
44dd904e4c
commit
ae555033d2
|
@ -6,8 +6,8 @@ import android.content.Intent
|
|||
|
||||
interface AccountFactory {
|
||||
val apiFactory: Class<*>
|
||||
val name: String
|
||||
val url: String
|
||||
val name: String?
|
||||
val url: String?
|
||||
fun initAccount(context: Context)
|
||||
fun isConnected(context: Context): Boolean
|
||||
fun connect(activity: Activity)
|
||||
|
|
|
@ -22,10 +22,10 @@ import org.unifiedpush.distributor.nextpush.utils.TAG
|
|||
|
||||
class SSOAccountFactory : AccountFactory {
|
||||
override val apiFactory: Class<*> = ApiSSOFactory::class.java
|
||||
override val name: String
|
||||
get() = ssoAccount!!.name
|
||||
override val url: String
|
||||
get() = ssoAccount!!.url
|
||||
override val name: String?
|
||||
get() = ssoAccount?.name
|
||||
override val url: String?
|
||||
get() = ssoAccount?.url
|
||||
|
||||
private var ssoAccount: SingleSignOnAccount? = null
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ object Api {
|
|||
private var provider: ApiProviderFactory? = null
|
||||
private var source: EventSource? = null
|
||||
|
||||
private val Context.baseUrl: String
|
||||
get() = getAccount(this)?.url ?: "http://0.0.0.0/"
|
||||
|
||||
private fun Context.withApiProvider(block: (ApiProvider) -> Unit) {
|
||||
(
|
||||
provider ?: run {
|
||||
|
@ -79,7 +82,7 @@ object Api {
|
|||
}
|
||||
|
||||
override fun onComplete() {
|
||||
saveUrl(this@apiSync, "${getAccount(this@apiSync)?.url}$mApiEndpoint")
|
||||
saveUrl(this@apiSync, "$baseUrl$mApiEndpoint")
|
||||
|
||||
// Sync once it is registered
|
||||
deviceId?.let {
|
||||
|
@ -97,7 +100,7 @@ object Api {
|
|||
.readTimeout(0, TimeUnit.SECONDS)
|
||||
.retryOnConnectionFailure(false)
|
||||
.build()
|
||||
val url = "${getAccount(this)?.url}$mApiEndpoint/device/$deviceId"
|
||||
val url = "$baseUrl$mApiEndpoint/device/$deviceId"
|
||||
|
||||
val request = Request.Builder().url(url)
|
||||
.get()
|
||||
|
|
Loading…
Reference in New Issue