Interface for LeakDetector
This commit is contained in:
parent
250ee1faa1
commit
3ff9ab1bc8
@ -26,8 +26,10 @@ import dagger.hilt.components.SingletonComponent
|
|||||||
import im.vector.app.core.debug.DebugNavigator
|
import im.vector.app.core.debug.DebugNavigator
|
||||||
import im.vector.app.core.debug.DebugReceiver
|
import im.vector.app.core.debug.DebugReceiver
|
||||||
import im.vector.app.core.debug.FlipperProxy
|
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.features.debug.DebugMenuActivity
|
||||||
import im.vector.app.flipper.VectorFlipperProxy
|
import im.vector.app.flipper.VectorFlipperProxy
|
||||||
|
import im.vector.app.leakcanary.LeakCanaryLeakDetector
|
||||||
import im.vector.app.receivers.VectorDebugReceiver
|
import im.vector.app.receivers.VectorDebugReceiver
|
||||||
|
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
@ -49,4 +51,7 @@ abstract class DebugModule {
|
|||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindsFlipperProxy(flipperProxy: VectorFlipperProxy): FlipperProxy
|
abstract fun bindsFlipperProxy(flipperProxy: VectorFlipperProxy): FlipperProxy
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindsLeakDetector(leakDetector: LeakCanaryLeakDetector): LeakDetector
|
||||||
}
|
}
|
||||||
|
@ -20,18 +20,18 @@ import com.airbnb.mvrx.MavericksViewModelFactory
|
|||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedFactory
|
import dagger.assisted.AssistedFactory
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
|
import im.vector.app.core.debug.LeakDetector
|
||||||
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
import im.vector.app.core.di.hiltMavericksViewModelFactory
|
||||||
import im.vector.app.core.platform.EmptyViewEvents
|
import im.vector.app.core.platform.EmptyViewEvents
|
||||||
import im.vector.app.core.platform.VectorViewModel
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import im.vector.app.leakcanary.LeakCanaryProxy
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class DebugMemoryLeaksViewModel @AssistedInject constructor(
|
class DebugMemoryLeaksViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: DebugMemoryLeaksViewState,
|
@Assisted initialState: DebugMemoryLeaksViewState,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val leakCanaryProxy: LeakCanaryProxy,
|
private val leakDetector: LeakDetector,
|
||||||
) : VectorViewModel<DebugMemoryLeaksViewState, DebugMemoryLeaksViewActions, EmptyViewEvents>(initialState) {
|
) : VectorViewModel<DebugMemoryLeaksViewState, DebugMemoryLeaksViewActions, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
@AssistedFactory
|
@AssistedFactory
|
||||||
@ -56,7 +56,7 @@ class DebugMemoryLeaksViewModel @AssistedInject constructor(
|
|||||||
private fun handleEnableMemoryLeaksAnalysis(action: DebugMemoryLeaksViewActions.EnableMemoryLeaksAnalysis) {
|
private fun handleEnableMemoryLeaksAnalysis(action: DebugMemoryLeaksViewActions.EnableMemoryLeaksAnalysis) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
vectorPreferences.enableMemoryLeakAnalysis(action.isEnabled)
|
vectorPreferences.enableMemoryLeakAnalysis(action.isEnabled)
|
||||||
leakCanaryProxy.enable(action.isEnabled)
|
leakDetector.enable(action.isEnabled)
|
||||||
refreshStateFromPreferences()
|
refreshStateFromPreferences()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,12 @@
|
|||||||
|
|
||||||
package im.vector.app.leakcanary
|
package im.vector.app.leakcanary
|
||||||
|
|
||||||
|
import im.vector.app.core.debug.LeakDetector
|
||||||
import leakcanary.LeakCanary
|
import leakcanary.LeakCanary
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class LeakCanaryProxy @Inject constructor() {
|
class LeakCanaryLeakDetector @Inject constructor() : LeakDetector {
|
||||||
fun enable(enable: Boolean) {
|
override fun enable(enable: Boolean) {
|
||||||
LeakCanary.config = LeakCanary.config.copy(dumpHeap = enable)
|
LeakCanary.config = LeakCanary.config.copy(dumpHeap = enable)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -42,6 +42,7 @@ import com.vanniktech.emoji.google.GoogleEmojiProvider
|
|||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
import im.vector.app.config.Config
|
import im.vector.app.config.Config
|
||||||
import im.vector.app.core.debug.FlipperProxy
|
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.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.pushers.FcmHelper
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.resources.BuildMeta
|
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.settings.VectorPreferences
|
||||||
import im.vector.app.features.themes.ThemeUtils
|
import im.vector.app.features.themes.ThemeUtils
|
||||||
import im.vector.app.features.version.VersionProvider
|
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.jitsi.meet.sdk.log.JitsiMeetDefaultLogHandler
|
||||||
import org.matrix.android.sdk.api.Matrix
|
import org.matrix.android.sdk.api.Matrix
|
||||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||||
@ -104,7 +103,7 @@ class VectorApplication :
|
|||||||
@Inject lateinit var matrix: Matrix
|
@Inject lateinit var matrix: Matrix
|
||||||
@Inject lateinit var fcmHelper: FcmHelper
|
@Inject lateinit var fcmHelper: FcmHelper
|
||||||
@Inject lateinit var buildMeta: BuildMeta
|
@Inject lateinit var buildMeta: BuildMeta
|
||||||
@Inject lateinit var leakCanaryProxy: LeakCanaryProxy
|
@Inject lateinit var leakDetector: LeakDetector
|
||||||
|
|
||||||
// font thread handler
|
// font thread handler
|
||||||
private var fontThreadHandler: Handler? = null
|
private var fontThreadHandler: Handler? = null
|
||||||
@ -258,6 +257,6 @@ class VectorApplication :
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initMemoryLeakAnalysis() {
|
private fun initMemoryLeakAnalysis() {
|
||||||
leakCanaryProxy.enable(vectorPreferences.isMemoryLeakAnalysisEnabled())
|
leakDetector.enable(vectorPreferences.isMemoryLeakAnalysisEnabled())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,11 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.app.leakcanary
|
package im.vector.app.core.debug
|
||||||
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* No op version.
|
* Used for memory leak analysis control.
|
||||||
*/
|
*/
|
||||||
@Suppress("UNUSED_PARAMETER")
|
interface LeakDetector {
|
||||||
class LeakCanaryProxy @Inject constructor() {
|
fun enable(enable: Boolean)
|
||||||
fun enable(enable: Boolean) {}
|
|
||||||
}
|
}
|
@ -24,6 +24,7 @@ import dagger.hilt.components.SingletonComponent
|
|||||||
import im.vector.app.core.debug.DebugNavigator
|
import im.vector.app.core.debug.DebugNavigator
|
||||||
import im.vector.app.core.debug.DebugReceiver
|
import im.vector.app.core.debug.DebugReceiver
|
||||||
import im.vector.app.core.debug.FlipperProxy
|
import im.vector.app.core.debug.FlipperProxy
|
||||||
|
import im.vector.app.core.debug.LeakDetector
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import org.matrix.android.sdk.api.Matrix
|
import org.matrix.android.sdk.api.Matrix
|
||||||
|
|
||||||
@ -57,4 +58,11 @@ object DebugModule {
|
|||||||
|
|
||||||
override fun networkInterceptor(): Interceptor? = null
|
override fun networkInterceptor(): Interceptor? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
fun providesLeakDetector() = object : LeakDetector {
|
||||||
|
override fun enable(enable: Boolean) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user