mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-30 22:05:19 +00:00
AutofillScenario: use runCatching to replace exception handling
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
@@ -12,6 +12,8 @@ import android.view.autofill.AutofillId
|
|||||||
import android.view.autofill.AutofillValue
|
import android.view.autofill.AutofillValue
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import com.github.ajalt.timberkt.e
|
import com.github.ajalt.timberkt.e
|
||||||
|
import com.github.michaelbull.result.getOrElse
|
||||||
|
import com.github.michaelbull.result.runCatching
|
||||||
|
|
||||||
enum class AutofillAction {
|
enum class AutofillAction {
|
||||||
Match, Search, Generate, FillOtpFromSms
|
Match, Search, Generate, FillOtpFromSms
|
||||||
@@ -36,7 +38,7 @@ sealed class AutofillScenario<out T : Any> {
|
|||||||
const val BUNDLE_KEY_GENERIC_PASSWORD_IDS = "genericPasswordIds"
|
const val BUNDLE_KEY_GENERIC_PASSWORD_IDS = "genericPasswordIds"
|
||||||
|
|
||||||
fun fromBundle(clientState: Bundle): AutofillScenario<AutofillId>? {
|
fun fromBundle(clientState: Bundle): AutofillScenario<AutofillId>? {
|
||||||
return try {
|
return runCatching {
|
||||||
Builder<AutofillId>().apply {
|
Builder<AutofillId>().apply {
|
||||||
username = clientState.getParcelable(BUNDLE_KEY_USERNAME_ID)
|
username = clientState.getParcelable(BUNDLE_KEY_USERNAME_ID)
|
||||||
fillUsername = clientState.getBoolean(BUNDLE_KEY_FILL_USERNAME)
|
fillUsername = clientState.getBoolean(BUNDLE_KEY_FILL_USERNAME)
|
||||||
@@ -57,8 +59,8 @@ sealed class AutofillScenario<out T : Any> {
|
|||||||
) ?: emptyList()
|
) ?: emptyList()
|
||||||
)
|
)
|
||||||
}.build()
|
}.build()
|
||||||
} catch (exception: IllegalArgumentException) {
|
}.getOrElse { e ->
|
||||||
e(exception)
|
e(e)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user