Work around voice message crashes on Android 5

- Catch NPE in onVisibilityChanged (happens for SDK 21 and 22)
- Do not allow voice messages on SDK 21: segfaults as soon as recording
  stops

Change-Id: I0cfc55fbb7880dc29e29df4fba14d57af1f82bba
This commit is contained in:
SpiritCroc 2021-08-19 11:52:11 +02:00
parent cad30d4790
commit 1af014a527
3 changed files with 16 additions and 6 deletions

View File

@ -90,10 +90,15 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
override fun onVisibilityChanged(changedView: View, visibility: Int) { override fun onVisibilityChanged(changedView: View, visibility: Int) {
super.onVisibilityChanged(changedView, visibility) super.onVisibilityChanged(changedView, visibility)
if (changedView == this && visibility == VISIBLE) { // On Android 5, this can cause a NPE for some unknown reason
views.voiceMessageMicButton.contentDescription = context.getString(R.string.a11y_start_voice_message) try {
} else { if (changedView == this && visibility == VISIBLE) {
views.voiceMessageMicButton.contentDescription = "" views.voiceMessageMicButton.contentDescription = context.getString(R.string.a11y_start_voice_message)
} else {
views.voiceMessageMicButton.contentDescription = ""
}
} catch (e: Exception) {
e.printStackTrace()
} }
} }

View File

@ -19,6 +19,7 @@ import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.media.RingtoneManager import android.media.RingtoneManager
import android.net.Uri import android.net.Uri
import android.os.Build
import android.provider.MediaStore import android.provider.MediaStore
import androidx.core.content.edit import androidx.core.content.edit
import com.squareup.seismic.ShakeDetector import com.squareup.seismic.ShakeDetector
@ -202,7 +203,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val SETTINGS_USER_COLOR_MODE_DEFAULT = "SETTINGS_USER_COLOR_MODE_DEFAULT" private const val SETTINGS_USER_COLOR_MODE_DEFAULT = "SETTINGS_USER_COLOR_MODE_DEFAULT"
private const val SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM = "SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM" private const val SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM = "SETTINGS_USER_COLOR_MODE_PUBLIC_ROOM"
private const val SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD = "SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD" private const val SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD = "SETTINGS_OPEN_CHATS_AT_FIRST_UNREAD"
private const val SETTINGS_VOICE_MESSAGE = "SETTINGS_VOICE_MESSAGE" const val SETTINGS_VOICE_MESSAGE = "SETTINGS_VOICE_MESSAGE"
private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH" private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH"
@ -1004,7 +1005,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
// Element removed this, SC added it back (but this time, default to true) // Element removed this, SC added it back (but this time, default to true)
fun useVoiceMessage(): Boolean { fun useVoiceMessage(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_VOICE_MESSAGE, true) // Voice messages crash on SDK 21
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP && defaultPrefs.getBoolean(SETTINGS_VOICE_MESSAGE, true)
} }
/** /**

View File

@ -16,6 +16,7 @@
package im.vector.app.features.settings package im.vector.app.features.settings
import android.os.Build
import androidx.preference.Preference import androidx.preference.Preference
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.preference.VectorSwitchPreference import im.vector.app.core.preference.VectorSwitchPreference
@ -56,6 +57,8 @@ class VectorSettingsLabsFragment @Inject constructor(
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_ALLOW_URL_PREVIEW_IN_ENCRYPTED_ROOM_KEY)?.isEnabled = vectorPreferences.showUrlPreviews() findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_ALLOW_URL_PREVIEW_IN_ENCRYPTED_ROOM_KEY)?.isEnabled = vectorPreferences.showUrlPreviews()
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_VOICE_MESSAGE)?.isEnabled = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_SPACES_HOME_AS_ORPHAN)!!.let { pref -> findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_SPACES_HOME_AS_ORPHAN)!!.let { pref ->
pref.setOnPreferenceChangeListener { _, _ -> pref.setOnPreferenceChangeListener { _, _ ->
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = false)) MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = false))