1
0
Fork 0

Closes #2441. Update LeakCanary to `2.0-beta-3` version.

master
Denys M 2019-09-27 11:16:32 +04:00 committed by Emily Kager
parent 7ab534705a
commit 6290c0c826
5 changed files with 66 additions and 48 deletions

View File

@ -404,7 +404,6 @@ dependencies {
implementation Deps.mozilla_lib_crash implementation Deps.mozilla_lib_crash
implementation Deps.mozilla_lib_push_firebase implementation Deps.mozilla_lib_push_firebase
debugImplementation Deps.leakcanary debugImplementation Deps.leakcanary
releaseImplementation Deps.leakcanary_noop
implementation Deps.androidx_legacy implementation Deps.androidx_legacy
implementation Deps.androidx_paging implementation Deps.androidx_paging

View File

@ -4,40 +4,22 @@
package org.mozilla.fenix package org.mozilla.fenix
import android.content.Context
import android.content.SharedPreferences
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import com.squareup.leakcanary.AndroidHeapDumper import leakcanary.AppWatcher
import com.squareup.leakcanary.HeapDumper import leakcanary.LeakCanary
import com.squareup.leakcanary.LeakCanary
import com.squareup.leakcanary.internal.LeakCanaryInternals
import org.mozilla.fenix.R.string.pref_key_leakcanary
import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.getPreferenceKey
import java.io.File
class DebugFenixApplication : FenixApplication() { class DebugFenixApplication : FenixApplication() {
private var heapDumper: ToggleableHeapDumper? = null
override fun setupLeakCanary() { override fun setupLeakCanary() {
val leakDirectoryProvider = LeakCanaryInternals.getLeakDirectoryProvider(this) val isEnabled = PreferenceManager.getDefaultSharedPreferences(this)
val defaultDumper = AndroidHeapDumper(this, leakDirectoryProvider) .getBoolean(getPreferenceKey(R.string.pref_key_leakcanary), false)
heapDumper = ToggleableHeapDumper(this, defaultDumper)
LeakCanary.refWatcher(this) updateLeakCanaryState(isEnabled)
.heapDumper(heapDumper)
.buildAndInstall()
} }
override fun toggleLeakCanary(newValue: Boolean) { override fun updateLeakCanaryState(isEnabled: Boolean) {
heapDumper?.enabled = newValue AppWatcher.config = AppWatcher.config.copy(enabled = isEnabled)
} LeakCanary.config = LeakCanary.config.copy(dumpHeap = isEnabled)
internal class ToggleableHeapDumper(
context: Context,
private val defaultDumper: HeapDumper
) : HeapDumper {
var prefs: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
var enabled = prefs.getBoolean(context.getPreferenceKey(pref_key_leakcanary), false)
override fun dumpHeap(): File? = if (enabled) defaultDumper.dumpHeap() else HeapDumper.RETRY_LATER
} }
} }

View File

@ -137,7 +137,7 @@ open class FenixApplication : Application() {
// no-op, LeakCanary is disabled by default // no-op, LeakCanary is disabled by default
} }
open fun toggleLeakCanary(newValue: Boolean) { open fun updateLeakCanaryState(isEnabled: Boolean) {
// no-op, LeakCanary is disabled by default // no-op, LeakCanary is disabled by default
} }

View File

