gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-android] branch master updated (c9fb036 -> 4bd0b7a)


From: gnunet
Subject: [taler-taler-android] branch master updated (c9fb036 -> 4bd0b7a)
Date: Tue, 21 Jul 2020 20:07:05 +0200

This is an automated email from the git hooks/post-receive script.

torsten-grote pushed a change to branch master
in repository taler-android.

    from c9fb036  [pos] create merchant-lib and move first v1 API endpoint there
     new 5d3d85f  [pos] compare version from backend and show error if 
incompatible
     new 18f3115  [wallet] introduce build flavors for distribution channels
     new 4bd0b7a  [pos] config endpoint does not need authentication

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/java/net/taler/merchantlib/MerchantApi.kt |  8 +--
 .../net/taler/merchantpos/config/ConfigManager.kt  | 15 ++---
 merchant-terminal/src/main/res/values/strings.xml  |  1 -
 .../src/main/java/net/taler/common/AndroidUtils.kt |  9 +++
 .../src/main/java/net/taler/common/Version.kt      | 70 ++++++++++++++++++++++
 .../src/main/res/values/strings.xml                |  6 +-
 .../src/test/java/net/taler/common/VersionTest.kt  | 65 ++++++++++++++++++++
 wallet/.gitlab-ci.yml                              | 14 +----
 wallet/build.gradle                                | 28 +++++++++
 .../net/taler/wallet/settings/SettingsFragment.kt  |  3 +-
 .../src/nightly/res/values/strings.xml             |  4 +-
 11 files changed, 190 insertions(+), 33 deletions(-)
 create mode 100644 
taler-kotlin-common/src/main/java/net/taler/common/Version.kt
 copy wallet/src/main/res/values/colors.xml => 
taler-kotlin-common/src/main/res/values/strings.xml (75%)
 create mode 100644 
taler-kotlin-common/src/test/java/net/taler/common/VersionTest.kt
 copy cashier/src/main/res/values-night/colors.xml => 
wallet/src/nightly/res/values/strings.xml (89%)

diff --git a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt 
b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
index 656b093..3406f78 100644
--- a/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
+++ b/merchant-lib/src/main/java/net/taler/merchantlib/MerchantApi.kt
@@ -21,17 +21,13 @@ import io.ktor.client.engine.okhttp.OkHttp
 import io.ktor.client.features.json.JsonFeature
 import io.ktor.client.features.json.serializer.KotlinxSerializer
 import io.ktor.client.request.get
