Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8373f9f6 authored by Grace Cheng's avatar Grace Cheng
Browse files

Prevent bouncer message crash

Prevent bouncer message crash from invalid resource id

Flag: EXEMPT BUGFIX
Fixes: 443671401
Test: atest BouncerMessageViewModelTest
Change-Id: I42610ee232df97b287546dd846d07118dd3c35d0
parent d678aab7
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -208,15 +208,15 @@ constructor(
                    faceAllowedOnBouncer,
                    isSecureLockDeviceEnabled) ->
                val isFaceAuthStrong = faceAuthInteractor.isFaceAuthStrong()
                val defaultPrimaryMessage =
                val defaultMessage =
                    BouncerMessageStrings.defaultMessage(
                        securityMode = authMethod,
                        fpAuthIsAllowed = fingerprintAllowedOnBouncer,
                        faceAuthIsAllowed = faceAllowedOnBouncer,
                        secureLockDeviceEnabled = isSecureLockDeviceEnabled,
                    )
                        .primaryMessage
                        .toResString()
                val defaultPrimaryMessage = defaultMessage.primaryMessage.toResString()

                message.value =
                    when (faceMessage) {
                        is FaceTimeoutMessage ->
@@ -295,15 +295,14 @@ constructor(
                    fingerprintAllowedOnBouncer,
                    faceAllowedOnBouncer,
                    isSecureLockDeviceEnabled) ->
                val defaultPrimaryMessage =
                val defaultMessage =
                    BouncerMessageStrings.defaultMessage(
                            authMethod,
                            fingerprintAllowedOnBouncer,
                            faceAllowedOnBouncer,
                            isSecureLockDeviceEnabled,
                        securityMode = authMethod,
                        fpAuthIsAllowed = fingerprintAllowedOnBouncer,
                        faceAuthIsAllowed = faceAllowedOnBouncer,
                        secureLockDeviceEnabled = isSecureLockDeviceEnabled,
                    )
                        .primaryMessage
                        .toResString()
                val defaultPrimaryMessage = defaultMessage.primaryMessage.toResString()
                message.value =
                    when (fingerprintMessage) {
                        is FingerprintLockoutMessage ->
@@ -424,9 +423,8 @@ constructor(
    }

    private fun BouncerMessagePair.toMessage(): MessageViewModel {
        val primaryMsg = if (this.primaryMessage == 0) "" else this.primaryMessage.toResString()
        val secondaryMsg =
            if (this.secondaryMessage == 0) "" else this.secondaryMessage.toResString()
        val primaryMsg = this.primaryMessage.toResString()
        val secondaryMsg = this.secondaryMessage.toResString()
        return MessageViewModel(primaryMsg, secondaryText = secondaryMsg, isUpdateAnimated = true)
    }

@@ -473,7 +471,7 @@ constructor(
    private fun Int.toPluralString(formatterArgs: Map<String, Any>): String =
        PluralsMessageFormatter.format(applicationContext.resources, formatterArgs, this)

    private fun Int.toResString(): String = applicationContext.getString(this)
    private fun Int.toResString(): String = if (this == 0) "" else applicationContext.getString(this)

    @AssistedFactory
    interface Factory {