mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-31 14:25:28 +00:00
AutofillSmsActivity: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
@@ -19,6 +19,8 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.ajalt.timberkt.e
|
import com.github.ajalt.timberkt.e
|
||||||
import com.github.ajalt.timberkt.w
|
import com.github.ajalt.timberkt.w
|
||||||
|
import com.github.michaelbull.result.onFailure
|
||||||
|
import com.github.michaelbull.result.runCatching
|
||||||
import com.google.android.gms.auth.api.phone.SmsCodeRetriever
|
import com.google.android.gms.auth.api.phone.SmsCodeRetriever
|
||||||
import com.google.android.gms.auth.api.phone.SmsRetriever
|
import com.google.android.gms.auth.api.phone.SmsRetriever
|
||||||
import com.google.android.gms.common.ConnectionResult
|
import com.google.android.gms.common.ConnectionResult
|
||||||
@@ -124,21 +126,21 @@ class AutofillSmsActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private suspend fun waitForSms() {
|
private suspend fun waitForSms() {
|
||||||
val smsClient = SmsCodeRetriever.getAutofillClient(this@AutofillSmsActivity)
|
val smsClient = SmsCodeRetriever.getAutofillClient(this@AutofillSmsActivity)
|
||||||
try {
|
runCatching {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
smsClient.startSmsCodeRetriever().suspendableAwait()
|
smsClient.startSmsCodeRetriever().suspendableAwait()
|
||||||
}
|
}
|
||||||
} catch (e: ResolvableApiException) {
|
}.onFailure { e ->
|
||||||
withContext(Dispatchers.Main) {
|
if (e is ResolvableApiException) {
|
||||||
e.startResolutionForResult(this@AutofillSmsActivity, 1)
|
e.startResolutionForResult(this@AutofillSmsActivity, 1)
|
||||||
}
|
} else {
|
||||||
} catch (e: Exception) {
|
|
||||||
e(e)
|
e(e)
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val smsCodeRetrievedReceiver = object : BroadcastReceiver() {
|
private val smsCodeRetrievedReceiver = object : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
Reference in New Issue
Block a user