2019-02-13 16:08:35 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2019-02-13 16:08:35 +01:00
|
|
|
|
|
|
|
package org.mozilla.fenix
|
|
|
|
|
2020-06-08 19:45:33 +02:00
|
|
|
import android.os.StrictMode
|
2019-02-13 16:08:35 +01:00
|
|
|
import androidx.preference.PreferenceManager
|
2019-09-27 09:16:32 +02:00
|
|
|
import leakcanary.AppWatcher
|
|
|
|
import leakcanary.LeakCanary
|
2019-02-13 16:08:35 +01:00
|
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
2020-06-16 20:12:18 +02:00
|
|
|
import org.mozilla.fenix.ext.resetPoliciesAfter
|
2019-02-13 16:08:35 +01:00
|
|
|
|
|
|
|
class DebugFenixApplication : FenixApplication() {
|
|
|
|
|
|
|
|
override fun setupLeakCanary() {
|
2020-06-16 20:12:18 +02:00
|
|
|
val isEnabled = StrictMode.allowThreadDiskReads().resetPoliciesAfter {
|
2020-06-08 19:45:33 +02:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
.getBoolean(getPreferenceKey(R.string.pref_key_leakcanary), true)
|
|
|
|
}
|
2019-09-27 09:16:32 +02:00
|
|
|
updateLeakCanaryState(isEnabled)
|
2019-02-13 16:08:35 +01:00
|
|
|
}
|
|
|
|
|
2019-09-27 09:16:32 +02:00
|
|
|
override fun updateLeakCanaryState(isEnabled: Boolean) {
|
|
|
|
AppWatcher.config = AppWatcher.config.copy(enabled = isEnabled)
|
|
|
|
LeakCanary.config = LeakCanary.config.copy(dumpHeap = isEnabled)
|
2019-02-13 16:08:35 +01:00
|
|
|
}
|
|
|
|
}
|