@ -26,7 +26,6 @@ import mozilla.components.concept.sync.Profile
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.Config import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.FenixApplication
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.R.string.pref_key_about import org.mozilla.fenix.R.string.pref_key_about
@ -54,6 +53,7 @@ import org.mozilla.fenix.R.string.pref_key_tracking_protection_settings
import org.mozilla.fenix.R.string.pref_key_your_rights import org.mozilla.fenix.R.string.pref_key_your_rights
import org.mozilla.fenix.components.PrivateShortcutCreateManager import org.mozilla.fenix.components.PrivateShortcutCreateManager
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.application
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.metrics
@ -85,15 +85,24 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// Observe account changes to keep the UI up-to-date. // Observe account changes to keep the UI up-to-date.
requireComponents.backgroundServices.accountManager.register(this, owner = this, autoPause = true) requireComponents.backgroundServices.accountManager.register(
this,
owner = this,
autoPause = true
)
// It's important to update the account UI state in onCreate, even though we also call it in onResume, since // It's important to update the account UI state in onCreate, even though we also call it in onResume, since
// that ensures we'll never display an incorrect state in the UI. For example, if user is signed-in, and we // that ensures we'll never display an incorrect state in the UI. For example, if user is signed-in, and we
// don't perform this call in onCreate, we'll briefly display a "Sign In" preference, which will then get // don't perform this call in onCreate, we'll briefly display a "Sign In" preference, which will then get
// replaced by the correct account information once this call is ran in onResume shortly after. // replaced by the correct account information once this call is ran in onResume shortly after.
updateAccountUIState(context!!, requireComponents.backgroundServices.accountManager.accountProfile()) updateAccountUIState(
context!!,
requireComponents.backgroundServices.accountManager.accountProfile()
)
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangeListener) preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(
preferenceChangeListener
)
} }
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
@ -139,12 +148,16 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
} }
findPreference<Preference>(getPreferenceKey(pref_key_add_private_browsing_shortcut))?.apply { findPreference<Preference>(getPreferenceKey(pref_key_add_private_browsing_shortcut))?.apply {
isVisible = !PrivateShortcutCreateManager.doesPrivateBrowsingPinnedShortcutExist(context) isVisible =
!PrivateShortcutCreateManager.doesPrivateBrowsingPinnedShortcutExist(context)
} }
setupPreferences() setupPreferences()
updateAccountUIState(context!!, requireComponents.backgroundServices.accountManager.accountProfile()) updateAccountUIState(
context!!,
requireComponents.backgroundServices.accountManager.accountProfile()
)
updatePreferenceVisibilityForFeatureFlags() updatePreferenceVisibilityForFeatureFlags()
} }
@ -187,7 +200,10 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
} }
resources.getString(pref_key_help) -> { resources.getString(pref_key_help) -> {
(activity as HomeActivity).openToBrowserAndLoad( (activity as HomeActivity).openToBrowserAndLoad(
searchTermOrURL = SupportUtils.getSumoURLForTopic(context!!, SupportUtils.SumoTopic.HELP), searchTermOrURL = SupportUtils.getSumoURLForTopic(
context!!,
SupportUtils.SumoTopic.HELP
),
newTab = true, newTab = true,
from = BrowserDirection.FromSettings from = BrowserDirection.FromSettings
) )
@ -228,7 +244,10 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
} }
resources.getString(pref_key_privacy_link) -> { resources.getString(pref_key_privacy_link) -> {
requireContext().let { context -> requireContext().let { context ->
val intent = SupportUtils.createCustomTabIntent(context, SupportUtils.getPrivacyNoticeUrl()) val intent = SupportUtils.createCustomTabIntent(
context,
SupportUtils.getPrivacyNoticeUrl()
)
startActivity(intent) startActivity(intent)
} }
} }
@ -247,7 +266,9 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener) preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(
preferenceChangeListener
)
} }
private fun getClickListenerForSignIn(): OnPreferenceClickListener { private fun getClickListenerForSignIn(): OnPreferenceClickListener {
@ -266,7 +287,8 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
if (!Config.channel.isReleased) { if (!Config.channel.isReleased) {
preferenceLeakCanary?.setOnPreferenceChangeListener { _, newValue -> preferenceLeakCanary?.setOnPreferenceChangeListener { _, newValue ->
(context?.applicationContext as FenixApplication).toggleLeakCanary(newValue as Boolean) val isEnabled = newValue == true
context?.application?.updateLeakCanaryState(isEnabled)
true true
} }
} }
@ -290,7 +312,8 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
} }
private fun navigateToTrackingProtectionSettings() { private fun navigateToTrackingProtectionSettings() {
val directions = SettingsFragmentDirections.actionSettingsFragmentToTrackingProtectionFragment() val directions =
SettingsFragmentDirections.actionSettingsFragmentToTrackingProtectionFragment()
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
} }
@ -311,7 +334,8 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
} }
private fun navigateToDefaultBrowserSettingsFragment() { private fun navigateToDefaultBrowserSettingsFragment() {
val directions = SettingsFragmentDirections.actionSettingsFragmentToDefaultBrowserSettingsFragment() val directions =
SettingsFragmentDirections.actionSettingsFragmentToDefaultBrowserSettingsFragment()
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
} }
@ -337,7 +361,8 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
} }
private fun navigateToDeleteBrowsingData() { private fun navigateToDeleteBrowsingData() {
val directions = SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataFragment() val directions =
SettingsFragmentDirections.actionSettingsFragmentToDeleteBrowsingDataFragment()
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
} }
@ -350,7 +375,10 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
override fun onAuthenticated(account: OAuthAccount, authType: AuthType) { override fun onAuthenticated(account: OAuthAccount, authType: AuthType) {
lifecycleScope.launch { lifecycleScope.launch {
context?.let { context?.let {
updateAccountUIState(it, it.components.backgroundServices.accountManager.accountProfile()) updateAccountUIState(
it,
it.components.backgroundServices.accountManager.accountProfile()
)
} }
} }
} }
@ -358,7 +386,10 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
override fun onLoggedOut() { override fun onLoggedOut() {
lifecycleScope.launch { lifecycleScope.launch {
context?.let { context?.let {
updateAccountUIState(it, it.components.backgroundServices.accountManager.accountProfile()) updateAccountUIState(
it,
it.components.backgroundServices.accountManager.accountProfile()
)
} }
} }
} }
@ -374,7 +405,10 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
override fun onAuthenticationProblems() { override fun onAuthenticationProblems() {
lifecycleScope.launch { lifecycleScope.launch {
context?.let { context?.let {
updateAccountUIState(it, it.components.backgroundServices.accountManager.accountProfile()) updateAccountUIState(
it,
it.components.backgroundServices.accountManager.accountProfile()
)
} }
} }
} }
@ -389,7 +423,11 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
val preferenceFirefoxAccount = val preferenceFirefoxAccount =
findPreference<AccountPreference>(context.getPreferenceKey(pref_key_account)) findPreference<AccountPreference>(context.getPreferenceKey(pref_key_account))
val preferenceFirefoxAccountAuthError = val preferenceFirefoxAccountAuthError =
findPreference<AccountAuthErrorPreference>(context.getPreferenceKey(pref_key_account_auth_error)) findPreference<AccountAuthErrorPreference>(
context.getPreferenceKey(
pref_key_account_auth_error
)
)
val accountPreferenceCategory = val accountPreferenceCategory =
findPreference<PreferenceCategory>(context.getPreferenceKey(pref_key_account_category)) findPreference<PreferenceCategory>(context.getPreferenceKey(pref_key_account_category))

