From de84bb7535a451bfcde2186fe3987f41c3c22d0f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 10 Jan 2020 10:17:53 +0100 Subject: [PATCH] Use more developerMode() --- vector/src/main/java/im/vector/riotx/core/error/fatal.kt | 5 ++--- vector/src/main/java/im/vector/riotx/core/rx/RxConfig.kt | 5 ++--- .../riotx/features/home/room/detail/RoomDetailViewModel.kt | 3 +-- .../im/vector/riotx/features/navigation/DefaultNavigator.kt | 6 ++++-- .../im/vector/riotx/features/settings/VectorPreferences.kt | 3 ++- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/core/error/fatal.kt b/vector/src/main/java/im/vector/riotx/core/error/fatal.kt index 800e1ea7ad..ad6a99928a 100644 --- a/vector/src/main/java/im/vector/riotx/core/error/fatal.kt +++ b/vector/src/main/java/im/vector/riotx/core/error/fatal.kt @@ -16,14 +16,13 @@ package im.vector.riotx.core.error -import im.vector.riotx.BuildConfig import timber.log.Timber /** * throw in debug, only log in production. As this method does not always throw, next statement should be a return */ -fun fatalError(message: String) { - if (BuildConfig.DEBUG) { +fun fatalError(message: String, failFast: Boolean) { + if (failFast) { error(message) } else { Timber.e(message) diff --git a/vector/src/main/java/im/vector/riotx/core/rx/RxConfig.kt b/vector/src/main/java/im/vector/riotx/core/rx/RxConfig.kt index d8828eb1b8..bd87251a58 100644 --- a/vector/src/main/java/im/vector/riotx/core/rx/RxConfig.kt +++ b/vector/src/main/java/im/vector/riotx/core/rx/RxConfig.kt @@ -16,7 +16,6 @@ package im.vector.riotx.core.rx -import im.vector.riotx.BuildConfig import im.vector.riotx.features.settings.VectorPreferences import io.reactivex.plugins.RxJavaPlugins import timber.log.Timber @@ -33,8 +32,8 @@ class RxConfig @Inject constructor( RxJavaPlugins.setErrorHandler { throwable -> Timber.e(throwable, "RxError") - // Avoid crash in production - if (BuildConfig.DEBUG || vectorPreferences.failFast()) { + // Avoid crash in production, except if user wants it + if (vectorPreferences.failFast()) { throw throwable } } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index c93358a04e..cd8032481d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -55,7 +55,6 @@ import im.vector.matrix.android.internal.crypto.attachments.toElementToDecrypt import im.vector.matrix.android.internal.crypto.model.event.EncryptedEventContent import im.vector.matrix.rx.rx import im.vector.matrix.rx.unwrap -import im.vector.riotx.BuildConfig import im.vector.riotx.R import im.vector.riotx.core.extensions.postLiveEvent import im.vector.riotx.core.platform.VectorViewModel @@ -308,7 +307,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro fun isMenuItemVisible(@IdRes itemId: Int) = when (itemId) { R.id.clear_message_queue -> /* For now always disable on production, worker cancellation is not working properly */ - timeline.pendingEventCount() > 0 && BuildConfig.DEBUG + timeline.pendingEventCount() > 0 && vectorPreferences.developerMode() R.id.resend_all -> timeline.failedToDeliverEventCount() > 0 R.id.clear_all -> timeline.failedToDeliverEventCount() > 0 else -> false diff --git a/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt index 48422056b4..8784ec662d 100644 --- a/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/riotx/features/navigation/DefaultNavigator.kt @@ -36,6 +36,7 @@ import im.vector.riotx.features.home.room.filtered.FilteredRoomsActivity import im.vector.riotx.features.roomdirectory.RoomDirectoryActivity import im.vector.riotx.features.roomdirectory.createroom.CreateRoomActivity import im.vector.riotx.features.roomdirectory.roompreview.RoomPreviewActivity +import im.vector.riotx.features.settings.VectorPreferences import im.vector.riotx.features.settings.VectorSettingsActivity import im.vector.riotx.features.share.SharedData import timber.log.Timber @@ -44,12 +45,13 @@ import javax.inject.Singleton @Singleton class DefaultNavigator @Inject constructor( - private val sessionHolder: ActiveSessionHolder + private val sessionHolder: ActiveSessionHolder, + private val vectorPreferences: VectorPreferences ) : Navigator { override fun openRoom(context: Context, roomId: String, eventId: String?, buildTask: Boolean) { if (sessionHolder.getSafeActiveSession()?.getRoom(roomId) == null) { - fatalError("Trying to open an unknown room $roomId") + fatalError("Trying to open an unknown room $roomId", vectorPreferences.failFast()) return } diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt index 72f8cf01dd..c734558c0e 100755 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorPreferences.kt @@ -24,6 +24,7 @@ import android.provider.MediaStore import androidx.core.content.edit import androidx.preference.PreferenceManager import com.squareup.seismic.ShakeDetector +import im.vector.riotx.BuildConfig import im.vector.riotx.R import im.vector.riotx.features.homeserver.ServerUrlsRepository import im.vector.riotx.features.themes.ThemeUtils @@ -268,7 +269,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { } fun failFast(): Boolean { - return developerMode() && defaultPrefs.getBoolean(SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY, false) + return BuildConfig.DEBUG || (developerMode() && defaultPrefs.getBoolean(SETTINGS_DEVELOPER_MODE_FAIL_FAST_PREFERENCE_KEY, false)) } /**