RUM-9508: LogsHeavyTraffic scenario for android benchmarks#2629
Conversation
| val component: BenchmarkActivityComponent | ||
| ) : ViewModel() | ||
|
|
||
| internal class MainActivityViewModelFactory( |
There was a problem hiding this comment.
I tried to support screen rotation case. Activity gets recreated, I wanted to make the component stay alive. So I put it into a viewModel. It almost worked.
The only problem for now is that if this is called, then you can't call start again, because executorService is already stopped. If you call start, the app crashes.
I'm not going to fix this now, it isn't critical.
| import androidx.lifecycle.viewmodel.initializer | ||
| import androidx.lifecycle.viewmodel.viewModelFactory | ||
|
|
||
| internal fun <C : Any> Fragment.componentHolderViewModel(factory: ViewModel.() -> C): Lazy<C> { |
There was a problem hiding this comment.
This thing is used to make dagger component that is used inside a fragment survive configuration change. See this.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #2629 +/- ##
===========================================
- Coverage 70.05% 70.00% -0.05%
===========================================
Files 820 820
Lines 30568 30568
Branches 5132 5132
===========================================
- Hits 21413 21397 -16
- Misses 7726 7727 +1
- Partials 1429 1444 +15 🚀 New features to boost your workflow:
|
2ac6506 to
d4759cf
Compare
d4759cf to
2fd7156
Compare
| Log.DEBUG | ||
| ) | ||
|
|
||
| internal fun Int.stringRepresentation(): String { |
There was a problem hiding this comment.
Let's make function name more specific, given that receiver type is very generic.
| internal fun Int.stringRepresentation(): String { | |
| internal fun Int.logStringRepresentation(): String { |
| internal lateinit var viewModel: LogsHeavyTrafficViewModel | ||
|
|
||
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
| (parentFragment?.parentFragment as LogsHeavyTrafficHostFragment).component.inject(this) |
There was a problem hiding this comment.
why we are doing it here for the LogsHeavyTrafficHostFragment if in the LogsHeavyTrafficHostFragment.onCreateView we are already doing component.inject(this) call?
There was a problem hiding this comment.
Right now it works the following way.
We have a root fragment LogsHeavyTrafficHostFragment that has its own navigation stack and hosts LogsHeavyTrafficFragment and LogsHeavyTrafficSettingsFragment.
LogsHeavyTrafficHostFragment contains a dagger component LogsHeavyTrafficComponent that is used to share state between LogsHeavyTrafficFragment and LogsHeavyTrafficSettingsFragment and provide everything these fragments need, currently it is LogsHeavyTrafficViewModel - shared view model with shared state.
I chose field injection as a way to inject this LogsHeavyTrafficViewModelinto LogsHeavyTrafficFragment, LogsHeavyTrafficSettingsFragment .
The alternative is to create properties in LogsHeavyTrafficComponent:
interface LogsHeavyTrafficComponent {
val viewModel: LogsHeavyTrafficViewModel
val navigationManager: LogsHeavyTrafficNavigationManager
}
and in LogsHeavyTrafficFragment and LogsHeavyTrafficSettingsFragment do (parentFragment?.parentFragment as LogsHeavyTrafficHostFragment).component.viewModel.
and in LogsHeavyTrafficHostFragment do component.navigationManager.
These are 2 ways to do the same thing.
why we are doing it here for the LogsHeavyTrafficHostFragment if in the LogsHeavyTrafficHostFragment.onCreateView we are already doing component.inject(this) call?
I am not sure I understand the question. inject(...) just does field injection into the fields annotated by @Inject, it doesn't create a new component, it just uses the component to provide necessary objects.
| internal lateinit var viewModel: LogsHeavyTrafficViewModel | ||
|
|
||
| override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
| (parentFragment?.parentFragment as LogsHeavyTrafficHostFragment).component.inject(this) |
What does this PR do?
Implemented LogsHeavyTraffic scenario for Android Benchmarking app that is described here. demo: link
created a synthetics test described here. Link. I checked that is works for my local build.
Motivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)