diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index ba29aad2..83106060 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -32,10 +32,11 @@ android { minSdkVersion 16 targetSdkVersion 28 versionCode 1 - versionName "1.0" + versionName "0.0.1" multiDexEnabled true testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + buildConfigField "String", "GIT_SDK_REVISION", "\"${gitRevision()}\"" resValue "string", "git_sdk_revision", "\"${gitRevision()}\"" resValue "string", "git_sdk_revision_unix_date", "\"${gitRevisionUnixDate()}\"" resValue "string", "git_sdk_revision_date", "\"${gitRevisionDate()}\"" diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt index b3b98847..3844e27b 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/Matrix.kt @@ -19,6 +19,7 @@ package im.vector.matrix.android.api import android.content.Context import androidx.lifecycle.ProcessLifecycleOwner import com.zhuinden.monarchy.Monarchy +import im.vector.matrix.android.BuildConfig import im.vector.matrix.android.api.auth.Authenticator import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.sync.FilterService @@ -86,6 +87,9 @@ class Matrix private constructor(context: Context) : MatrixKoinComponent { return instance } + fun getSdkVersion(): String { + return BuildConfig.VERSION_NAME + " (" + BuildConfig.GIT_SDK_REVISION + ")" + } } } diff --git a/vector/build.gradle b/vector/build.gradle index 10953eb4..2f49297b 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -51,7 +51,7 @@ project.android.buildTypes.all { buildType -> ] } -def buildNumber = System.getenv("BUILD_NUMBER") as Integer ?: 0 +def buildNumber = System.getenv("BUILDKITE_BUILD_NUMBER") as Integer ?: 0 android { compileSdkVersion 28 @@ -63,9 +63,16 @@ android { versionCode generateVersionCodeFromTimestamp() versionName "${versionMajor}.${versionMinor}.${versionPatch}" + buildConfigField "String", "GIT_REVISION", "\"${gitRevision()}\"" resValue "string", "git_revision", "\"${gitRevision()}\"" + + buildConfigField "String", "GIT_REVISION_DATE", "\"${gitRevisionDate()}\"" resValue "string", "git_revision_date", "\"${gitRevisionDate()}\"" + + buildConfigField "String", "GIT_BRANCH_NAME", "\"${gitBranchName()}\"" resValue "string", "git_branch_name", "\"${gitBranchName()}\"" + + buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\"" resValue "string", "build_number", "\"${buildNumber}\"" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt index 3e51cdec..2f2de8ed 100644 --- a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt @@ -39,10 +39,13 @@ import im.vector.riotredesign.features.lifecycle.VectorActivityLifecycleCallback import im.vector.riotredesign.features.rageshake.VectorFileLogger import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule +import im.vector.riotredesign.features.version.getVersion import org.koin.android.ext.android.inject import org.koin.log.EmptyLogger import org.koin.standalone.StandAloneContext.startKoin import timber.log.Timber +import java.text.SimpleDateFormat +import java.util.* class VectorApplication : Application() { @@ -57,6 +60,8 @@ class VectorApplication : Application() { super.onCreate() appContext = this + logInfo() + VectorUncaughtExceptionHandler.activate(this) // Log @@ -92,6 +97,20 @@ class VectorApplication : Application() { vectorConfiguration.initConfiguration() } + private fun logInfo() { + val appVersion = getVersion(longFormat = true, useBuildNumber = true) + val sdkVersion = Matrix.getSdkVersion() + val date = SimpleDateFormat("MM-dd HH:mm:ss.SSSZ", Locale.US).format(Date()) + + Timber.v("----------------------------------------------------------------") + Timber.v("----------------------------------------------------------------") + Timber.v(" Application version: $appVersion") + Timber.v(" SDK version: $sdkVersion") + Timber.v(" Local time: $date") + Timber.v("----------------------------------------------------------------") + Timber.v("----------------------------------------------------------------\n\n\n\n") + } + override fun attachBaseContext(base: Context) { super.attachBaseContext(base) MultiDex.install(this) diff --git a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt index f755f433..4b586f42 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt @@ -34,6 +34,7 @@ import im.vector.riotredesign.core.extensions.toOnOff import im.vector.riotredesign.core.utils.getDeviceLocale import im.vector.riotredesign.features.settings.VectorLocale import im.vector.riotredesign.features.themes.ThemeUtils +import im.vector.riotredesign.features.version.getVersion import okhttp3.* import org.json.JSONException import org.json.JSONObject @@ -192,13 +193,11 @@ object BugReporter { var deviceId = "undefined" var userId = "undefined" - var matrixSdkVersion = "undefined" var olmVersion = "undefined" Matrix.getInstance().currentSession?.let { session -> userId = session.sessionParams.credentials.userId deviceId = session.sessionParams.credentials.deviceId ?: "undefined" - // TODO matrixSdkVersion = session.getVersion(true); olmVersion = session.getCryptoVersion(context, true) } @@ -210,9 +209,9 @@ object BugReporter { .addFormDataPart("user_agent", Matrix.getInstance().getUserAgent()) .addFormDataPart("user_id", userId) .addFormDataPart("device_id", deviceId) - // TODO .addFormDataPart("version", Matrix.getInstance(context).getVersion(true, false)) + .addFormDataPart("version", getVersion(longFormat = true, useBuildNumber = false)) .addFormDataPart("branch_name", context.getString(R.string.git_branch_name)) - .addFormDataPart("matrix_sdk_version", matrixSdkVersion) + .addFormDataPart("matrix_sdk_version", Matrix.getSdkVersion()) .addFormDataPart("olm_version", olmVersion) .addFormDataPart("device", Build.MODEL.trim()) .addFormDataPart("lazy_loading", true.toOnOff()) diff --git a/vector/src/main/java/im/vector/riotredesign/features/rageshake/VectorUncaughtExceptionHandler.kt b/vector/src/main/java/im/vector/riotredesign/features/rageshake/VectorUncaughtExceptionHandler.kt index 60959029..dc50e805 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/rageshake/VectorUncaughtExceptionHandler.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/rageshake/VectorUncaughtExceptionHandler.kt @@ -21,7 +21,9 @@ import android.content.Context import android.os.Build import androidx.core.content.edit import androidx.preference.PreferenceManager +import im.vector.matrix.android.api.Matrix import im.vector.riotredesign.BuildConfig +import im.vector.riotredesign.features.version.getVersion import timber.log.Timber import java.io.PrintWriter import java.io.StringWriter @@ -32,8 +34,8 @@ object VectorUncaughtExceptionHandler : Thread.UncaughtExceptionHandler { // key to save the crash status private const val PREFS_CRASH_KEY = "PREFS_CRASH_KEY" - private var vectorVersion: String = "" - private var matrixSdkVersion: String = "" + private val vectorVersion = getVersion(longFormat = true, useBuildNumber = true) + private val matrixSdkVersion = Matrix.getSdkVersion() private var previousHandler: Thread.UncaughtExceptionHandler? = null @@ -120,12 +122,6 @@ object VectorUncaughtExceptionHandler : Thread.UncaughtExceptionHandler { previousHandler?.uncaughtException(thread, throwable) } - // TODO Call me - fun setVersions(vectorVersion: String, matrixSdkVersion: String) { - this.vectorVersion = vectorVersion - this.matrixSdkVersion = matrixSdkVersion - } - /** * Tells if the application crashed * diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/PreferencesManager.java b/vector/src/main/java/im/vector/riotredesign/features/settings/PreferencesManager.java index 2da01d4a..c695d4cd 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/PreferencesManager.java +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/PreferencesManager.java @@ -40,11 +40,10 @@ import timber.log.Timber; public class PreferencesManager { - public static final String VERSION_BUILD = "VERSION_BUILD"; - public static final String SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY = "SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY_2"; public static final String SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY = "SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY"; public static final String SETTINGS_VERSION_PREFERENCE_KEY = "SETTINGS_VERSION_PREFERENCE_KEY"; + public static final String SETTINGS_SDK_VERSION_PREFERENCE_KEY = "SETTINGS_SDK_VERSION_PREFERENCE_KEY"; public static final String SETTINGS_OLM_VERSION_PREFERENCE_KEY = "SETTINGS_OLM_VERSION_PREFERENCE_KEY"; public static final String SETTINGS_LOGGED_IN_PREFERENCE_KEY = "SETTINGS_LOGGED_IN_PREFERENCE_KEY"; public static final String SETTINGS_HOME_SERVER_PREFERENCE_KEY = "SETTINGS_HOME_SERVER_PREFERENCE_KEY"; diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt index 3fad652a..e386eaa9 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsPreferencesFragment.kt @@ -43,6 +43,7 @@ import androidx.core.view.isVisible import androidx.preference.* import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputLayout +import im.vector.matrix.android.api.Matrix import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.extensions.getFingerprintHumanReadable import im.vector.matrix.android.api.extensions.sortByLastSeen @@ -72,6 +73,7 @@ import im.vector.riotredesign.features.crypto.keys.KeysExporter import im.vector.riotredesign.features.crypto.keys.KeysImporter import im.vector.riotredesign.features.crypto.keysbackup.settings.KeysBackupManageActivity import im.vector.riotredesign.features.themes.ThemeUtils +import im.vector.riotredesign.features.version.getVersion import org.koin.android.ext.android.inject import timber.log.Timber import java.lang.ref.WeakReference @@ -637,11 +639,23 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref // application version (findPreference(PreferencesManager.SETTINGS_VERSION_PREFERENCE_KEY)).let { - it.summary = "TODO" // VectorUtils.getApplicationVersion(appContext) + it.summary = getVersion(longFormat = false, useBuildNumber = true) - it.setOnPreferenceClickListener { - appContext?.let { - copyToClipboard(it, "TODO") //VectorUtils.getApplicationVersion(it)) + it.setOnPreferenceClickListener { pref -> + appContext?.let { ctx -> + copyToClipboard(ctx, pref.summary) + } + true + } + } + + // SDK version + (findPreference(PreferencesManager.SETTINGS_SDK_VERSION_PREFERENCE_KEY)).let { + it.summary = Matrix.getSdkVersion() + + it.setOnPreferenceClickListener { pref -> + appContext?.let { ctx -> + copyToClipboard(ctx, pref.summary) } true } @@ -1456,7 +1470,6 @@ class VectorSettingsPreferencesFragment : VectorPreferenceFragment(), SharedPref private fun refreshPreferences() { PreferenceManager.getDefaultSharedPreferences(activity).edit { putString(PreferencesManager.SETTINGS_DISPLAY_NAME_PREFERENCE_KEY, "TODO") //session.myUser.displayname) - putString(PreferencesManager.SETTINGS_VERSION_PREFERENCE_KEY, "TODO") // VectorUtils.getApplicationVersion(activity)) /* TODO session.dataHandler.pushRules()?.let { diff --git a/vector/src/main/java/im/vector/riotredesign/features/version/Version.kt b/vector/src/main/java/im/vector/riotredesign/features/version/Version.kt new file mode 100644 index 00000000..826fe156 --- /dev/null +++ b/vector/src/main/java/im/vector/riotredesign/features/version/Version.kt @@ -0,0 +1,49 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotredesign.features.version + +import im.vector.riotredesign.BuildConfig + +fun getVersion(longFormat: Boolean, useBuildNumber: Boolean): String { + var result = BuildConfig.VERSION_NAME + + var flavor = BuildConfig.SHORT_FLAVOR_DESCRIPTION + + if (flavor.isNotBlank()) { + flavor += "-" + } + + var gitVersion = BuildConfig.GIT_REVISION + val gitRevisionDate = BuildConfig.GIT_REVISION_DATE + val buildNumber = BuildConfig.BUILD_NUMBER + + var useLongFormat = longFormat + + if (useBuildNumber && buildNumber != "0") { + // It's a build from CI + gitVersion = "b$buildNumber" + useLongFormat = false + } + + result += if (useLongFormat) { + " ($flavor$gitVersion-$gitRevisionDate)" + } else { + " ($flavor$gitVersion)" + } + + return result +} \ No newline at end of file diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index 1b57207d..3293c4cf 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -6,4 +6,6 @@ "Import e2e keys from file \"%1$s\"." + Matrix SDK Version + \ No newline at end of file diff --git a/vector/src/main/res/xml/vector_settings_preferences.xml b/vector/src/main/res/xml/vector_settings_preferences.xml index 0eb55c2a..e891b121 100755 --- a/vector/src/main/res/xml/vector_settings_preferences.xml +++ b/vector/src/main/res/xml/vector_settings_preferences.xml @@ -454,10 +454,15 @@ android:title="@string/settings_version" tools:summary="1.2.3" /> + + + tools:summary="7.8.9" />