aboutsummaryrefslogtreecommitdiff
path: root/app/src/nonFree/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2020-09-05 04:42:09 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2020-09-05 22:49:01 +0530
commitc3e600689547ef850cb9dcaa3b01f97de543b9d5 (patch)
tree851e8f675da3ac3b0210a2dc4eb048a378a19580 /app/src/nonFree/java
parent90c9ce1b91f025b499888665dc4f7ef10e656881 (diff)
AutofillSmsActivity: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'app/src/nonFree/java')
-rw-r--r--app/src/nonFree/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSmsActivity.kt18
1 files changed, 10 insertions, 8 deletions
diff --git a/app/src/nonFree/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSmsActivity.kt b/app/src/nonFree/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSmsActivity.kt
index 4413ea10..25a5ef93 100644
--- a/app/src/nonFree/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSmsActivity.kt
+++ b/app/src/nonFree/java/com/zeapo/pwdstore/autofill/oreo/ui/AutofillSmsActivity.kt
@@ -19,6 +19,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import com.github.ajalt.timberkt.e
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.SmsRetriever
import com.google.android.gms.common.ConnectionResult
@@ -124,18 +126,18 @@ class AutofillSmsActivity : AppCompatActivity() {
private suspend fun waitForSms() {
val smsClient = SmsCodeRetriever.getAutofillClient(this@AutofillSmsActivity)
- try {
+ runCatching {
withContext(Dispatchers.IO) {
smsClient.startSmsCodeRetriever().suspendableAwait()
}
- } catch (e: ResolvableApiException) {
- withContext(Dispatchers.Main) {
+ }.onFailure { e ->
+ if (e is ResolvableApiException) {
e.startResolutionForResult(this@AutofillSmsActivity, 1)
- }
- } catch (e: Exception) {
- e(e)
- withContext(Dispatchers.Main) {
- finish()
+ } else {
+ e(e)
+ withContext(Dispatchers.Main) {
+ finish()
+ }
}
}
}