-import io.ktor.client.request.header
-import io.ktor.http.HttpHeaders.Authorization
 
 class MerchantApi(private val httpClient: HttpClient) {
 
     constructor() : this(getDefaultHttpClient())
 
-    suspend fun getConfig(baseUrl: String, apiKey: String = "sandbox"): 
ConfigResponse {
-        return httpClient.get("$baseUrl/config") {
-            header(Authorization, "ApiKey $apiKey")
-        }
+    suspend fun getConfig(baseUrl: String): ConfigResponse {
+        return httpClient.get("$baseUrl/config")
     }
 
 }
diff --git 
a/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt 
b/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt
index eee7905..3f45e32 100644
--- 
a/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt
+++ 
b/merchant-terminal/src/main/java/net/taler/merchantpos/config/ConfigManager.kt
@@ -34,14 +34,14 @@ import com.fasterxml.jackson.module.kotlin.readValue
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.launch
+import net.taler.common.Version
+import net.taler.common.getIncompatibleStringOrNull
 import net.taler.merchantlib.ConfigResponse
 import net.taler.merchantlib.MerchantApi
 import net.taler.merchantpos.LogErrorListener
 import net.taler.merchantpos.R
 import org.json.JSONObject
 
-private const val VERSION = "0:0:0"
-
 private const val SETTINGS_NAME = "taler-merchant-terminal"
 
 private const val SETTINGS_CONFIG_URL = "configUrl"
@@ -52,6 +52,8 @@ internal const val CONFIG_URL_DEMO = 
"https://docs.taler.net/_static/sample-pos-
 internal const val CONFIG_USERNAME_DEMO = ""
 internal const val CONFIG_PASSWORD_DEMO = ""
 
+private val VERSION = Version(1, 0, 0)
+
 private val TAG = ConfigManager::class.java.simpleName
 
 interface ConfigurationReceiver {
@@ -120,7 +122,7 @@ class ConfigManager(
         }
 
         scope.launch(Dispatchers.IO) {
-            val configResponse = api.getConfig(merchantConfig.baseUrl, 
merchantConfig.apiKey)
+            val configResponse = api.getConfig(merchantConfig.baseUrl)
             onMerchantConfigReceived(config, json, merchantConfig, 
configResponse)
         }
     }
@@ -131,10 +133,9 @@ class ConfigManager(
         merchantConfig: MerchantConfig,
         configResponse: ConfigResponse
     ) = scope.launch(Dispatchers.Default) {
-        // TODO do real matching
-        if (VERSION != configResponse.version) {
-            val str = context.getString(R.string.config_error_version)
-            mConfigUpdateResult.postValue(ConfigUpdateResult.Error(str))
+        val versionIncompatible = VERSION.getIncompatibleStringOrNull(context, 
configResponse.version)
+        if (versionIncompatible != null) {
+            
mConfigUpdateResult.postValue(ConfigUpdateResult.Error(versionIncompatible))
             return@launch
         }
         for (receiver in configurationReceivers) {
diff --git a/merchant-terminal/src/main/res/values/strings.xml 
b/merchant-terminal/src/main/res/values/strings.xml
index 931f31c..b3dcd8d 100644
--- a/merchant-terminal/src/main/res/values/strings.xml
+++ b/merchant-terminal/src/main/res/values/strings.xml
@@ -22,7 +22,6 @@
     <string name="config_password">Password</string>
     <string name="config_ok">Fetch configuration</string>
     <string name="config_auth_error">Error: Invalid username or 
password</string>
-    <string name="config_error_version">Error: Incompatible backend 
version</string>
     <string name="config_error_network">Error: Could not connect to 
configuration server</string>
     <string name="config_error_category">Error: No valid product category 
found</string>
     <string name="config_error_malformed">Error: The configuration JSON is 
malformed</string>
diff --git a/taler-kotlin-common/src/main/java/net/taler/common/AndroidUtils.kt 
b/taler-kotlin-common/src/main/java/net/taler/common/AndroidUtils.kt
index ba6ee1c..b46f306 100644
--- a/taler-kotlin-common/src/main/java/net/taler/common/AndroidUtils.kt
+++ b/taler-kotlin-common/src/main/java/net/taler/common/AndroidUtils.kt
@@ -112,3 +112,12 @@ fun Long.toShortDate(context: Context): CharSequence {
     val flags = FORMAT_SHOW_DATE or FORMAT_SHOW_YEAR or FORMAT_ABBREV_ALL
     return formatDateTime(context, this, flags)
 }
+
+fun Version.getIncompatibleStringOrNull(context: Context, otherVersion: 
String): String? {
+    val other = Version.parse(otherVersion) ?: return 
context.getString(R.string.version_invalid)
+    val match = compare(other) ?: return 
context.getString(R.string.version_invalid)
+    if (match.compatible) return null
+    if (match.currentCmp < 0) return 
context.getString(R.string.version_too_old)
+    if (match.currentCmp > 0) return 
context.getString(R.string.version_too_new)
+    throw AssertionError("$this == $other")
+}
diff --git a/taler-kotlin-common/src/main/java/net/taler/common/Version.kt 
b/taler-kotlin-common/src/main/java/net/taler/common/Version.kt
new file mode 100644
index 0000000..8774115
--- /dev/null
+++ b/taler-kotlin-common/src/main/java/net/taler/common/Version.kt
@@ -0,0 +1,70 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under 
the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+ * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.common
+
+import kotlin.math.sign
+
+/**
+ * Semantic versioning, but libtool-style.
+ * See 
https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
+ */
+data class Version(
+    val current: Int,
+    val revision: Int,
+    val age: Int
+) {
+    companion object {
+        fun parse(v: String): Version? {
+            val elements = v.split(":")
+            if (elements.size != 3) return null
+            val (currentStr, revisionStr, ageStr) = elements
+            val current = currentStr.toIntOrNull()
+            val revision = revisionStr.toIntOrNull()
+            val age = ageStr.toIntOrNull()
+            if (current == null || revision == null || age == null) return null
+            return Version(current, revision, age)
+        }
+    }
+
+    /**
+     * Compare two libtool-style versions.
+     *
+     * Returns a [VersionMatchResult] or null if the given version was null.
+     */
+    fun compare(other: Version?): VersionMatchResult? {
+        if (other == null) return null
+        val compatible = current - age <= other.current &&
+                current >= other.current - other.age
+        val currentCmp = sign((current - other.current).toDouble()).toInt()
+        return VersionMatchResult(compatible, currentCmp)
+    }
+
+    /**
+     * Result of comparing two libtool versions.
+     */
+    data class VersionMatchResult(
+        /**
+         * Is the first version compatible with the second?
+         */
+        val compatible: Boolean,
+        /**
+         * Is the first version older (-1), newer (+1) or identical (0)?
+         */
+        val currentCmp: Int
+    )
+
+}
diff --git a/wallet/src/main/res/values/colors.xml 
b/taler-kotlin-common/src/main/res/values/strings.xml
similarity index 75%
copy from wallet/src/main/res/values/colors.xml
copy to taler-kotlin-common/src/main/res/values/strings.xml
index 6413bb8..a5b1df1 100644
--- a/wallet/src/main/res/values/colors.xml
+++ b/taler-kotlin-common/src/main/res/values/strings.xml
@@ -15,7 +15,7 @@
   -->
 
 <resources>
-    <color name="colorPrimary">#283593</color>
-    <color name="colorPrimaryDark">#1A237E</color>
-    <color name="colorAccent">#AE1010</color>
+    <string name="version_invalid">Invalid version. Please try again 
later!</string>
+    <string name="version_too_old">App too old. Please upgrade!</string>
+    <string name="version_too_new">Service outdated. Please wait until it gets 
upgraded.</string>
 </resources>
diff --git a/taler-kotlin-common/src/test/java/net/taler/common/VersionTest.kt 
b/taler-kotlin-common/src/test/java/net/taler/common/VersionTest.kt
new file mode 100644
index 0000000..70f30eb
--- /dev/null
+++ b/taler-kotlin-common/src/test/java/net/taler/common/VersionTest.kt
@@ -0,0 +1,65 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under 
the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
+ * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.common
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
+import org.junit.Test
+
+class VersionTest {
+
+    @Test
+    fun testParse() {
+        assertNull(Version.parse(""))
+        assertNull(Version.parse("foo"))
+        assertNull(Version.parse("foo:bar:foo"))
+        assertNull(Version.parse("0:0:0:"))
+        assertNull(Version.parse("0:0:"))
+        assertEquals(Version(0, 0, 0), Version.parse("0:0:0"))
+        assertEquals(Version(1, 2, 3), Version.parse("1:2:3"))
+        assertEquals(Version(1337, 42, 23), Version.parse("1337:42:23"))
+    }
+
+    @Test
+    fun testComparision() {
+        assertEquals(
+            Version.VersionMatchResult(true, 0),
+            Version.parse("0:0:0")!!.compare(Version.parse("0:0:0"))
+        )
+        assertEquals(
+            Version.VersionMatchResult(true, -1),
+            Version.parse("0:0:0")!!.compare(Version.parse("1:0:1"))
+        )
+        assertEquals(
+            Version.VersionMatchResult(true, -1),
+            Version.parse("0:0:0")!!.compare(Version.parse("1:5:1"))
+        )
+        assertEquals(
+            Version.VersionMatchResult(false, -1),
+            Version.parse("0:0:0")!!.compare(Version.parse("1:5:0"))
+        )
+        assertEquals(
+            Version.VersionMatchResult(false, 1),
+            Version.parse("1:0:0")!!.compare(Version.parse("0:5:0"))
+        )
+        assertEquals(
+            Version.VersionMatchResult(true, 0),
+            Version.parse("1:0:1")!!.compare(Version.parse("1:5:1"))
+        )
+    }
+
+}
diff --git a/wallet/.gitlab-ci.yml b/wallet/.gitlab-ci.yml
index 8845aa4..56768f7 100644
--- a/wallet/.gitlab-ci.yml
+++ b/wallet/.gitlab-ci.yml
@@ -23,20 +23,8 @@ wallet_deploy_nightly:
   script:
     # Ensure that key exists
     - test -z "$DEBUG_KEYSTORE" && exit 0
-    # Rename nightly app
-    - sed -i
-      's,<string name="app_name">.*</string>,<string name="app_name">Taler 
Wallet Nightly</string>,'
-      wallet/src/main/res/values*/strings.xml
-    # Set time-based version code
-    - export versionCode=$(date '+%s')
-    - sed -i "s,^\(\s*versionCode\) *[0-9].*,\1 $versionCode," 
wallet/build.gradle
-    # Add commit to version name
-    - export versionName=$(git rev-parse --short=7 HEAD)
-    - sed -i "s,^\(\s*versionName\ *\"[0-9].*\)\",\1 ($versionName)\"," 
wallet/build.gradle
-    # Set nightly application ID
-    - sed -i "s,^\(\s*applicationId\) \"*[a-z\.].*\",\1 
\"net.taler.wallet.nightly\"," wallet/build.gradle
     # Build the APK
-    - ./gradlew :wallet:assembleDebug
+    - ./gradlew :wallet:assembleNightlyDebug
     # START only needed while patch not accepted/released upstream
     - apt update && apt install patch
     - patch -b /usr/lib/python3/dist-packages/fdroidserver/nightly.py 
nightly-stats.patch
diff --git a/wallet/build.gradle b/wallet/build.gradle
index d93b8b9..5b28c6c 100644
--- a/wallet/build.gradle
+++ b/wallet/build.gradle
@@ -25,6 +25,18 @@ plugins {
 
 def walletCoreVersion = "v0.7.1-dev.10"
 
+static def versionCodeEpoch() {
+    return (new Date().getTime() / 1000).toInteger()
+}
+def gitCommit = { ->
+    def stdout = new ByteArrayOutputStream()
+    exec {
+        commandLine 'git', 'rev-parse', '--short=7', 'HEAD'
+        standardOutput = stdout
+    }
+    return stdout.toString().trim()
+}
+
 android {
     compileSdkVersion 29
     //noinspection GradleDependency
@@ -45,6 +57,22 @@ android {
             proguardFiles 
getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
         }
     }
+    flavorDimensions "distributionChannel"
+    productFlavors {
+        fdroid {
+            dimension "distributionChannel"
+            applicationIdSuffix ".fdroid"
+        }
+        google {
+            dimension "distributionChannel"
+        }
+        nightly {
+            dimension "distributionChannel"
+            applicationIdSuffix ".nightly"
+            versionCode versionCodeEpoch()
+            versionNameSuffix " ($gitCommit)"
+        }
+    }
 
     compileOptions {
         sourceCompatibility = 1.8
diff --git a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt 
b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
index d9b1def..a52b9d8 100644
--- a/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/settings/SettingsFragment.kt
@@ -27,6 +27,7 @@ import androidx.preference.SwitchPreferenceCompat
 import com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_SHORT
 import com.google.android.material.snackbar.Snackbar
 import net.taler.common.toRelativeTime
+import net.taler.wallet.BuildConfig.FLAVOR
 import net.taler.wallet.BuildConfig.VERSION_CODE
 import net.taler.wallet.BuildConfig.VERSION_NAME
 import net.taler.wallet.BuildConfig.WALLET_CORE_VERSION
@@ -82,7 +83,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
         model.devMode.observe(viewLifecycleOwner, Observer { enabled ->
             prefDevMode.isChecked = enabled
             if (enabled) {
-                prefVersionApp.summary = "$VERSION_NAME ($VERSION_CODE)"
+                prefVersionApp.summary = "$VERSION_NAME ($FLAVOR 
$VERSION_CODE)"
                 prefVersionCore.summary = WALLET_CORE_VERSION
                 model.exchangeVersion?.let { prefVersionExchange.summary = it }
                 model.merchantVersion?.let { prefVersionMerchant.summary = it }
diff --git a/cashier/src/main/res/values-night/colors.xml 
b/wallet/src/nightly/res/values/strings.xml
similarity index 89%
copy from cashier/src/main/res/values-night/colors.xml
copy to wallet/src/nightly/res/values/strings.xml
index c46823c..7276d52 100644
--- a/cashier/src/main/res/values-night/colors.xml
+++ b/wallet/src/nightly/res/values/strings.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?><!--
+<!--
   ~ This file is part of GNU Taler
   ~ (C) 2020 Taler Systems S.A.
   ~
@@ -15,5 +15,5 @@
   -->
 
 <resources>
-    <color name="background">#222222</color>
+    <string name="app_name">Taler Wallet Nightly</string>
 </resources>

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]