diff options
| author | 2023-06-21 14:19:39 -0400 | |
|---|---|---|
| committer | 2023-06-23 17:01:54 -0400 | |
| commit | 114b886b4aaf3341b4072f184c96cc71d4763f76 (patch) | |
| tree | a7164664ab23a2d52c6344f91131919459f174dc /java/tests/src | |
| parent | 5d76bc638c7d3617af573dcba981e30b8b477123 (diff) | |
Creates application-level and activity-level dagger graphs
Provides Activities and BroadcastReceivers with the ability to use
injection in their constructors. Adds ChooserActivity, ResolverActivity,
IntentForwarderActivity, and ChooserActivityReEnabler to the dagger
graph.
Test: Existing tests still pass
BUG: 242615621
Change-Id: I0ce3bb225ceab59243833535c3776d9d64672d7d
Diffstat (limited to 'java/tests/src')
| -rw-r--r-- | java/tests/src/com/android/intentresolver/TestApplication.kt | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/java/tests/src/com/android/intentresolver/TestApplication.kt b/java/tests/src/com/android/intentresolver/TestApplication.kt index 849cfbab..f0761fbd 100644 --- a/java/tests/src/com/android/intentresolver/TestApplication.kt +++ b/java/tests/src/com/android/intentresolver/TestApplication.kt @@ -19,9 +19,30 @@ package com.android.intentresolver import android.app.Application import android.content.Context import android.os.UserHandle +import com.android.intentresolver.dagger.ApplicationComponent +import com.android.intentresolver.dagger.DaggerApplicationComponent -class TestApplication : Application() { +class TestApplication : Application(), ApplicationComponentOwner { + + private lateinit var applicationComponent: ApplicationComponent + + private val pendingDaggerActions = mutableSetOf<(ApplicationComponent) -> Unit>() + + override fun onCreate() { + super.onCreate() + applicationComponent = DaggerApplicationComponent.builder().application(this).build() + pendingDaggerActions.forEach { it.invoke(applicationComponent) } + pendingDaggerActions.clear() + } + + override fun doWhenApplicationComponentReady(action: (ApplicationComponent) -> Unit) { + if (this::applicationComponent.isInitialized) { + action.invoke(applicationComponent) + } else { + pendingDaggerActions.add(action) + } + } // return the current context as a work profile doesn't really exist in these tests override fun createContextAsUser(user: UserHandle, flags: Int): Context = this -}
\ No newline at end of file +} |