From b10e9c54b44cc411e65ad681274b57040dc092cd Mon Sep 17 00:00:00 2001
From: Benoit Marty <benoitm@matrix.org>
Date: Thu, 5 Mar 2020 10:40:36 +0100
Subject: [PATCH] Add BinaryOperationInTimber lint rule and fix existing errors

---
 vector/lint.xml                                        |  3 +++
 .../riotx/core/utils/ExternalApplicationsUtil.kt       | 10 +++++-----
 .../features/configuration/VectorConfiguration.kt      |  4 ++--
 .../KeysBackupRestoreFromPassphraseViewModel.kt        |  2 +-
 .../riotx/features/login/LoginCaptchaFragment.kt       |  2 +-
 .../rageshake/VectorUncaughtExceptionHandler.kt        |  2 +-
 .../riotx/features/settings/VectorPreferences.kt       |  2 +-
 7 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/vector/lint.xml b/vector/lint.xml
index 3d3bb1856f..f93527856f 100644
--- a/vector/lint.xml
+++ b/vector/lint.xml
@@ -46,4 +46,7 @@
 
     <!-- Manifest -->
     <issue id="PermissionImpliesUnsupportedChromeOsHardware" severity="error" />
+
+    <!-- Timber -->
+    <issue id="BinaryOperationInTimber" severity="error" />
 </lint>
diff --git a/vector/src/main/java/im/vector/riotx/core/utils/ExternalApplicationsUtil.kt b/vector/src/main/java/im/vector/riotx/core/utils/ExternalApplicationsUtil.kt
index 78242d58de..37f6df1379 100644
--- a/vector/src/main/java/im/vector/riotx/core/utils/ExternalApplicationsUtil.kt
+++ b/vector/src/main/java/im/vector/riotx/core/utils/ExternalApplicationsUtil.kt
@@ -144,10 +144,10 @@ fun openCamera(activity: Activity, titlePrefix: String, requestCode: Int): Strin
             Timber.e("Cannot use the external storage media to save image")
         }
     } catch (uoe: UnsupportedOperationException) {
-        Timber.e(uoe, "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI " +
-                "no SD card? Attempting to insert into device storage.")
+        Timber.e(uoe, "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI.")
+        Timber.e("no SD card? Attempting to insert into device storage.")
     } catch (e: Exception) {
-        Timber.e(e, "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI. $e")
+        Timber.e(e, "Unable to insert camera URI into MediaStore.Images.Media.EXTERNAL_CONTENT_URI.")
     }
 
     if (null == dummyUri) {
@@ -157,13 +157,13 @@ fun openCamera(activity: Activity, titlePrefix: String, requestCode: Int): Strin
                 Timber.e("Cannot use the internal storage to save media to save image")
             }
         } catch (e: Exception) {
-            Timber.e(e, "Unable to insert camera URI into internal storage. Giving up. $e")
+            Timber.e(e, "Unable to insert camera URI into internal storage. Giving up.")
         }
     }
 
     if (dummyUri != null) {
         captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, dummyUri)
-        Timber.v("trying to take a photo on " + dummyUri.toString())
+        Timber.v("trying to take a photo on $dummyUri")
     } else {
         Timber.v("trying to take a photo with no predefined uri")
     }
diff --git a/vector/src/main/java/im/vector/riotx/features/configuration/VectorConfiguration.kt b/vector/src/main/java/im/vector/riotx/features/configuration/VectorConfiguration.kt
index adf8421842..a4b7ca263d 100644
--- a/vector/src/main/java/im/vector/riotx/features/configuration/VectorConfiguration.kt
+++ b/vector/src/main/java/im/vector/riotx/features/configuration/VectorConfiguration.kt
@@ -36,8 +36,8 @@ class VectorConfiguration @Inject constructor(private val context: Context) {
     // TODO Import mLanguageReceiver From Riot?
     fun onConfigurationChanged() {
         if (Locale.getDefault().toString() != VectorLocale.applicationLocale.toString()) {
-            Timber.v("## onConfigurationChanged() : the locale has been updated to " + Locale.getDefault().toString()
-                     + ", restore the expected value " + VectorLocale.applicationLocale.toString())
+            Timber.v("## onConfigurationChanged(): the locale has been updated to ${Locale.getDefault()}")
+            Timber.v("## onConfigurationChanged(): restore the expected value ${VectorLocale.applicationLocale}")
             updateApplicationSettings(VectorLocale.applicationLocale,
                                       FontScale.getFontScalePrefValue(context),
                                       ThemeUtils.getApplicationTheme(context))
diff --git a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt
index c6ffd730ca..69c5e70740 100644
--- a/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt
+++ b/vector/src/main/java/im/vector/riotx/features/crypto/keysbackup/restore/KeysBackupRestoreFromPassphraseViewModel.kt
@@ -74,7 +74,7 @@ class KeysBackupRestoreFromPassphraseViewModel @Inject constructor() : ViewModel
                                         isIndeterminate = true))
                             }
                             is StepProgressListener.Step.ImportingKey -> {
-                                Timber.d("backupKeys.ImportingKey.progress: " + step.progress)
+                                Timber.d("backupKeys.ImportingKey.progress: ${step.progress}")
                                 // Progress 0 can take a while, display an indeterminate progress in this case
                                 if (step.progress == 0) {
                                     sharedViewModel.loadingEvent.postValue(WaitingViewData(context.getString(R.string.keys_backup_restoring_waiting_message)
diff --git a/vector/src/main/java/im/vector/riotx/features/login/LoginCaptchaFragment.kt b/vector/src/main/java/im/vector/riotx/features/login/LoginCaptchaFragment.kt
index b11cd57329..9bd709d1bd 100644
--- a/vector/src/main/java/im/vector/riotx/features/login/LoginCaptchaFragment.kt
+++ b/vector/src/main/java/im/vector/riotx/features/login/LoginCaptchaFragment.kt
@@ -89,7 +89,7 @@ class LoginCaptchaFragment @Inject constructor(
             }
 
             override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) {
-                Timber.d("## onReceivedSslError() : " + error.certificate)
+                Timber.d("## onReceivedSslError() : ${error.certificate}")
 
                 if (!isAdded) {
                     return
diff --git a/vector/src/main/java/im/vector/riotx/features/rageshake/VectorUncaughtExceptionHandler.kt b/vector/src/main/java/im/vector/riotx/features/rageshake/VectorUncaughtExceptionHandler.kt
index 0b5c3d2d26..e93a113439 100644
--- a/vector/src/main/java/im/vector/riotx/features/rageshake/VectorUncaughtExceptionHandler.kt
+++ b/vector/src/main/java/im/vector/riotx/features/rageshake/VectorUncaughtExceptionHandler.kt
@@ -99,9 +99,9 @@ class VectorUncaughtExceptionHandler @Inject constructor(private val bugReporter
         val pw = PrintWriter(sw, true)
         throwable.printStackTrace(pw)
         b.append(sw.buffer.toString())
-        Timber.e("FATAL EXCEPTION " + b.toString())
 
         val bugDescription = b.toString()
+        Timber.e("FATAL EXCEPTION $bugDescription")
 
         bugReporter.saveCrashReport(context, bugDescription)
 
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 816b5b3fee..28f78743e4 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
@@ -423,7 +423,7 @@ class VectorPreferences @Inject constructor(private val context: Context) {
             uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
         }
 
-        Timber.v("## getNotificationRingTone() returns " + uri!!)
+        Timber.v("## getNotificationRingTone() returns $uri")
         return uri
     }