From ff548d2f981e6c4ac184a44f781caba63baf8572 Mon Sep 17 00:00:00 2001 From: Yoan Pintas Date: Wed, 13 Sep 2023 10:43:03 +0000 Subject: [PATCH] Fix crash when max shortcuts count is exceeded (#8644) --- .github/workflows/build.yml | 2 +- .github/workflows/nightly.yml | 2 +- .github/workflows/nightly_er.yml | 2 +- changelog.d/8644.bugfix | 1 + .../app/features/home/ShortcutsHandler.kt | 24 +++++++++---------- .../VectorUncaughtExceptionHandler.kt | 8 ++++--- 6 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 changelog.d/8644.bugfix diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b135aa5c9e4..80e09ffdeb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ on: # Enrich gradle.properties for CI/CD env: - GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false + GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -XX:MaxMetaspaceSize=1g" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 2 --no-daemon jobs: diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 1e05533da17..93d63af5d30 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -7,7 +7,7 @@ on: - cron: "0 4 * * *" env: - GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false + GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -XX:MaxMetaspaceSize=1g" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 2 --no-daemon jobs: diff --git a/.github/workflows/nightly_er.yml b/.github/workflows/nightly_er.yml index e9981ad06a5..7efa900b062 100644 --- a/.github/workflows/nightly_er.yml +++ b/.github/workflows/nightly_er.yml @@ -6,7 +6,7 @@ on: - cron: "0 4 * * *" env: - GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false + GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx3072m -Dfile.encoding=UTF-8 -XX:+HeapDumpOnOutOfMemoryError -XX:MaxMetaspaceSize=1g" -Dkotlin.daemon.jvm.options="-Xmx2560m" -Dkotlin.incremental=false CI_GRADLE_ARG_PROPERTIES: --stacktrace -PpreDexEnable=false --max-workers 2 --no-daemon jobs: diff --git a/changelog.d/8644.bugfix b/changelog.d/8644.bugfix new file mode 100644 index 00000000000..c9898370cb4 --- /dev/null +++ b/changelog.d/8644.bugfix @@ -0,0 +1 @@ +Fix crash when max shortcuts count is exceeded \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt b/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt index 3a72907467d..d83c65ad5e0 100644 --- a/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt +++ b/vector/src/main/java/im/vector/app/features/home/ShortcutsHandler.kt @@ -139,19 +139,19 @@ class ShortcutsHandler @Inject constructor( } private fun createShortcuts(rooms: List) { - if (hasPinCode.get()) { - // No shortcut in this case (privacy) - ShortcutManagerCompat.removeAllDynamicShortcuts(context) - } else { - val shortcuts = rooms - .take(maxShortcutCountPerActivity) - .mapIndexed { index, room -> - shortcutCreator.create(room, index) - } + ShortcutManagerCompat.removeAllDynamicShortcuts(context) - shortcuts.forEach { shortcut -> - ShortcutManagerCompat.pushDynamicShortcut(context, shortcut) - } + // No shortcut in this case (privacy) + if (hasPinCode.get()) return + + val shortcuts = rooms + .take(maxShortcutCountPerActivity) + .mapIndexed { index, room -> + shortcutCreator.create(room, index) + } + + shortcuts.forEach { shortcut -> + ShortcutManagerCompat.pushDynamicShortcut(context, shortcut) } } diff --git a/vector/src/main/java/im/vector/app/features/rageshake/VectorUncaughtExceptionHandler.kt b/vector/src/main/java/im/vector/app/features/rageshake/VectorUncaughtExceptionHandler.kt index d3174631e8e..6d6ecd9edc6 100644 --- a/vector/src/main/java/im/vector/app/features/rageshake/VectorUncaughtExceptionHandler.kt +++ b/vector/src/main/java/im/vector/app/features/rageshake/VectorUncaughtExceptionHandler.kt @@ -20,6 +20,7 @@ import android.content.SharedPreferences import android.os.Build import androidx.core.content.edit import im.vector.app.core.di.DefaultPreferences +import im.vector.app.core.resources.AppNameProvider import im.vector.app.core.resources.VersionCodeProvider import im.vector.app.features.version.VersionProvider import org.matrix.android.sdk.api.Matrix @@ -36,6 +37,7 @@ class VectorUncaughtExceptionHandler @Inject constructor( private val bugReporter: BugReporter, private val versionProvider: VersionProvider, private val versionCodeProvider: VersionCodeProvider, + private val appNameProvider: AppNameProvider, ) : Thread.UncaughtExceptionHandler { // key to save the crash status @@ -67,12 +69,12 @@ class VectorUncaughtExceptionHandler @Inject constructor( putBoolean(PREFS_CRASH_KEY, true) } val b = StringBuilder() - val appName = "Element" // TODO Matrix.getApplicationName() + val appName = appNameProvider.getAppName() - b.append(appName + " Build : " + versionCodeProvider.getVersionCode() + "\n") + b.append("$appName Build : ${versionCodeProvider.getVersionCode()}\n") b.append("$appName Version : ${versionProvider.getVersion(longFormat = true)}\n") b.append("SDK Version : ${Matrix.getSdkVersion()}\n") - b.append("Phone : " + Build.MODEL.trim() + " (" + Build.VERSION.INCREMENTAL + " " + Build.VERSION.RELEASE + " " + Build.VERSION.CODENAME + ")\n") + b.append("Phone : ${Build.MODEL.trim()} (${Build.VERSION.INCREMENTAL} ${Build.VERSION.RELEASE} ${Build.VERSION.CODENAME})\n") b.append("Memory statuses \n")