Skip to content

Commit

Permalink
Merge pull request #412 from tangem/merge_5.16_dev
Browse files Browse the repository at this point in the history
Merge 5.16 dev
  • Loading branch information
Mama1emon authored Oct 10, 2024
2 parents 9d6a993 + f6fdc78 commit 2ea3795
Show file tree
Hide file tree
Showing 29 changed files with 416 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.tangem.common.card.Card
import com.tangem.common.card.EllipticCurve
import com.tangem.common.core.CompletionCallback
import com.tangem.common.core.Config
import com.tangem.common.core.ProductType
import com.tangem.common.core.TangemError
import com.tangem.common.core.TangemSdkError
import com.tangem.common.extensions.VoidCallback
Expand Down Expand Up @@ -180,10 +181,12 @@ class SdkTaskSpinnerFragment : BaseFragment() {
message: ViewDelegateMessage?,
enableHowTo: Boolean,
iconScanRes: Int?,
productType: ProductType,
) {}
override fun onSecurityDelay(ms: Int, totalDurationSeconds: Int) {}
override fun onDelay(total: Int, current: Int, step: Int) {}
override fun onTagLost() {}

override fun onSecurityDelay(ms: Int, totalDurationSeconds: Int, productType: ProductType) {}
override fun onDelay(total: Int, current: Int, step: Int, productType: ProductType) {}
override fun onTagLost(productType: ProductType) {}
override fun onTagConnected() {}
override fun onWrongCard(wrongValueType: WrongValueType) {}
override fun onSessionStopped(message: Message?) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.google.android.material.slider.Slider
import com.tangem.SessionViewDelegate
import com.tangem.WrongValueType
import com.tangem.common.UserCodeType
import com.tangem.common.core.ProductType
import com.tangem.common.core.TangemSdkError
import com.tangem.demo.inflate
import com.tangem.demo.ui.extension.withMainContext
Expand Down Expand Up @@ -87,19 +88,19 @@ class TagConnectTagLostError : BaseDelegateAction() {
}

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onTagConnected() }
delay(timeMillis = 2000)
withMainContext { delegate.onTagLost() }
withMainContext { delegate.onTagLost(ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onTagConnected() }
delay(timeMillis = 2000)
withMainContext { delegate.onTagLost() }
withMainContext { delegate.onTagLost(ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onError(TangemSdkError.UnknownError()) }
delay(timeMillis = 2000)
withMainContext { delegate.onTagLost() }
withMainContext { delegate.onTagLost(ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.dismiss() }
}
Expand Down Expand Up @@ -129,7 +130,7 @@ class SecurityDelay : BaseDelegateAction() {
}

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onTagConnected() }

Expand All @@ -139,7 +140,13 @@ class SecurityDelay : BaseDelegateAction() {
repeat(securityDelayCounts) {
delay(timeMillis = 1000)
currentMs = currentMs.minus(other = 100)
withMainContext { delegate.onSecurityDelay(currentMs, totalDurationMs) }
withMainContext {
delegate.onSecurityDelay(
ms = currentMs,
totalDurationSeconds = totalDurationMs,
productType = ProductType.ANY,
)
}
}

withMainContext { delegate.onSessionStopped(null) }
Expand Down Expand Up @@ -170,7 +177,7 @@ class SecurityDelayPinFails : BaseDelegateAction() {
}

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onTagConnected() }
delay(timeMillis = 1000)
Expand All @@ -180,11 +187,17 @@ class SecurityDelayPinFails : BaseDelegateAction() {
repeat(repeatCounts) {
delay(timeMillis = 1000)
currentMs = currentMs.minus(other = 100)
withMainContext { delegate.onSecurityDelay(ms = currentMs, totalDurationSeconds = 0) }
withMainContext {
delegate.onSecurityDelay(
ms = currentMs,
totalDurationSeconds = 0,
productType = ProductType.ANY,
)
}
}

delay(timeMillis = 2000)
withMainContext { delegate.onTagLost() }
withMainContext { delegate.onTagLost(ProductType.ANY) }
delay(timeMillis = 1000)
withMainContext { delegate.dismiss() }
}
Expand All @@ -201,7 +214,7 @@ class WrongCard : BaseDelegateAction() {
}

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onTagConnected() }
delay(timeMillis = 2000)
Expand All @@ -224,7 +237,7 @@ class OnError : BaseDelegateAction() {
}

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onTagConnected() }
delay(timeMillis = 2000)
Expand All @@ -247,19 +260,19 @@ class RequestAccessCode : BaseDelegateAction() {
}

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCode(UserCodeType.AccessCode, true, false, null) {} }
delay(timeMillis = 2000)
withMainContext { delegate.dismiss() }
delay(timeMillis = 500)
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCode(UserCodeType.AccessCode, false, false, null) {} }
delay(timeMillis = 2000)
withMainContext { delegate.dismiss() }
delay(timeMillis = 500)
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCode(UserCodeType.AccessCode, true, false, null) {} }
delay(timeMillis = 2000)
Expand All @@ -276,7 +289,7 @@ class SingleRequestAccessCode(
override fun usedCommandsInfo(): String = "RequestUserCode(access,true), Dismiss"

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCode(UserCodeType.AccessCode, true, showForgotButton, null) {} }
}
Expand All @@ -295,19 +308,19 @@ class RequestPasscode : BaseDelegateAction() {
}

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCode(UserCodeType.Passcode, true, false, null) {} }
delay(timeMillis = 2000)
withMainContext { delegate.dismiss() }
delay(timeMillis = 500)
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCode(UserCodeType.Passcode, false, false, null) {} }
delay(timeMillis = 2000)
withMainContext { delegate.dismiss() }
delay(timeMillis = 500)
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCode(UserCodeType.Passcode, true, false, null) {} }
delay(timeMillis = 2000)
Expand Down Expand Up @@ -349,7 +362,7 @@ class RequestPinSetup : BaseDelegateAction() {
override fun usedCommandsInfo(): String = "SessionStarted, RequestPinSetup"

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 500)
withMainContext { delegate.requestUserCodeChange(UserCodeType.Passcode, null) {} }
}
Expand All @@ -364,7 +377,7 @@ class ErrorsWithDifferentFormats : BaseDelegateAction() {
""".trimIndent()

override fun getCommandsPool(): suspend () -> Unit = suspend {
withMainContext { delegate.onSessionStarted(null, null, true) }
withMainContext { delegate.onSessionStarted(null, null, true, null, ProductType.ANY) }
delay(timeMillis = 2000)
withMainContext { delegate.onError(TangemSdkError.BackupFailedIncompatibleBatch()) }
delay(timeMillis = 5000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class AndroidStringLocator(val context: Context) : StringsLocator {
StringsLocator.ID.BACKUP_ADD_BACKUP_CARD_MESSAGE -> "backup_add_backup_card_message"
StringsLocator.ID.BACKUP_FINALIZE_PRIMARY_CARD_MESSAGE_FORMAT ->
"backup_finalize_primary_card_message_format"
StringsLocator.ID.BACKUP_FINALIZE_PRIMARY_RING_MESSAGE -> "backup_finalize_primary_ring_message"
StringsLocator.ID.BACKUP_FINALIZE_BACKUP_CARD_MESSAGE_FORMAT -> "backup_finalize_backup_card_message_format"
StringsLocator.ID.BACKUP_FINALIZE_BACKUP_RING_MESSAGE -> "backup_finalize_backup_ring_message"
StringsLocator.ID.RESET_CODES_SCAN_FIRST_CARD -> "reset_codes_scan_first_card"
StringsLocator.ID.RESET_CODES_SCAN_CONFIRMATION_CARD -> "reset_codes_scan_confirmation_card"
StringsLocator.ID.RESET_CODES_SCAN_TO_RESET -> "reset_codes_scan_to_reset"
Expand All @@ -50,6 +52,10 @@ class AndroidStringLocator(val context: Context) : StringsLocator {
StringsLocator.ID.PIN_2 -> "pin2"
StringsLocator.ID.PIN_RESET_CODE_FORMAT -> "pin_reset_code_format"
StringsLocator.ID.SIGN_MULTIPLE_CHUNKS_PART -> "sign_multiple_chunks_part"
StringsLocator.ID.VIEW_DELEGATE_SCAN_DESCRIPTION_FORMAT -> "view_delegate_scan_description_format"
StringsLocator.ID.VIEW_DELEGATE_SECURITY_DELAY_DESCRIPTION_FORMAT -> {
"view_delegate_security_delay_description_format"
}
}

return R.string::class.java.getDeclaredField(resourceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.tangem.common.CardIdFormatter
import com.tangem.common.UserCodeType
import com.tangem.common.core.CompletionCallback
import com.tangem.common.core.Config
import com.tangem.common.core.ProductType
import com.tangem.common.core.TangemError
import com.tangem.common.extensions.VoidCallback
import com.tangem.operations.resetcode.ResetCodesViewDelegate
Expand Down Expand Up @@ -44,9 +45,15 @@ class DefaultSessionViewDelegate(
message: ViewDelegateMessage?,
enableHowTo: Boolean,
iconScanRes: Int?,
productType: ProductType,
) {
Log.view { "session started" }
createAndShowState(SessionViewDelegateState.Ready(formatCardId(cardId)), enableHowTo, message, iconScanRes)
createAndShowState(
state = SessionViewDelegateState.Ready(formatCardId(cardId), productType),
enableHowTo = enableHowTo,
message = message,
iconScanRes = iconScanRes,
)
checkNfcEnabled()
}

Expand All @@ -72,19 +79,19 @@ class DefaultSessionViewDelegate(
readingDialog?.show(SessionViewDelegateState.Success(message))
}

override fun onSecurityDelay(ms: Int, totalDurationSeconds: Int) {
override fun onSecurityDelay(ms: Int, totalDurationSeconds: Int, productType: ProductType) {
Log.view { "showing security delay: $ms, $totalDurationSeconds" }
readingDialog?.show(SessionViewDelegateState.SecurityDelay(ms, totalDurationSeconds))
readingDialog?.show(SessionViewDelegateState.SecurityDelay(ms, totalDurationSeconds, productType))
}

override fun onDelay(total: Int, current: Int, step: Int) {
override fun onDelay(total: Int, current: Int, step: Int, productType: ProductType) {
Log.view { "showing delay" }
readingDialog?.show(SessionViewDelegateState.Delay(total, current, step))
readingDialog?.show(SessionViewDelegateState.Delay(total, current, step, productType))
}

override fun onTagLost() {
override fun onTagLost(productType: ProductType) {
Log.view { "tag lost" }
readingDialog?.show(SessionViewDelegateState.TagLost)
readingDialog?.show(SessionViewDelegateState.TagLost(productType))
}

override fun onTagConnected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,24 @@ import com.tangem.Message
import com.tangem.WrongValueType
import com.tangem.common.UserCodeType
import com.tangem.common.core.CompletionCallback
import com.tangem.common.core.ProductType
import com.tangem.common.core.TangemError
import com.tangem.operations.resetcode.ResetPinService

sealed class SessionViewDelegateState {
data class Error(val error: TangemError) : SessionViewDelegateState()
data class Success(val message: Message?) : SessionViewDelegateState()
data class SecurityDelay(val ms: Int, val totalDurationSeconds: Int) :
data class SecurityDelay(val ms: Int, val totalDurationSeconds: Int, val productType: ProductType) :
SessionViewDelegateState()

data class Delay(val total: Int, val current: Int, val step: Int) : SessionViewDelegateState()
data class Ready(val cardId: String?) : SessionViewDelegateState()
data class Delay(
val total: Int,
val current: Int,
val step: Int,
val productType: ProductType,
) : SessionViewDelegateState()

data class Ready(val cardId: String?, val productType: ProductType) : SessionViewDelegateState()
data class PinRequested(
val type: UserCodeType,
val isFirstAttempt: Boolean,
Expand All @@ -37,7 +44,7 @@ sealed class SessionViewDelegateState {
) : SessionViewDelegateState()

data class WrongCard(val wrongValueType: WrongValueType) : SessionViewDelegateState()
object TagLost : SessionViewDelegateState()
data class TagLost(val productType: ProductType) : SessionViewDelegateState()
object TagConnected : SessionViewDelegateState()
object HowToTap : SessionViewDelegateState()
object None : SessionViewDelegateState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.tangem.Log
import com.tangem.ViewDelegateMessage
import com.tangem.common.CompletionResult
import com.tangem.common.Timer
import com.tangem.common.core.ProductType
import com.tangem.common.core.ScanTagImage
import com.tangem.common.core.SessionEnvironment
import com.tangem.common.core.TangemSdkError
Expand Down Expand Up @@ -292,10 +293,18 @@ class NfcSessionDialog(
private fun activateTrickySecurityDelay(totalDuration: Long) {
val timer = Timer(period = totalDuration, step = 100L, delayMs = 1000L, dispatcher = Dispatchers.IO)
timer.onComplete = {
postUI { onSecurityDelay(SessionViewDelegateState.SecurityDelay(0, 0)) }
postUI { onSecurityDelay(SessionViewDelegateState.SecurityDelay(0, 0, ProductType.ANY)) }
}
timer.onTick = {
postUI { onSecurityDelay(SessionViewDelegateState.SecurityDelay((totalDuration - it).toInt(), 0)) }
postUI {
onSecurityDelay(
SessionViewDelegateState.SecurityDelay(
ms = (totalDuration - it).toInt(),
totalDurationSeconds = 0,
productType = ProductType.ANY,
),
)
}
}
timer.start()
emulateSecurityDelayTimer = timer
Expand All @@ -310,7 +319,7 @@ class NfcSessionDialog(
emulateSecurityDelayTimer?.period?.let { activateTrickySecurityDelay(it) }
}

SessionViewDelegateState.TagLost -> {
is SessionViewDelegateState.TagLost -> {
emulateSecurityDelayTimer?.cancel()
}

Expand All @@ -326,7 +335,7 @@ class NfcSessionDialog(
}

private fun getEmptyOnReadyEvent(): SessionViewDelegateState {
return SessionViewDelegateState.Ready(headerWidget.cardId)
return SessionViewDelegateState.Ready(headerWidget.cardId, ProductType.ANY)
}

private companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class HeaderWidget(mainView: View) : BaseSessionDelegateStateWidget(mainView) {
if (scannedCardId == null) {
tvCard.text = ""
} else {
tvCard.show()
tvCard.text = getString(R.string.view_delegate_header_card)
tvCardId.show()
tvCardId.text = scannedCardId
}
Expand Down
Loading

0 comments on commit 2ea3795

Please sign in to comment.