From 290be635b9b87d167fb2116666d6223ba70c475f Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Tue, 30 Mar 2021 19:18:27 +0300 Subject: [PATCH] Modified using LeakCanary. Allowed only for 'dev' flavor.| #1114 --- FlowCrypt/build.gradle | 6 +++++- .../main/java/com/flowcrypt/email/Constants.kt | 1 - .../com/flowcrypt/email/FlowCryptApplication.kt | 15 --------------- .../preferences/MainDevPreferencesFragment.kt | 1 - .../src/main/res/values/strings_dev_settings.xml | 4 ---- FlowCrypt/src/main/res/xml/dev_preferences.xml | 7 ------- ext.gradle | 2 +- 7 files changed, 6 insertions(+), 30 deletions(-) diff --git a/FlowCrypt/build.gradle b/FlowCrypt/build.gradle index aee07e7e16..888f6b3446 100644 --- a/FlowCrypt/build.gradle +++ b/FlowCrypt/build.gradle @@ -302,6 +302,10 @@ android { ndkVersion "22.0.7026061" } +configurations { + devDebugImplementation {} +} + easylauncher { buildTypes { debug { @@ -325,7 +329,7 @@ dependencies { kapt 'androidx.annotation:annotation:1.2.0' kapt "androidx.room:room-compiler:$roomVersion" - debugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.ext.leakcanaryVersion}" + devDebugImplementation "com.squareup.leakcanary:leakcanary-android:${rootProject.ext.leakcanaryVersion}" androidTestImplementation "androidx.test.espresso:espresso-core:${rootProject.ext.espressoVersion}" androidTestImplementation "androidx.test.espresso:espresso-contrib:${rootProject.ext.espressoVersion}" diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt index a095700449..b4d7313882 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/Constants.kt @@ -45,7 +45,6 @@ class Constants { * The preference keys. */ const val PREF_KEY_IS_WRITE_LOGS_TO_FILE_ENABLED = "preferences_key_is_write_logs_to_file_enabled" - const val PREF_KEY_IS_DETECT_MEMORY_LEAK_ENABLED = "pref_key_is_detect_memory_leak_enabled" const val PREF_KEY_IS_ACRA_ENABLED = "pref_key_is_acra_enabled" const val PREF_KEY_IS_MAIL_DEBUG_ENABLED = "preferences_key_is_mail_debug_enabled" const val PREF_KEY_IS_HTTP_LOG_ENABLED = "pref_key_is_http_log_enabled" diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/FlowCryptApplication.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/FlowCryptApplication.kt index f8cd7d7891..f9a69792ce 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/FlowCryptApplication.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/FlowCryptApplication.kt @@ -24,7 +24,6 @@ import com.flowcrypt.email.util.CacheManager import com.flowcrypt.email.util.GeneralUtil import com.flowcrypt.email.util.SharedPreferencesHelper import com.flowcrypt.email.util.acra.CustomReportSenderFactory -import leakcanary.LeakCanary import org.acra.ACRA import org.acra.ReportField import org.acra.annotation.ReportsCrashes @@ -79,7 +78,6 @@ class FlowCryptApplication : Application(), Configuration.Provider { MsgsCacheManager.init(this) NotificationChannelManager.registerNotificationChannels(this) IMAPStoreManager.init(this) - initLeakCanary() SyncInboxWorker.enqueuePeriodic(this) enqueueMsgsCacheCleanerWorker() } @@ -112,19 +110,6 @@ class FlowCryptApplication : Application(), Configuration.Provider { Constants.PREF_KEY_INSTALL_VERSION.toUpperCase(Locale.getDefault()), installVersion) } - /** - * Init the LeakCanary tools if the current build is debug and detect memory leaks enabled. - */ - private fun initLeakCanary() { - if (GeneralUtil.isDebugBuild()) { - val isEnabled = SharedPreferencesHelper.getBoolean( - PreferenceManager.getDefaultSharedPreferences(this), - Constants.PREF_KEY_IS_DETECT_MEMORY_LEAK_ENABLED, false) - LeakCanary.config = LeakCanary.config.copy(dumpHeap = isEnabled) - LeakCanary.showLeakDisplayActivityLauncherIcon(showLauncherIcon = isEnabled) - } - } - private fun initPerInstallationSharedPrefs() { val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this) if (sharedPreferences.all.isEmpty()) { diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/MainDevPreferencesFragment.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/MainDevPreferencesFragment.kt index 901a260ae2..70f3e5a797 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/MainDevPreferencesFragment.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/ui/activity/fragment/preferences/MainDevPreferencesFragment.kt @@ -60,7 +60,6 @@ class MainDevPreferencesFragment : BaseDevPreferencesFragment(), SharedPreferenc override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { when (key) { Constants.PREF_KEY_IS_WRITE_LOGS_TO_FILE_ENABLED, - Constants.PREF_KEY_IS_DETECT_MEMORY_LEAK_ENABLED, Constants.PREF_KEY_IS_ACRA_ENABLED, Constants.PREF_KEY_IS_NODE_HTTP_DEBUG_ENABLED, Constants.PREF_KEY_NODE_HTTP_LOG_LEVEL, diff --git a/FlowCrypt/src/main/res/values/strings_dev_settings.xml b/FlowCrypt/src/main/res/values/strings_dev_settings.xml index ee1b8e8483..3fd698c82c 100644 --- a/FlowCrypt/src/main/res/values/strings_dev_settings.xml +++ b/FlowCrypt/src/main/res/values/strings_dev_settings.xml @@ -8,7 +8,6 @@ pref_key_build_config_info preferences_key_is_write_logs_to_file_enabled - preferences_key_is_detect_memory_leak_enable preferences_key_is_acra_enable preferences_key_is_mail_debug_enabled pref_key_is_http_log_enabled @@ -16,7 +15,6 @@ pref_key_is_node_http_debug_enabled pref_key_node_http_log_level pref_key_is_native_node_debug_enabled - pref_key_is_detect_memory_leak_enabled pref_key_is_acra_enabled @@ -25,7 +23,6 @@ Build config info Please press "Force stop" to apply changes Write API logs to a file - Enable detect memory leak Enable ACRA(App Crash Reports) IMAP debug Dev Settings @@ -38,6 +35,5 @@ Disabled Node HTTP Native Node logs - Detect memory leaks Application Crash Reports diff --git a/FlowCrypt/src/main/res/xml/dev_preferences.xml b/FlowCrypt/src/main/res/xml/dev_preferences.xml index 6f12998523..f61d6f5577 100644 --- a/FlowCrypt/src/main/res/xml/dev_preferences.xml +++ b/FlowCrypt/src/main/res/xml/dev_preferences.xml @@ -20,13 +20,6 @@ android:summaryOff="@string/pref_summary_disabled" android:summaryOn="@string/pref_summary_enabled" android:title="@string/pref_title_acra" /> - - diff --git a/ext.gradle b/ext.gradle index 9ff134852f..5e219a3e61 100644 --- a/ext.gradle +++ b/ext.gradle @@ -34,7 +34,7 @@ ext { /*https://mvnrepository.com/artifact/com.squareup.okio/okio*/ okioVersion = '2.10.0' /*https://mvnrepository.com/artifact/com.squareup.leakcanary/leakcanary-android*/ - leakcanaryVersion = '2.6' + leakcanaryVersion = '2.7' /*https://mvnrepository.com/artifact/com.sun.mail/android-mail*/ javaMailVersion = '1.6.6' /*https://mvnrepository.com/artifact/com.github.bumptech.glide/glide*/