Fix network call on main thread

pull/2473/head
Alex Baker 2 years ago
parent 7283491872
commit 5cb8419206

@ -116,17 +116,16 @@ class MicrosoftAuthenticationActivity : ComponentActivity() {
} }
} }
private suspend fun getEmail(accessToken: String?): String? { private suspend fun getEmail(accessToken: String?): String? = withContext(Dispatchers.IO) {
if (accessToken == null) { if (accessToken == null) {
return null return@withContext null
} }
val discovery = AuthorizationServiceDiscovery( val discovery = AuthorizationServiceDiscovery(
JSONObject( JSONObject(
intent.getStringExtra(EXTRA_SERVICE_DISCOVERY)!! intent.getStringExtra(EXTRA_SERVICE_DISCOVERY)!!
) )
) )
val userInfo = withContext(Dispatchers.IO) { val userInfo = httpClientFactory
httpClientFactory
.newClient(foreground = false) .newClient(foreground = false)
.newCall( .newCall(
Request.Builder() Request.Builder()
@ -135,9 +134,8 @@ class MicrosoftAuthenticationActivity : ComponentActivity() {
.build() .build()
) )
.execute() .execute()
} val response = userInfo.body?.string() ?: return@withContext null
val response = userInfo.body?.string() ?: return null JSONObject(response).getString("email")
return JSONObject(response).getString("email")
} }
private fun error(message: String) { private fun error(message: String) {

Loading…
Cancel
Save