Display some version of Riot and SDK (Fix #185)

This commit is contained in:
Benoit Marty 2019-06-21 11:13:16 +02:00
parent 1eb374fa49
commit 1cfc85a772
11 changed files with 116 additions and 22 deletions

View File

@ -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()}\""

View File

@ -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 + ")"
}
}

}

View File

@ -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"

View File

@ -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)

View File

@ -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())

View File

@ -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
*

View File

@ -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";

View File

@ -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 {

View File

@ -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
}

View File

@ -6,4 +6,6 @@

<string name="import_e2e_keys_from_file">"Import e2e keys from file \"%1$s\"."</string>

<string name="settings_sdk_version">Matrix SDK Version</string>

</resources>

View File

@ -454,10 +454,15 @@
android:title="@string/settings_version"
tools:summary="1.2.3" />

<im.vector.riotredesign.core.preference.VectorPreference
android:key="SETTINGS_SDK_VERSION_PREFERENCE_KEY"
android:title="@string/settings_sdk_version"
tools:summary="4.5.6" />

<im.vector.riotredesign.core.preference.VectorPreference
android:key="SETTINGS_OLM_VERSION_PREFERENCE_KEY"
android:title="@string/settings_olm_version"
tools:summary="1.2.3" />
tools:summary="7.8.9" />

<im.vector.riotredesign.core.preference.VectorPreference
android:key="SETTINGS_COPYRIGHT_PREFERENCE_KEY"