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:
parent
cad30d4790
commit
1af014a527
|
@ -90,11 +90,16 @@ class VoiceMessageRecorderView @JvmOverloads constructor(
|
|||
|
||||
override fun onVisibilityChanged(changedView: View, visibility: Int) {
|
||||
super.onVisibilityChanged(changedView, visibility)
|
||||
// On Android 5, this can cause a NPE for some unknown reason
|
||||
try {
|
||||
if (changedView == this && visibility == VISIBLE) {
|
||||
views.voiceMessageMicButton.contentDescription = context.getString(R.string.a11y_start_voice_message)
|
||||
} else {
|
||||
views.voiceMessageMicButton.contentDescription = ""
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
fun initVoiceRecordingViews() {
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.content.Context
|
|||
import android.content.SharedPreferences
|
||||
import android.media.RingtoneManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.MediaStore
|
||||
import androidx.core.content.edit
|
||||
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_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_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"
|
||||
|
||||
|
@ -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)
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package im.vector.app.features.settings
|
||||
|
||||
import android.os.Build
|
||||
import androidx.preference.Preference
|
||||
import im.vector.app.R
|
||||
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_VOICE_MESSAGE)?.isEnabled = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
|
||||
|
||||
findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_LABS_SPACES_HOME_AS_ORPHAN)!!.let { pref ->
|
||||
pref.setOnPreferenceChangeListener { _, _ ->
|
||||
MainActivity.restartApp(requireActivity(), MainActivityArgs(clearCache = false))
|
||||
|
|
Loading…
Reference in New Issue