Interface for LeakDetector

This commit is contained in:
Maxime NATUREL 2022-08-10 14:44:51 +02:00
parent 250ee1faa1
commit 3ff9ab1bc8
6 changed files with 26 additions and 16 deletions

View file

@ -26,8 +26,10 @@ import dagger.hilt.components.SingletonComponent
import im.vector.app.core.debug.DebugNavigator
import im.vector.app.core.debug.DebugReceiver
import im.vector.app.core.debug.FlipperProxy
import im.vector.app.core.debug.LeakDetector
import im.vector.app.features.debug.DebugMenuActivity
import im.vector.app.flipper.VectorFlipperProxy
import im.vector.app.leakcanary.LeakCanaryLeakDetector
import im.vector.app.receivers.VectorDebugReceiver
@InstallIn(SingletonComponent::class)
@ -49,4 +51,7 @@ abstract class DebugModule {
@Binds
abstract fun bindsFlipperProxy(flipperProxy: VectorFlipperProxy): FlipperProxy
@Binds
abstract fun bindsLeakDetector(leakDetector: LeakCanaryLeakDetector): LeakDetector
}

View file

@ -20,18 +20,18 @@ import com.airbnb.mvrx.MavericksViewModelFactory
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import im.vector.app.core.debug.LeakDetector
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.EmptyViewEvents
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.leakcanary.LeakCanaryProxy
import kotlinx.coroutines.launch
class DebugMemoryLeaksViewModel @AssistedInject constructor(
@Assisted initialState: DebugMemoryLeaksViewState,
private val vectorPreferences: VectorPreferences,
private val leakCanaryProxy: LeakCanaryProxy,
private val leakDetector: LeakDetector,
) : VectorViewModel<DebugMemoryLeaksViewState, DebugMemoryLeaksViewActions, EmptyViewEvents>(initialState) {
@AssistedFactory
@ -56,7 +56,7 @@ class DebugMemoryLeaksViewModel @AssistedInject constructor(
private fun handleEnableMemoryLeaksAnalysis(action: DebugMemoryLeaksViewActions.EnableMemoryLeaksAnalysis) {
viewModelScope.launch {
vectorPreferences.enableMemoryLeakAnalysis(action.isEnabled)
leakCanaryProxy.enable(action.isEnabled)
leakDetector.enable(action.isEnabled)
refreshStateFromPreferences()
}
}

View file

@ -16,11 +16,12 @@
package im.vector.app.leakcanary
import im.vector.app.core.debug.LeakDetector
import leakcanary.LeakCanary
import javax.inject.Inject
class LeakCanaryProxy @Inject constructor() {
fun enable(enable: Boolean) {
class LeakCanaryLeakDetector @Inject constructor() : LeakDetector {
override fun enable(enable: Boolean) {
LeakCanary.config = LeakCanary.config.copy(dumpHeap = enable)
}
}

View file

@ -42,6 +42,7 @@ import com.vanniktech.emoji.google.GoogleEmojiProvider
import dagger.hilt.android.HiltAndroidApp
import im.vector.app.config.Config
import im.vector.app.core.debug.FlipperProxy
import im.vector.app.core.debug.LeakDetector
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.pushers.FcmHelper
import im.vector.app.core.resources.BuildMeta
@ -61,8 +62,6 @@ import im.vector.app.features.settings.VectorLocale
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.themes.ThemeUtils
import im.vector.app.features.version.VersionProvider
import im.vector.app.leakcanary.LeakCanaryProxy
import im.vector.app.push.fcm.FcmHelper
import org.jitsi.meet.sdk.log.JitsiMeetDefaultLogHandler
import org.matrix.android.sdk.api.Matrix
import org.matrix.android.sdk.api.auth.AuthenticationService
@ -104,7 +103,7 @@ class VectorApplication :
@Inject lateinit var matrix: Matrix
@Inject lateinit var fcmHelper: FcmHelper
@Inject lateinit var buildMeta: BuildMeta
@Inject lateinit var leakCanaryProxy: LeakCanaryProxy
@Inject lateinit var leakDetector: LeakDetector
// font thread handler
private var fontThreadHandler: Handler? = null
@ -258,6 +257,6 @@ class VectorApplication :
}
private fun initMemoryLeakAnalysis() {
leakCanaryProxy.enable(vectorPreferences.isMemoryLeakAnalysisEnabled())
leakDetector.enable(vectorPreferences.isMemoryLeakAnalysisEnabled())
}
}

View file

@ -14,14 +14,11 @@
* limitations under the License.
*/
package im.vector.app.leakcanary
import javax.inject.Inject
package im.vector.app.core.debug
/**
* No op version.
* Used for memory leak analysis control.
*/
@Suppress("UNUSED_PARAMETER")
class LeakCanaryProxy @Inject constructor() {
fun enable(enable: Boolean) {}
interface LeakDetector {
fun enable(enable: Boolean)
}

View file

@ -24,6 +24,7 @@ import dagger.hilt.components.SingletonComponent
import im.vector.app.core.debug.DebugNavigator
import im.vector.app.core.debug.DebugReceiver
import im.vector.app.core.debug.FlipperProxy
import im.vector.app.core.debug.LeakDetector
import okhttp3.Interceptor
import org.matrix.android.sdk.api.Matrix
@ -57,4 +58,11 @@ object DebugModule {
override fun networkInterceptor(): Interceptor? = null
}
@Provides
fun providesLeakDetector() = object : LeakDetector {
override fun enable(enable: Boolean) {
// no op
}
}
}