diff options
author | Torsten Grote <t@grobox.de> | 2020-09-01 11:12:31 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-09-01 11:13:17 -0300 |
commit | c928b458fce0c72c75852ab338a6e4e85a278ed4 (patch) | |
tree | 02f70b9be6ca1cc5cb30ad41631bac92d9f49ed0 | |
parent | c59243c9bdabf07137ad0f070b6ecbde57e66466 (diff) | |
download | taler-android-c928b458fce0c72c75852ab338a6e4e85a278ed4.tar.gz taler-android-c928b458fce0c72c75852ab338a6e4e85a278ed4.tar.bz2 taler-android-c928b458fce0c72c75852ab338a6e4e85a278ed4.zip |
[wallet] support the new TalerErrorInfo error format
Yet another last-minute breaking protocol change.
-rw-r--r-- | anastasis-ui/build.gradle | 4 | ||||
-rw-r--r-- | build.gradle | 2 | ||||
-rw-r--r-- | cashier/build.gradle | 4 | ||||
-rw-r--r-- | merchant-lib/build.gradle | 6 | ||||
-rw-r--r-- | merchant-terminal/build.gradle | 4 | ||||
-rw-r--r-- | taler-kotlin-android/build.gradle | 6 | ||||
-rw-r--r-- | wallet/build.gradle | 8 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt | 18 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt | 12 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt | 19 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt | 4 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt | 4 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt | 2 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt | 21 | ||||
-rw-r--r-- | wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt | 4 | ||||
-rw-r--r-- | wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt | 2 |
16 files changed, 72 insertions, 48 deletions
diff --git a/anastasis-ui/build.gradle b/anastasis-ui/build.gradle index ff0eec5..0f86815 100644 --- a/anastasis-ui/build.gradle +++ b/anastasis-ui/build.gradle @@ -38,6 +38,10 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug { + minifyEnabled minify_debug + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } } compileOptions { diff --git a/build.gradle b/build.gradle index 2bd92ab..61fff53 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,8 @@ buildscript { ext.constraintlayout_version = "2.0.1" // check https://android-rebuilds.beuc.net/ for availability of free build tools ext.build_tools_version = "29.0.2" + // should debug build types be minified with D8 as well? + ext.minify_debug = false repositories { google() jcenter() diff --git a/cashier/build.gradle b/cashier/build.gradle index 604a508..f5c56a9 100644 --- a/cashier/build.gradle +++ b/cashier/build.gradle @@ -41,6 +41,10 @@ android { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug { + minifyEnabled minify_debug + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } } kotlinOptions { diff --git a/merchant-lib/build.gradle b/merchant-lib/build.gradle index d76f867..87bafd3 100644 --- a/merchant-lib/build.gradle +++ b/merchant-lib/build.gradle @@ -38,7 +38,11 @@ android { buildTypes { release { - minifyEnabled false + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + debug { + minifyEnabled minify_debug proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } diff --git a/merchant-terminal/build.gradle b/merchant-terminal/build.gradle index 8c94fa1..f7bbc1c 100644 --- a/merchant-terminal/build.gradle +++ b/merchant-terminal/build.gradle @@ -25,6 +25,10 @@ android { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug { + minifyEnabled minify_debug + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } } compileOptions { diff --git a/taler-kotlin-android/build.gradle b/taler-kotlin-android/build.gradle index 8036800..e57d365 100644 --- a/taler-kotlin-android/build.gradle +++ b/taler-kotlin-android/build.gradle @@ -38,7 +38,11 @@ android { buildTypes { release { - minifyEnabled false + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + debug { + minifyEnabled minify_debug proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } diff --git a/wallet/build.gradle b/wallet/build.gradle index 5d02bca..30cf291 100644 --- a/wallet/build.gradle +++ b/wallet/build.gradle @@ -24,7 +24,7 @@ plugins { id "de.undercouch.download" } -def walletCoreVersion = "v0.7.1-dev.22" +def walletCoreVersion = "v0.7.1-dev.23" static def versionCodeEpoch() { return (new Date().getTime() / 1000).toInteger() @@ -48,7 +48,7 @@ android { minSdkVersion 24 targetSdkVersion 29 versionCode 6 - versionName "0.7.1.dev.22" + versionName "0.7.1.dev.23" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" buildConfigField "String", "WALLET_CORE_VERSION", "\"$walletCoreVersion\"" } @@ -57,6 +57,10 @@ android { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + debug { + minifyEnabled minify_debug + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } } flavorDimensions "distributionChannel" productFlavors { diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt index a72df9c..a2b48b6 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt @@ -157,20 +157,20 @@ class WalletBackendApi( } } sendRequest(operation, args?.invoke(JSONObject())) { isError, message -> - val response = if (isError) { - val error = - json.decodeFromString(WalletErrorInfo.serializer(), message.toString()) - WalletResponse.Error(error) - } else { - try { + val response = try { + if (isError) { + val error = + json.decodeFromString(TalerErrorInfo.serializer(), message.toString()) + WalletResponse.Error(error) + } else { val t: T = serializer?.let { json.decodeFromString(serializer, message.toString()) } ?: Unit as T WalletResponse.Success(t) - } catch (e: Exception) { - val info = WalletErrorInfo(0, "", e.toString(), null) - WalletResponse.Error(info) } + } catch (e: Exception) { + val info = TalerErrorInfo(0, "", e.toString(), null) + WalletResponse.Error(info) } cont.resume(response) } diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt index 993114c..c8a2bad 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletBackendService.kt @@ -184,13 +184,16 @@ class WalletBackendService : Service() { private fun handleAkonoMessage(messageStr: String) { val message = JSONObject(messageStr) - Log.v(TAG, "got back message: ${message.toString(2)}") when (val type = message.getString("type")) { "notification" -> { - sendNotify(message.getString("payload")) + val payload = message.getJSONObject("payload") + if (payload.optString("type") != "waiting-for-retry") { + Log.v(TAG, "got back notification: ${message.toString(2)}") + } + sendNotify(payload.toString()) } "tunnelHttp" -> { - Log.v(TAG, "got http tunnel request!") + Log.v(TAG, "got http tunnel request! ${message.toString(2)}") Intent().also { intent -> intent.action = HostCardEmulatorService.HTTP_TUNNEL_REQUEST intent.putExtra("tunnelMessage", messageStr) @@ -204,15 +207,18 @@ class WalletBackendService : Service() { sendNotify(message.toString(2)) } "reset" -> { + Log.v(TAG, "got back message: ${message.toString(2)}") exitProcess(1) } else -> { + Log.v(TAG, "got back response: ${message.toString(2)}") val payload = message.getJSONObject("result").toString(2) handleResponse(false, message, payload) } } } "error" -> { + Log.v(TAG, "got back error: ${message.toString(2)}") val payload = message.getJSONObject("error").toString(2) handleResponse(true, message, payload) } diff --git a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt index 5826997..2476607 100644 --- a/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt +++ b/wallet/src/main/java/net/taler/wallet/backend/WalletResponse.kt @@ -38,7 +38,7 @@ sealed class WalletResponse<T> { @Serializable @SerialName("error") data class Error<T>( - val error: WalletErrorInfo + val error: TalerErrorInfo ) : WalletResponse<T>() fun onSuccess(block: (result: T) -> Unit): WalletResponse<T> { @@ -46,35 +46,34 @@ sealed class WalletResponse<T> { return this } - fun onError(block: (result: WalletErrorInfo) -> Unit): WalletResponse<T> { + fun onError(block: (result: TalerErrorInfo) -> Unit): WalletResponse<T> { if (this is Error) block(this.error) return this } } @Serializable -data class WalletErrorInfo( +data class TalerErrorInfo( // Numeric error code defined defined in the // GANA gnu-taler-error-codes registry. - val talerErrorCode: Int, + val code: Int, // English description of the error code. - val talerErrorHint: String, + val hint: String?, // English diagnostic message that can give details // for the instance of the error. - val message: String, + val message: String?, - // Error details, type depends on talerErrorCode + // Error details @Serializable(JSONObjectDeserializer::class) val details: JSONObject? ) { val userFacingMsg: String get() { return StringBuilder().apply { - append(talerErrorCode) - append(" ") - append(message) + append(code) + message?.let { append(" ").append(it) } details?.let { details -> append("\n\n") details.optJSONObject("errorResponse")?.let { errorResponse -> diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt index befcd83..c364286 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt @@ -26,7 +26,7 @@ import net.taler.common.ContractTerms import net.taler.lib.common.Amount import net.taler.wallet.TAG import net.taler.wallet.backend.WalletBackendApi -import net.taler.wallet.backend.WalletErrorInfo +import net.taler.wallet.backend.TalerErrorInfo import net.taler.wallet.payment.PayStatus.AlreadyPaid import net.taler.wallet.payment.PayStatus.InsufficientBalance import net.taler.wallet.payment.PreparePayResponse.AlreadyConfirmedResponse @@ -130,7 +130,7 @@ class PaymentManager( mPayStatus.value = PayStatus.None } - private fun handleError(operation: String, error: WalletErrorInfo) { + private fun handleError(operation: String, error: TalerErrorInfo) { Log.e(TAG, "got $operation error result $error") mPayStatus.value = PayStatus.Error(error.userFacingMsg) } diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt index 2e99806..4b908b5 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentResponses.kt @@ -21,7 +21,7 @@ import kotlinx.serialization.Serializable import net.taler.common.ContractTerms import net.taler.lib.android.CustomClassDiscriminator import net.taler.lib.common.Amount -import net.taler.wallet.transactions.TransactionError +import net.taler.wallet.backend.TalerErrorInfo @Serializable sealed class PreparePayResponse { @@ -75,5 +75,5 @@ sealed class ConfirmPayResult { @Serializable @SerialName("pending") - data class Pending(val lastError: TransactionError) : ConfirmPayResult() + data class Pending(val lastError: TalerErrorInfo) : ConfirmPayResult() } diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt index 9dc2d23..936bbbd 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionAdapter.kt @@ -104,7 +104,7 @@ internal class TransactionAdapter( private fun bindExtraInfo(transaction: Transaction) { if (transaction.error != null) { extraInfoView.text = - context.getString(R.string.payment_error, transaction.error!!.text) + context.getString(R.string.payment_error, transaction.error!!.userFacingMsg) extraInfoView.setTextColor(red) extraInfoView.visibility = VISIBLE } else if (transaction is TransactionWithdrawal && !transaction.confirmed) { diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt index 3210093..603b754 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt @@ -28,6 +28,7 @@ import net.taler.common.ContractProduct import net.taler.lib.common.Amount import net.taler.lib.common.Timestamp import net.taler.wallet.R +import net.taler.wallet.backend.TalerErrorInfo import net.taler.wallet.cleanExchange import net.taler.wallet.transactions.WithdrawalDetails.ManualTransfer import net.taler.wallet.transactions.WithdrawalDetails.TalerBankIntegrationApi @@ -40,7 +41,7 @@ sealed class Transaction { abstract val transactionId: String abstract val timestamp: Timestamp abstract val pending: Boolean - abstract val error: TransactionError? + abstract val error: TalerErrorInfo? abstract val amountRaw: Amount abstract val amountEffective: Amount @@ -65,14 +66,6 @@ sealed class AmountType { } @Serializable -data class TransactionError( - private val ec: Int, - private val hint: String? = null, -) { - val text get() = if (hint == null) "$ec" else "$ec $hint" -} - -@Serializable @SerialName("withdrawal") class TransactionWithdrawal( override val transactionId: String, @@ -80,7 +73,7 @@ class TransactionWithdrawal( override val pending: Boolean, val exchangeBaseUrl: String, val withdrawalDetails: WithdrawalDetails, - override val error: TransactionError? = null, + override val error: TalerErrorInfo? = null, override val amountRaw: Amount, override val amountEffective: Amount ) : Transaction() { @@ -137,7 +130,7 @@ class TransactionPayment( override val pending: Boolean, val info: TransactionInfo, val status: PaymentStatus, - override val error: TransactionError? = null, + override val error: TalerErrorInfo? = null, override val amountRaw: Amount, override val amountEffective: Amount ) : Transaction() { @@ -197,7 +190,7 @@ class TransactionRefund( * Part of the refund that couldn't be applied because the refund permissions were expired */ val amountInvalid: Amount? = null, - override val error: TransactionError? = null, + override val error: TalerErrorInfo? = null, @SerialName("amountEffective") // TODO remove when fixed in wallet-core override val amountRaw: Amount, @SerialName("amountRaw") // TODO remove when fixed in wallet-core @@ -224,7 +217,7 @@ class TransactionTip( // TODO status: TipStatus, val exchangeBaseUrl: String, val merchant: ContractMerchant, - override val error: TransactionError? = null, + override val error: TalerErrorInfo? = null, override val amountRaw: Amount, override val amountEffective: Amount ) : Transaction() { @@ -247,7 +240,7 @@ class TransactionRefresh( override val timestamp: Timestamp, override val pending: Boolean, val exchangeBaseUrl: String, - override val error: TransactionError? = null, + override val error: TalerErrorInfo? = null, override val amountRaw: Amount, override val amountEffective: Amount ) : Transaction() { diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt index 730f704..b6b4285 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt @@ -25,7 +25,7 @@ import kotlinx.serialization.Serializable import net.taler.lib.common.Amount import net.taler.wallet.TAG import net.taler.wallet.backend.WalletBackendApi -import net.taler.wallet.backend.WalletErrorInfo +import net.taler.wallet.backend.TalerErrorInfo import net.taler.wallet.exchanges.ExchangeFees import net.taler.wallet.exchanges.ExchangeItem import net.taler.wallet.withdraw.WithdrawStatus.ReceivedDetails @@ -201,7 +201,7 @@ class WithdrawManager( } @UiThread - private fun handleError(operation: String, error: WalletErrorInfo) { + private fun handleError(operation: String, error: TalerErrorInfo) { Log.e(TAG, "Error $operation $error") withdrawStatus.value = WithdrawStatus.Error(error.userFacingMsg) } diff --git a/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt b/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt index 4872149..a88b203 100644 --- a/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt +++ b/wallet/src/test/java/net/taler/wallet/backend/WalletResponseTest.kt @@ -67,7 +67,7 @@ class WalletResponseTest { "message":"unexpected exception: Error: BUG: invariant violation (purchase status)" } """.trimIndent() - val info = json.decodeFromString(WalletErrorInfo.serializer(), infoJson) + val info = json.decodeFromString(TalerErrorInfo.serializer(), infoJson) println(info.userFacingMsg) } } |