View File

@ -12,7 +12,7 @@ object Versions {
const val rxBindings = "3.0.0-alpha2" const val rxBindings = "3.0.0-alpha2"
const val anko = "0.10.8" const val anko = "0.10.8"
const val sentry = "1.7.10" const val sentry = "1.7.10"
const val leakcanary = "1.6.3" const val leakcanary = "2.0-beta-3"
const val leanplum = "5.2.3" const val leanplum = "5.2.3"
const val osslicenses_plugin = "0.9.5" const val osslicenses_plugin = "0.9.5"
const val osslicenses_library = "17.0.0" const val osslicenses_library = "17.0.0"
@ -162,7 +162,6 @@ object Deps {
const val sentry = "io.sentry:sentry-android:${Versions.sentry}" const val sentry = "io.sentry:sentry-android:${Versions.sentry}"
const val leakcanary = "com.squareup.leakcanary:leakcanary-android:${Versions.leakcanary}" const val leakcanary = "com.squareup.leakcanary:leakcanary-android:${Versions.leakcanary}"
const val leakcanary_noop = "com.squareup.leakcanary:leakcanary-android-no-op:${Versions.leakcanary}"
const val leanplum = "com.leanplum:leanplum-core:${Versions.leanplum}" const val leanplum = "com.leanplum:leanplum-core:${Versions.leanplum}"
const val leanplumMessaging = "com.leanplum:leanplum-fcm:${Versions.leanplum}" const val leanplumMessaging = "com.leanplum:leanplum-fcm:${Versions.leanplum}"