Repository: square/leakcanary
File: leakcanary-android-core/src/main/java/leakcanary/LeakCanary.kt (Kotlin)

Code before:

    /**
     * When true, [objectInspectors] are used to find leaks instead of only checking instances
     * tracked by [KeyedWeakReference]. This leads to finding more leaks and shorter leak traces.
     * However this also means the same leaking instances will be found in every heap dump for a
     * given process life.
     *
     * Defaults to false.
     */
    val useExperimentalLeakFinders: Boolean = false
  )

  /**
   * The current LeakCanary configuration. Can be updated at any time, usually by replacing it with
   * a mutated copy, e.g.:
   *
   * ```
   * LeakCanary.config = LeakCanary.config.copy(computeRetainedHeapSize = true)
   * ```
   */
  @Volatile
  var config: Config = if (AppWatcher.isInstalled) Config() else InternalLeakCanary.noInstallConfig
    set(value) {
      field = value
      SharkLog.d { "Updated LeakCanary.config to $value" }
    }

  /**
   * Returns a new [Intent] that can be used to programmatically launch the leak display activity.
   */
  fun newLeakDisplayActivityIntent() = InternalLeakCanary.leakDisplayActivityIntent

  /**
   * Dynamically shows / hides the launcher icon for the leak display activity.
   * Note: you can change the default value by overriding the leak_canary_add_launcher_icon
   * boolean resource:
   *
   * ```
   * <?xml version="1.0" encoding="utf-8"?>
   * <resources>
   *   <bool name="leak_canary_add_launcher_icon">false</bool>
   * </resources>
   * ```
   */
  fun showLeakDisplayActivityLauncherIcon(showLauncherIcon: Boolean) {
    InternalLeakCanary.setEnabledBlocking(
        "leakcanary.internal.activity.LeakLauncherActivity", showLauncherIcon
    )
  }

  /**

Review comment (suggestion):
A small comment explaining the following blob of code might improve readability here. Something like `// Log the new diff between the old config and new`

Code after:

    /**
     * When true, [objectInspectors] are used to find leaks instead of only checking instances
     * tracked by [KeyedWeakReference]. This leads to finding more leaks and shorter leak traces.
     * However this also means the same leaking instances will be found in every heap dump for a
     * given process life.
     *
     * Defaults to false.
     */
    val useExperimentalLeakFinders: Boolean = false
  )

  /**
   * The current LeakCanary configuration. Can be updated at any time, usually by replacing it with
   * a mutated copy, e.g.:
   *
   * ```
   * LeakCanary.config = LeakCanary.config.copy(computeRetainedHeapSize = true)
   * ```
   */
  @Volatile
  var config: Config = if (AppWatcher.isInstalled) Config() else InternalLeakCanary.noInstallConfig
    set(newConfig) {
      val previousConfig = field
      field = newConfig
      SharkLog.d {
        val changedFields = mutableListOf<String>()
        Config::class.java.declaredFields.forEach { field ->
          field.isAccessible = true
          val previousValue = field[previousConfig]
          val newValue = field[newConfig]
          if (previousValue != newValue) {
            changedFields += "${field.name}=$newValue"
          }
        }

        "Updated LeakCanary.config: Config(${if (changedFields.isNotEmpty()) changedFields.joinToString(
            ", "
        ) else "no changes"})"
      }
    }

  /**
   * Returns a new [Intent] that can be used to programmatically launch the leak display activity.
   */
  fun newLeakDisplayActivityIntent() = InternalLeakCanary.leakDisplayActivityIntent

  /**
   * Dynamically shows / hides the launcher icon for the leak display activity.
   * Note: you can change the default value by overriding the leak_canary_add_launcher_icon
   * boolean resource: