summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mark Renouf <mrenouf@google.com> 2024-04-02 10:54:45 -0400
committer Mark Renouf <mrenouf@google.com> 2024-04-03 11:08:38 -0400
commit8e7e81138fc72d5df530cb77032f9aae1f18cb2c (patch)
tree55f56c955348dc639ddc98dbf19cfd187804708b
parent7f2fc4418c68dbdcf8f6766bde2180749150d549 (diff)
Simplify startup and Profile flow handling
Instead of blocking to collect a set of intermediate values in ChooserHelper, simply allow the @JavaInterop classes to do this work instead. This greatly simplifies the startup code run from onCreate but does not affect latency, as the flows are still collected within the same call stack (onCreate) when needed. This change also removes an unneccesary intermediate StateFlow from ProfileAvailability. The flow was only used internally to collect the current value. Since ProfileAvailability is a @JavaInterop class (bridging blocking/suspending code), used from the Main thread only, we can simplify to `runBlocking { flow.first() }` where an immediate value is needed. Bug: 330561320 Test: atest IntentResolver-tests-activity Flag: ACONFIG intentresolver/com.android.intentresolver.enable_private_profile Change-Id: I88c5a96a57db32bb5eee90f5d94e1d56b224aa63
-rw-r--r--java/src/com/android/intentresolver/v2/ChooserActivity.java19
-rw-r--r--java/src/com/android/intentresolver/v2/ChooserHelper.kt40
-rw-r--r--java/src/com/android/intentresolver/v2/ProfileAvailability.kt23
-rw-r--r--java/src/com/android/intentresolver/v2/ProfileHelper.kt19
-rw-r--r--tests/unit/src/com/android/intentresolver/v2/ProfileAvailabilityTest.kt8
-rw-r--r--tests/unit/src/com/android/intentresolver/v2/ProfileHelperTest.kt197
6 files changed, 140 insertions, 166 deletions
diff --git a/java/src/com/android/intentresolver/v2/ChooserActivity.java b/java/src/com/android/intentresolver/v2/ChooserActivity.java
index d624c9e4..5f3129f8 100644
--- a/java/src/com/android/intentresolver/v2/ChooserActivity.java
+++ b/java/src/com/android/intentresolver/v2/ChooserActivity.java
@@ -124,6 +124,7 @@ import com.android.intentresolver.emptystate.EmptyState;
import com.android.intentresolver.emptystate.EmptyStateProvider;
import com.android.intentresolver.grid.ChooserGridAdapter;
import com.android.intentresolver.icons.TargetDataLoader;
+import com.android.intentresolver.inject.Background;
import com.android.intentresolver.logging.EventLog;
import com.android.intentresolver.measurements.Tracer;
import com.android.intentresolver.model.AbstractResolverComparator;
@@ -185,6 +186,8 @@ import java.util.function.Supplier;
import javax.inject.Inject;
+import kotlinx.coroutines.CoroutineDispatcher;
+
/**
* The Chooser Activity handles intent resolution specifically for sharing intents -
* for example, as generated by {@see android.content.Intent#createChooser(Intent, CharSequence)}.
@@ -265,6 +268,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
private static final int SCROLL_STATUS_SCROLLING_HORIZONTAL = 2;
@Inject public UserInteractor mUserInteractor;
+ @Inject @Background public CoroutineDispatcher mBackgroundDispatcher;
@Inject public ChooserHelper mChooserHelper;
@Inject public FeatureFlags mFeatureFlags;
@Inject public android.service.chooser.FeatureFlags mChooserServiceFeatureFlags;
@@ -352,7 +356,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
setTheme(R.style.Theme_DeviceDefault_Chooser);
// Initializer is invoked when this function returns, via Lifecycle.
- mChooserHelper.setInitializer(this::initializeWith);
+ mChooserHelper.setInitializer(this::initialize);
if (mChooserServiceFeatureFlags.chooserPayloadToggling()) {
mChooserHelper.setOnChooserRequestChanged(this::onChooserRequestChanged);
}
@@ -467,8 +471,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
}
/** DO NOT CALL. Only for use from ChooserHelper as a callback. */
- private void initializeWith(InitialState initialState) {
- Log.d(TAG, "initializeWith: " + initialState);
+ private void initialize() {
mViewModel = new ViewModelProvider(this).get(ChooserViewModel.class);
mRequest = mViewModel.getRequest().getValue();
@@ -476,14 +479,14 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
mProfiles = new ProfileHelper(
mUserInteractor,
- mFeatureFlags,
- initialState.getProfiles(),
- initialState.getLaunchedAs());
+ getCoroutineScope(getLifecycle()),
+ mBackgroundDispatcher,
+ mFeatureFlags);
mProfileAvailability = new ProfileAvailability(
- getCoroutineScope(getLifecycle()),
mUserInteractor,
- initialState.getAvailability());
+ getCoroutineScope(getLifecycle()),
+ mBackgroundDispatcher);
mProfileAvailability.setOnProfileStatusChange(this::onWorkProfileStatusUpdated);
diff --git a/java/src/com/android/intentresolver/v2/ChooserHelper.kt b/java/src/com/android/intentresolver/v2/ChooserHelper.kt
index 503e46d8..9da0d605 100644
--- a/java/src/com/android/intentresolver/v2/ChooserHelper.kt
+++ b/java/src/com/android/intentresolver/v2/ChooserHelper.kt
@@ -31,7 +31,6 @@ import com.android.intentresolver.inject.Background
import com.android.intentresolver.v2.annotation.JavaInterop
import com.android.intentresolver.v2.data.model.ChooserRequest
import com.android.intentresolver.v2.domain.interactor.UserInteractor
-import com.android.intentresolver.v2.shared.model.Profile
import com.android.intentresolver.v2.ui.viewmodel.ChooserViewModel
import com.android.intentresolver.v2.validation.Invalid
import com.android.intentresolver.v2.validation.Valid
@@ -43,35 +42,10 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
-import kotlinx.coroutines.runBlocking
private const val TAG: String = "ChooserHelper"
/**
- * Provides initial values to ChooserActivity and completes initialization from onCreate.
- *
- * This information is collected and provided on behalf of ChooserActivity to eliminate the need for
- * suspending functions within remaining synchronous startup code.
- */
-@JavaInterop
-fun interface ChooserInitializer {
- /** @param initialState the initial state to provide to initialization */
- fun initializeWith(initialState: InitialState)
-}
-
-/**
- * A parameter object for Initialize which contains all the values which are required "early", on
- * the main thread and outside of any coroutines. This supports code which expects to be called by
- * the system on the main thread only. (This includes everything originally called from onCreate).
- */
-@JavaInterop
-data class InitialState(
- val profiles: List<Profile>,
- val availability: Map<Profile, Boolean>,
- val launchedAs: Profile
-)
-
-/**
* __Purpose__
*
* Cleanup aid. Provides a pathway to cleaner code.
@@ -113,7 +87,7 @@ constructor(
private val activity: ComponentActivity = hostActivity as ComponentActivity
private val viewModel by activity.viewModels<ChooserViewModel>()
- private lateinit var activityInitializer: ChooserInitializer
+ private lateinit var activityInitializer: Runnable
var onChooserRequestChanged: Consumer<ChooserRequest> = Consumer {}
@@ -126,7 +100,7 @@ constructor(
*
* This _must_ be called from [ChooserActivity.onCreate].
*/
- fun setInitializer(initializer: ChooserInitializer) {
+ fun setInitializer(initializer: Runnable) {
check(activity.lifecycle.currentState == Lifecycle.State.INITIALIZED) {
"setInitializer must be called before onCreate returns"
}
@@ -189,14 +163,6 @@ constructor(
private fun initializeActivity(request: Valid<ChooserRequest>) {
request.warnings.forEach { it.log(TAG) }
-
- val initialState =
- runBlocking(background) {
- val initialProfiles = userInteractor.profiles.first()
- val initialAvailability = userInteractor.availability.first()
- val launchedAsProfile = userInteractor.launchedAsProfile.first()
- InitialState(initialProfiles, initialAvailability, launchedAsProfile)
- }
- activityInitializer.initializeWith(initialState)
+ activityInitializer.run()
}
}
diff --git a/java/src/com/android/intentresolver/v2/ProfileAvailability.kt b/java/src/com/android/intentresolver/v2/ProfileAvailability.kt
index ddb57991..27d8c6bb 100644
--- a/java/src/com/android/intentresolver/v2/ProfileAvailability.kt
+++ b/java/src/com/android/intentresolver/v2/ProfileAvailability.kt
@@ -16,27 +16,26 @@
package com.android.intentresolver.v2
+import androidx.annotation.MainThread
import com.android.intentresolver.v2.annotation.JavaInterop
import com.android.intentresolver.v2.domain.interactor.UserInteractor
import com.android.intentresolver.v2.shared.model.Profile
+import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
-import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
-import kotlinx.coroutines.flow.stateIn
+import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
+import kotlinx.coroutines.runBlocking
/** Provides availability status for profiles */
@JavaInterop
class ProfileAvailability(
- private val scope: CoroutineScope,
private val userInteractor: UserInteractor,
- initialState: Map<Profile, Boolean>
+ private val scope: CoroutineScope,
+ private val background: CoroutineDispatcher,
) {
- private val availability =
- userInteractor.availability.stateIn(scope, SharingStarted.Eagerly, initialState)
-
/** Used by WorkProfilePausedEmptyStateProvider */
var waitingToEnableProfile = false
private set
@@ -45,8 +44,14 @@ class ProfileAvailability(
var onProfileStatusChange: Runnable? = null
private var waitJob: Job? = null
+
/** Query current profile availability. An unavailable profile is one which is not active. */
- fun isAvailable(profile: Profile) = availability.value[profile] ?: false
+ @MainThread
+ fun isAvailable(profile: Profile): Boolean {
+ return runBlocking(background) {
+ userInteractor.availability.map { it[profile] == true }.first()
+ }
+ }
/** Used by WorkProfilePausedEmptyStateProvider */
fun requestQuietModeState(profile: Profile, quietMode: Boolean) {
@@ -65,7 +70,7 @@ class ProfileAvailability(
val job =
scope.launch {
// Wait for the profile to become available
- availability.filter { it[profile] == true }.first()
+ userInteractor.availability.filter { it[profile] == true }.first()
}
job.invokeOnCompletion {
waitingToEnableProfile = false
diff --git a/java/src/com/android/intentresolver/v2/ProfileHelper.kt b/java/src/com/android/intentresolver/v2/ProfileHelper.kt
index 8a8e6b54..87948150 100644
--- a/java/src/com/android/intentresolver/v2/ProfileHelper.kt
+++ b/java/src/com/android/intentresolver/v2/ProfileHelper.kt
@@ -17,29 +17,40 @@
package com.android.intentresolver.v2
import android.os.UserHandle
+import androidx.annotation.MainThread
import com.android.intentresolver.inject.IntentResolverFlags
import com.android.intentresolver.v2.annotation.JavaInterop
import com.android.intentresolver.v2.domain.interactor.UserInteractor
import com.android.intentresolver.v2.shared.model.Profile
import com.android.intentresolver.v2.shared.model.User
import javax.inject.Inject
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.runBlocking
@JavaInterop
+@MainThread
class ProfileHelper
@Inject
constructor(
interactor: UserInteractor,
+ private val scope: CoroutineScope,
+ private val background: CoroutineDispatcher,
private val flags: IntentResolverFlags,
- val profiles: List<Profile>,
- val launchedAsProfile: Profile,
) {
private val launchedByHandle: UserHandle = interactor.launchedAs
+ val launchedAsProfile by lazy {
+ runBlocking(background) { interactor.launchedAsProfile.first() }
+ }
+ val profiles by lazy { runBlocking(background) { interactor.profiles.first() } }
+
// Map UserHandle back to a user within launchedByProfile
- private val launchedByUser =
+ private val launchedByUser: User =
when (launchedByHandle) {
launchedAsProfile.primary.handle -> launchedAsProfile.primary
- launchedAsProfile.clone?.handle -> launchedAsProfile.clone
+ launchedAsProfile.clone?.handle -> requireNotNull(launchedAsProfile.clone)
else -> error("launchedByUser must be a member of launchedByProfile")
}
val launchedAsProfileType: Profile.Type = launchedAsProfile.type
diff --git a/tests/unit/src/com/android/intentresolver/v2/ProfileAvailabilityTest.kt b/tests/unit/src/com/android/intentresolver/v2/ProfileAvailabilityTest.kt
index 9f2b3e0f..c0d5ed4e 100644
--- a/tests/unit/src/com/android/intentresolver/v2/ProfileAvailabilityTest.kt
+++ b/tests/unit/src/com/android/intentresolver/v2/ProfileAvailabilityTest.kt
@@ -22,6 +22,7 @@ import com.android.intentresolver.v2.domain.interactor.UserInteractor
import com.android.intentresolver.v2.shared.model.Profile
import com.android.intentresolver.v2.shared.model.User
import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
@@ -40,8 +41,7 @@ class ProfileAvailabilityTest {
@Test
fun testProfileAvailable() = runTest {
- val availability = ProfileAvailability(backgroundScope, interactor, mapOf())
- runCurrent()
+ val availability = ProfileAvailability(interactor, this, Dispatchers.IO)
assertThat(availability.isAvailable(personalProfile)).isTrue()
assertThat(availability.isAvailable(workProfile)).isTrue()
@@ -59,8 +59,7 @@ class ProfileAvailabilityTest {
@Test
fun waitingToEnableProfile() = runTest {
- val availability = ProfileAvailability(backgroundScope, interactor, mapOf())
- runCurrent()
+ val availability = ProfileAvailability(interactor, this, Dispatchers.IO)
availability.requestQuietModeState(workProfile, true)
assertThat(availability.waitingToEnableProfile).isFalse()
@@ -68,7 +67,6 @@ class ProfileAvailabilityTest {
availability.requestQuietModeState(workProfile, false)
assertThat(availability.waitingToEnableProfile).isTrue()
-
runCurrent()
assertThat(availability.waitingToEnableProfile).isFalse()
diff --git a/tests/unit/src/com/android/intentresolver/v2/ProfileHelperTest.kt b/tests/unit/src/com/android/intentresolver/v2/ProfileHelperTest.kt
index cb4b1d0a..06d795fe 100644
--- a/tests/unit/src/com/android/intentresolver/v2/ProfileHelperTest.kt
+++ b/tests/unit/src/com/android/intentresolver/v2/ProfileHelperTest.kt
@@ -17,20 +17,15 @@
package com.android.intentresolver.v2
import com.android.intentresolver.Flags.FLAG_ENABLE_PRIVATE_PROFILE
-import com.android.intentresolver.inject.FakeChooserServiceFlags
import com.android.intentresolver.inject.FakeIntentResolverFlags
-import com.android.intentresolver.inject.IntentResolverFlags
import com.android.intentresolver.v2.annotation.JavaInterop
import com.android.intentresolver.v2.data.repository.FakeUserRepository
import com.android.intentresolver.v2.domain.interactor.UserInteractor
import com.android.intentresolver.v2.shared.model.Profile
import com.android.intentresolver.v2.shared.model.User
-import com.google.common.truth.Truth
import com.google.common.truth.Truth.assertThat
-import kotlinx.coroutines.flow.first
+import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.runTest
-import org.junit.Assert.*
-
import org.junit.Test
@OptIn(JavaInterop::class)
@@ -48,67 +43,69 @@ class ProfileHelperTest {
private val privateUser = User(12, User.Role.PRIVATE)
private val privateProfile = Profile(Profile.Type.PRIVATE, privateUser)
- private val flags = FakeIntentResolverFlags().apply {
- setFlag(FLAG_ENABLE_PRIVATE_PROFILE, true)
- }
+ private val flags =
+ FakeIntentResolverFlags().apply { setFlag(FLAG_ENABLE_PRIVATE_PROFILE, true) }
private fun assertProfiles(
helper: ProfileHelper,
personalProfile: Profile,
workProfile: Profile? = null,
- privateProfile: Profile? = null) {
-
+ privateProfile: Profile? = null
+ ) {
assertThat(helper.personalProfile).isEqualTo(personalProfile)
assertThat(helper.personalHandle).isEqualTo(personalProfile.primary.handle)
personalProfile.clone?.also {
assertThat(helper.cloneUserPresent).isTrue()
assertThat(helper.cloneHandle).isEqualTo(it.handle)
- } ?: {
- assertThat(helper.cloneUserPresent).isFalse()
- assertThat(helper.cloneHandle).isNull()
}
+ ?: {
+ assertThat(helper.cloneUserPresent).isFalse()
+ assertThat(helper.cloneHandle).isNull()
+ }
workProfile?.also {
assertThat(helper.workProfilePresent).isTrue()
assertThat(helper.workProfile).isEqualTo(it)
assertThat(helper.workHandle).isEqualTo(it.primary.handle)
- } ?: {
- assertThat(helper.workProfilePresent).isFalse()
- assertThat(helper.workProfile).isNull()
- assertThat(helper.workHandle).isNull()
}
+ ?: {
+ assertThat(helper.workProfilePresent).isFalse()
+ assertThat(helper.workProfile).isNull()
+ assertThat(helper.workHandle).isNull()
+ }
privateProfile?.also {
assertThat(helper.privateProfilePresent).isTrue()
assertThat(helper.privateProfile).isEqualTo(it)
assertThat(helper.privateHandle).isEqualTo(it.primary.handle)
- } ?: {
- assertThat(helper.privateProfilePresent).isFalse()
- assertThat(helper.privateProfile).isNull()
- assertThat(helper.privateHandle).isNull()
}
+ ?: {
+ assertThat(helper.privateProfilePresent).isFalse()
+ assertThat(helper.privateProfile).isNull()
+ assertThat(helper.privateHandle).isNull()
+ }
}
-
@Test
fun launchedByPersonal() = runTest {
val repository = FakeUserRepository(listOf(personalUser))
val interactor = UserInteractor(repository, launchedAs = personalUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
assertProfiles(helper, personalProfile)
assertThat(helper.isLaunchedAsCloneProfile).isFalse()
assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.PERSONAL)
assertThat(helper.getQueryIntentsHandle(personalUser.handle))
- .isEqualTo(personalProfile.primary.handle)
+ .isEqualTo(personalProfile.primary.handle)
assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(personalProfile.primary.handle)
}
@@ -116,13 +113,14 @@ class ProfileHelperTest {
fun launchedByPersonal_withClone() = runTest {
val repository = FakeUserRepository(listOf(personalUser, cloneUser))
val interactor = UserInteractor(repository, launchedAs = personalUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
assertProfiles(helper, personalWithCloneProfile)
@@ -136,47 +134,46 @@ class ProfileHelperTest {
fun launchedByClone() = runTest {
val repository = FakeUserRepository(listOf(personalUser, cloneUser))
val interactor = UserInteractor(repository, launchedAs = cloneUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
assertProfiles(helper, personalWithCloneProfile)
assertThat(helper.isLaunchedAsCloneProfile).isTrue()
assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.PERSONAL)
assertThat(helper.getQueryIntentsHandle(personalWithCloneProfile.primary.handle))
- .isEqualTo(personalWithCloneProfile.clone?.handle)
+ .isEqualTo(personalWithCloneProfile.clone?.handle)
assertThat(helper.tabOwnerUserHandleForLaunch)
- .isEqualTo(personalWithCloneProfile.primary.handle)
+ .isEqualTo(personalWithCloneProfile.primary.handle)
}
@Test
fun launchedByPersonal_withWork() = runTest {
val repository = FakeUserRepository(listOf(personalUser, workUser))
val interactor = UserInteractor(repository, launchedAs = personalUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
-
- assertProfiles(helper,
- personalProfile = personalProfile,
- workProfile = workProfile)
+ assertProfiles(helper, personalProfile = personalProfile, workProfile = workProfile)
assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.PERSONAL)
assertThat(helper.isLaunchedAsCloneProfile).isFalse()
assertThat(helper.getQueryIntentsHandle(personalUser.handle))
- .isEqualTo(personalProfile.primary.handle)
+ .isEqualTo(personalProfile.primary.handle)
assertThat(helper.getQueryIntentsHandle(workUser.handle))
- .isEqualTo(workProfile.primary.handle)
+ .isEqualTo(workProfile.primary.handle)
assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(personalProfile.primary.handle)
}
@@ -184,50 +181,47 @@ class ProfileHelperTest {
fun launchedByWork() = runTest {
val repository = FakeUserRepository(listOf(personalUser, workUser))
val interactor = UserInteractor(repository, launchedAs = workUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
- assertProfiles(helper,
- personalProfile = personalProfile,
- workProfile = workProfile)
+ assertProfiles(helper, personalProfile = personalProfile, workProfile = workProfile)
assertThat(helper.isLaunchedAsCloneProfile).isFalse()
assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.WORK)
assertThat(helper.getQueryIntentsHandle(personalProfile.primary.handle))
- .isEqualTo(personalProfile.primary.handle)
+ .isEqualTo(personalProfile.primary.handle)
assertThat(helper.getQueryIntentsHandle(workProfile.primary.handle))
- .isEqualTo(workProfile.primary.handle)
- assertThat(helper.tabOwnerUserHandleForLaunch)
- .isEqualTo(workProfile.primary.handle)
+ .isEqualTo(workProfile.primary.handle)
+ assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(workProfile.primary.handle)
}
@Test
fun launchedByPersonal_withPrivate() = runTest {
val repository = FakeUserRepository(listOf(personalUser, privateUser))
val interactor = UserInteractor(repository, launchedAs = personalUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
- assertProfiles(helper,
- personalProfile = personalProfile,
- privateProfile = privateProfile)
+ assertProfiles(helper, personalProfile = personalProfile, privateProfile = privateProfile)
assertThat(helper.isLaunchedAsCloneProfile).isFalse()
assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.PERSONAL)
assertThat(helper.getQueryIntentsHandle(personalProfile.primary.handle))
- .isEqualTo(personalProfile.primary.handle)
+ .isEqualTo(personalProfile.primary.handle)
assertThat(helper.getQueryIntentsHandle(privateProfile.primary.handle))
- .isEqualTo(privateProfile.primary.handle)
+ .isEqualTo(privateProfile.primary.handle)
assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(personalProfile.primary.handle)
}
@@ -235,25 +229,23 @@ class ProfileHelperTest {
fun launchedByPrivate() = runTest {
val repository = FakeUserRepository(listOf(personalUser, privateUser))
val interactor = UserInteractor(repository, launchedAs = privateUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
-
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
- assertProfiles(helper,
- personalProfile = personalProfile,
- privateProfile = privateProfile)
+ assertProfiles(helper, personalProfile = personalProfile, privateProfile = privateProfile)
assertThat(helper.isLaunchedAsCloneProfile).isFalse()
assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.PRIVATE)
assertThat(helper.getQueryIntentsHandle(personalProfile.primary.handle))
- .isEqualTo(personalProfile.primary.handle)
+ .isEqualTo(personalProfile.primary.handle)
assertThat(helper.getQueryIntentsHandle(privateProfile.primary.handle))
- .isEqualTo(privateProfile.primary.handle)
+ .isEqualTo(privateProfile.primary.handle)
assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(privateProfile.primary.handle)
}
@@ -263,22 +255,21 @@ class ProfileHelperTest {
val repository = FakeUserRepository(listOf(personalUser, privateUser))
val interactor = UserInteractor(repository, launchedAs = personalUser.handle)
- val launchedBy = interactor.launchedAsProfile.first()
- val helper = ProfileHelper(
- interactor = interactor,
- flags = flags,
- profiles = interactor.profiles.first(),
- launchedAsProfile = launchedBy)
+ val helper =
+ ProfileHelper(
+ interactor = interactor,
+ scope = this,
+ background = Dispatchers.Unconfined,
+ flags = flags
+ )
- assertProfiles(helper,
- personalProfile = personalProfile,
- privateProfile = null)
+ assertProfiles(helper, personalProfile = personalProfile, privateProfile = null)
assertThat(helper.isLaunchedAsCloneProfile).isFalse()
assertThat(helper.launchedAsProfileType).isEqualTo(Profile.Type.PERSONAL)
assertThat(helper.getQueryIntentsHandle(personalProfile.primary.handle))
- .isEqualTo(personalProfile.primary.handle)
+ .isEqualTo(personalProfile.primary.handle)
assertThat(helper.tabOwnerUserHandleForLaunch).isEqualTo(personalProfile.primary.handle)
}
-} \ No newline at end of file
+}