summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Anton Potapov <apotapov@google.com> 2023-10-25 17:00:28 +0100
committer Anton Potapov <apotapov@google.com> 2023-10-25 17:15:19 +0100
commite65fce6d6689cdc073cf598ca960dbe64c8dc775 (patch)
tree4efa0f17e57c78dd448ee88fb75314c21472a65c
parent57ae6eea50aed76c5c5631700609d23811bf5b73 (diff)
Migrate from using userId to UserHandle for better type safety
Also renamed: - BaseQSTileViewModel to QSTileViewModelImpl - QSViewModelFactory to QSTileViewModelFactory Test: atest DisabledByPolicyInteractorTest Test: atest QSTileViewModelInterfaceComplianceTest Bug: 299908705 Change-Id: Ie66ddc8d8788906840196e77d7851c4e1b9e69d9
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt11
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileDataInteractor.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileInput.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSTileViewModelFactory.kt (renamed from packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSViewModelFactory.kt)26
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSTileViewModelImpl.kt (renamed from packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/BaseQSTileViewModel.kt)37
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileData.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileInteractor.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileComponent.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileScope.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModel.kt3
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt3
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt8
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelInterfaceComplianceTest.kt7
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeDisabledByPolicyInteractor.kt4
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeQSTileDataInteractor.kt13
15 files changed, 74 insertions, 64 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt
index 056f967b09bb..d1f8945cc091 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractor.kt
@@ -17,6 +17,7 @@
package com.android.systemui.qs.tiles.base.interactor
import android.content.Context
+import android.os.UserHandle
import androidx.annotation.VisibleForTesting
import androidx.annotation.WorkerThread
import com.android.settingslib.RestrictedLockUtils
@@ -32,7 +33,7 @@ import kotlinx.coroutines.withContext
/**
* Provides restrictions data for the tiles. This is used in
- * [com.android.systemui.qs.tiles.base.viewmodel.BaseQSTileViewModel] to determine if the tile is
+ * [com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelImpl] to determine if the tile is
* disabled based on the [com.android.systemui.qs.tiles.viewmodel.QSTileConfig.policy].
*/
interface DisabledByPolicyInteractor {
@@ -41,7 +42,7 @@ interface DisabledByPolicyInteractor {
* Checks if the tile is restricted by the policy for a specific user. Pass the result to the
* [handlePolicyResult] to let the user know that the tile is disable by the admin.
*/
- suspend fun isDisabled(userId: Int, userRestriction: String?): PolicyResult
+ suspend fun isDisabled(user: UserHandle, userRestriction: String?): PolicyResult
/**
* Returns true when [policyResult] is [PolicyResult.TileDisabled] and has been handled by this
@@ -75,14 +76,14 @@ constructor(
@Background private val backgroundDispatcher: CoroutineDispatcher,
) : DisabledByPolicyInteractor {
- override suspend fun isDisabled(userId: Int, userRestriction: String?): PolicyResult =
+ override suspend fun isDisabled(user: UserHandle, userRestriction: String?): PolicyResult =
withContext(backgroundDispatcher) {
val admin: EnforcedAdmin =
- restrictedLockProxy.getEnforcedAdmin(userId, userRestriction)
+ restrictedLockProxy.getEnforcedAdmin(user.identifier, userRestriction)
?: return@withContext PolicyResult.TileEnabled
return@withContext if (
- !restrictedLockProxy.hasBaseUserRestriction(userId, userRestriction)
+ !restrictedLockProxy.hasBaseUserRestriction(user.identifier, userRestriction)
) {
PolicyResult.TileDisabled(admin)
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileDataInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileDataInteractor.kt
index a3e38500123e..9752fea22f6b 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileDataInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileDataInteractor.kt
@@ -16,6 +16,7 @@
package com.android.systemui.qs.tiles.base.interactor
+import android.os.UserHandle
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
@@ -29,13 +30,12 @@ interface QSTileDataInteractor<DATA_TYPE> {
/**
* Returns a data flow scoped to the user. This means the subscription will live when the tile
- * is listened for the [userId]. It's cancelled when the tile is not listened or the user
- * changes.
+ * is listened for the [user]. It's cancelled when the tile is not listened or the user changes.
*
* You can use [Flow.onStart] on the returned to update the tile with the current state as soon
* as possible.
*/
- fun tileData(userId: Int, triggers: Flow<DataUpdateTrigger>): Flow<DATA_TYPE>
+ fun tileData(user: UserHandle, triggers: Flow<DataUpdateTrigger>): Flow<DATA_TYPE>
/**
* Returns tile availability - whether this device currently supports this tile.
@@ -43,5 +43,5 @@ interface QSTileDataInteractor<DATA_TYPE> {
* You can use [Flow.onStart] on the returned to update the tile with the current state as soon
* as possible.
*/
- fun availability(userId: Int): Flow<Boolean>
+ fun availability(user: UserHandle): Flow<Boolean>
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileInput.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileInput.kt
index 102fa3641ff4..77ff6092063f 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileInput.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileInput.kt
@@ -16,11 +16,12 @@
package com.android.systemui.qs.tiles.base.interactor
+import android.os.UserHandle
import com.android.systemui.qs.tiles.viewmodel.QSTileUserAction
/** @see QSTileUserActionInteractor.handleInput */
data class QSTileInput<T>(
- val userId: Int,
+ val user: UserHandle,
val action: QSTileUserAction,
val data: T,
)
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSViewModelFactory.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSTileViewModelFactory.kt
index 71cf228481ea..936bf9c8f4da 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSViewModelFactory.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSTileViewModelFactory.kt
@@ -33,17 +33,17 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
/**
- * Factory to create an appropriate [BaseQSTileViewModel] instance depending on your circumstances.
+ * Factory to create an appropriate [QSTileViewModelImpl] instance depending on your circumstances.
*
- * @see [QSViewModelFactory.Component]
- * @see [QSViewModelFactory.Static]
+ * @see [QSTileViewModelFactory.Component]
+ * @see [QSTileViewModelFactory.Static]
*/
-sealed interface QSViewModelFactory<T> {
+sealed interface QSTileViewModelFactory<T> {
/**
* This factory allows you to pass an instance of [QSTileComponent] to a view model effectively
* binding them together. This achieves a DI scope that lives along the instance of
- * [BaseQSTileViewModel].
+ * [QSTileViewModelImpl].
*/
class Component<T>
@Inject
@@ -55,14 +55,14 @@ sealed interface QSViewModelFactory<T> {
private val qsTileLogger: QSTileLogger,
private val systemClock: SystemClock,
@Background private val backgroundDispatcher: CoroutineDispatcher,
- ) : QSViewModelFactory<T> {
+ ) : QSTileViewModelFactory<T> {
/**
- * Creates [BaseQSTileViewModel] based on the interactors obtained from [component].
+ * Creates [QSTileViewModelImpl] based on the interactors obtained from [component].
* Reference of that [component] is then stored along the view model.
*/
- fun create(component: QSTileComponent<T>): BaseQSTileViewModel<T> =
- BaseQSTileViewModel(
+ fun create(component: QSTileComponent<T>): QSTileViewModelImpl<T> =
+ QSTileViewModelImpl(
component::config,
component::userActionInteractor,
component::dataInteractor,
@@ -78,7 +78,7 @@ sealed interface QSViewModelFactory<T> {
}
/**
- * This factory passes by necessary implementations to the [BaseQSTileViewModel]. This is a
+ * This factory passes by necessary implementations to the [QSTileViewModelImpl]. This is a
* default choice for most of the tiles.
*/
class Static<T>
@@ -91,7 +91,7 @@ sealed interface QSViewModelFactory<T> {
private val qsTileLogger: QSTileLogger,
private val systemClock: SystemClock,
@Background private val backgroundDispatcher: CoroutineDispatcher,
- ) : QSViewModelFactory<T> {
+ ) : QSTileViewModelFactory<T> {
/**
* @param config contains all the static information (like TileSpec) about the tile.
@@ -107,8 +107,8 @@ sealed interface QSViewModelFactory<T> {
userActionInteractor: QSTileUserActionInteractor<T>,
tileDataInteractor: QSTileDataInteractor<T>,
mapper: QSTileDataToStateMapper<T>,
- ): BaseQSTileViewModel<T> =
- BaseQSTileViewModel(
+ ): QSTileViewModelImpl<T> =
+ QSTileViewModelImpl(
{ config },
{ userActionInteractor },
{ tileDataInteractor },
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/BaseQSTileViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSTileViewModelImpl.kt
index 8db6ab2d9459..bbb74453abbd 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/BaseQSTileViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/viewmodel/QSTileViewModelImpl.kt
@@ -16,7 +16,7 @@
package com.android.systemui.qs.tiles.base.viewmodel
-import androidx.annotation.CallSuper
+import android.os.UserHandle
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.qs.tiles.base.analytics.QSTileAnalytics
import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger
@@ -62,11 +62,11 @@ import kotlinx.coroutines.flow.stateIn
* Provides a hassle-free way to implement new tiles according to current System UI architecture
* standards. This ViewModel is cheap to instantiate and does nothing until its [state] is listened.
*
- * Don't use this constructor directly. Instead, inject [QSViewModelFactory] to create a new
+ * Don't use this constructor directly. Instead, inject [QSTileViewModelFactory] to create a new
* instance of this class.
*/
@OptIn(ExperimentalCoroutinesApi::class)
-class BaseQSTileViewModel<DATA_TYPE>(
+class QSTileViewModelImpl<DATA_TYPE>(
val tileConfig: () -> QSTileConfig,
private val userActionInteractor: () -> QSTileUserActionInteractor<DATA_TYPE>,
private val tileDataInteractor: () -> QSTileDataInteractor<DATA_TYPE>,
@@ -81,8 +81,8 @@ class BaseQSTileViewModel<DATA_TYPE>(
private val tileScope: CoroutineScope = CoroutineScope(SupervisorJob()),
) : QSTileViewModel {
- private val userIds: MutableStateFlow<Int> =
- MutableStateFlow(userRepository.getSelectedUserInfo().id)
+ private val users: MutableStateFlow<UserHandle> =
+ MutableStateFlow(userRepository.getSelectedUserInfo().userHandle)
private val userInputs: MutableSharedFlow<QSTileUserAction> =
MutableSharedFlow(replay = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
private val forceUpdates: MutableSharedFlow<Unit> =
@@ -108,7 +108,7 @@ class BaseQSTileViewModel<DATA_TYPE>(
replay = 1,
)
override val isAvailable: StateFlow<Boolean> =
- userIds
+ users
.flatMapLatest { tileDataInteractor().availability(it) }
.flowOn(backgroundDispatcher)
.stateIn(
@@ -117,17 +117,14 @@ class BaseQSTileViewModel<DATA_TYPE>(
true,
)
- @CallSuper
override fun forceUpdate() {
forceUpdates.tryEmit(Unit)
}
- @CallSuper
- override fun onUserIdChanged(userId: Int) {
- userIds.tryEmit(userId)
+ override fun onUserChanged(user: UserHandle) {
+ users.tryEmit(user)
}
- @CallSuper
override fun onActionPerformed(userAction: QSTileUserAction) {
qsTileLogger.logUserAction(
userAction,
@@ -143,11 +140,11 @@ class BaseQSTileViewModel<DATA_TYPE>(
}
private fun createTileDataFlow(): SharedFlow<DATA_TYPE> =
- userIds
- .flatMapLatest { userId ->
+ users
+ .flatMapLatest { user ->
val updateTriggers =
merge(
- userInputFlow(userId),
+ userInputFlow(user),
forceUpdates
.map { DataUpdateTrigger.ForceUpdate }
.onEach { qsTileLogger.logForceUpdate(spec) },
@@ -157,7 +154,7 @@ class BaseQSTileViewModel<DATA_TYPE>(
qsTileLogger.logInitialRequest(spec)
}
tileDataInteractor()
- .tileData(userId, updateTriggers)
+ .tileData(user, updateTriggers)
.cancellable()
.flowOn(backgroundDispatcher)
}
@@ -176,10 +173,10 @@ class BaseQSTileViewModel<DATA_TYPE>(
*
* Subscribing to the result flow twice will result in doubling all actions, logs and analytics.
*/
- private fun userInputFlow(userId: Int): Flow<DataUpdateTrigger> {
+ private fun userInputFlow(user: UserHandle): Flow<DataUpdateTrigger> {
return userInputs
.filterFalseActions()
- .filterByPolicy(userId)
+ .filterByPolicy(user)
.throttle(CLICK_THROTTLE_DURATION, systemClock)
// Skip the input until there is some data
.mapNotNull { action ->
@@ -188,20 +185,20 @@ class BaseQSTileViewModel<DATA_TYPE>(
qsTileLogger.logUserActionPipeline(spec, action, state, data)
qsTileAnalytics.trackUserAction(config, action)
- DataUpdateTrigger.UserInput(QSTileInput(userId, action, data))
+ DataUpdateTrigger.UserInput(QSTileInput(user, action, data))
}
.onEach { userActionInteractor().handleInput(it.input) }
.flowOn(backgroundDispatcher)
}
- private fun Flow<QSTileUserAction>.filterByPolicy(userId: Int): Flow<QSTileUserAction> =
+ private fun Flow<QSTileUserAction>.filterByPolicy(user: UserHandle): Flow<QSTileUserAction> =
config.policy.let { policy ->
when (policy) {
is QSTilePolicy.NoRestrictions -> this@filterByPolicy
is QSTilePolicy.Restricted ->
filter { action ->
val result =
- disabledByPolicyInteractor.isDisabled(userId, policy.userRestriction)
+ disabledByPolicyInteractor.isDisabled(user, policy.userRestriction)
!disabledByPolicyInteractor.handlePolicyResult(result).also { isDisabled ->
if (isDisabled) {
qsTileLogger.logUserActionRejectedByPolicy(action, spec)
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileData.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileData.kt
index 22c7309d45a6..bb5a229a0696 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileData.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileData.kt
@@ -18,11 +18,12 @@ package com.android.systemui.qs.tiles.impl.custom
import android.content.ComponentName
import android.graphics.drawable.Icon
+import android.os.UserHandle
import android.service.quicksettings.Tile
import com.android.systemui.qs.tiles.impl.custom.di.bound.CustomTileBoundComponent
data class CustomTileData(
- val userId: Int,
+ val user: UserHandle,
val componentName: ComponentName,
val tile: Tile,
val callingAppUid: Int,
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileInteractor.kt
index a28a441ca7fc..761274e96e43 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/custom/CustomTileInteractor.kt
@@ -16,6 +16,7 @@
package com.android.systemui.qs.tiles.impl.custom
+import android.os.UserHandle
import com.android.systemui.qs.tiles.base.interactor.DataUpdateTrigger
import com.android.systemui.qs.tiles.base.interactor.QSTileDataInteractor
import com.android.systemui.qs.tiles.impl.di.QSTileScope
@@ -25,11 +26,14 @@ import kotlinx.coroutines.flow.Flow
@QSTileScope
class CustomTileInteractor @Inject constructor() : QSTileDataInteractor<CustomTileData> {
- override fun tileData(userId: Int, triggers: Flow<DataUpdateTrigger>): Flow<CustomTileData> {
+ override fun tileData(
+ user: UserHandle,
+ triggers: Flow<DataUpdateTrigger>
+ ): Flow<CustomTileData> {
TODO("Not yet implemented")
}
- override fun availability(userId: Int): Flow<Boolean> {
+ override fun availability(user: UserHandle): Flow<Boolean> {
TODO("Not yet implemented")
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileComponent.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileComponent.kt
index a65b2a063e98..6f351cdb9b33 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileComponent.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileComponent.kt
@@ -24,7 +24,7 @@ import com.android.systemui.qs.tiles.viewmodel.QSTileConfig
/**
* Base QS tile component. It should be used with [QSTileScope] to create a custom tile scoped
* component. Pass this component to
- * [com.android.systemui.qs.tiles.base.viewmodel.QSViewModelFactory.Component].
+ * [com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelFactory.Component].
*/
interface QSTileComponent<T> {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileScope.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileScope.kt
index eafbb7d3523e..a412de364c19 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileScope.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/di/QSTileScope.kt
@@ -21,7 +21,7 @@ import javax.inject.Scope
/**
* Scope annotation for QS tiles. This scope is created for each tile and is disposed when the tile
* is no longer needed (ex. it's removed from QS). So, it lives along the instance of
- * [com.android.systemui.qs.tiles.base.viewmodel.BaseQSTileViewModel]. This doesn't align with tile
+ * [com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelImpl]. This doesn't align with tile
* visibility. For example, the tile scope survives shade open/close.
*/
@MustBeDocumented @Retention(AnnotationRetention.RUNTIME) @Scope annotation class QSTileScope
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModel.kt
index debcc5df11ad..580c42122a85 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModel.kt
@@ -16,6 +16,7 @@
package com.android.systemui.qs.tiles.viewmodel
+import android.os.UserHandle
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
@@ -42,7 +43,7 @@ interface QSTileViewModel {
* and use this value instead. This is to maintain consistent and concurrency-free behaviour
* across different parts of QS.
*/
- fun onUserIdChanged(userId: Int)
+ fun onUserChanged(user: UserHandle)
/** Triggers the emission of the new [QSTileState] in a [state]. */
fun forceUpdate()
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt
index 72663be6708f..28536f5b19a7 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelAdapter.kt
@@ -17,6 +17,7 @@
package com.android.systemui.qs.tiles.viewmodel
import android.content.Context
+import android.os.UserHandle
import android.util.Log
import android.view.View
import androidx.annotation.GuardedBy
@@ -134,7 +135,7 @@ constructor(
qsTileViewModel.currentState?.supportedActions?.contains(action) == true
override fun userSwitch(currentUser: Int) {
- qsTileViewModel.onUserIdChanged(currentUser)
+ qsTileViewModel.onUserChanged(UserHandle.of(currentUser))
}
@Deprecated(
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt
index a6199c25874b..2bdc154dd885 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/base/interactor/DisabledByPolicyInteractorTest.kt
@@ -83,7 +83,7 @@ class DisabledByPolicyInteractorTest : SysuiTestCase() {
@Test
fun testDisabledWhenAdminWithNoRestrictions() =
testScope.runTest {
- val admin = EnforcedAdmin(TEST_COMPONENT_NAME, UserHandle(TEST_USER))
+ val admin = EnforcedAdmin(TEST_COMPONENT_NAME, TEST_USER)
whenever(restrictedLockProxy.getEnforcedAdmin(anyInt(), anyString())).thenReturn(admin)
whenever(restrictedLockProxy.hasBaseUserRestriction(anyInt(), anyString()))
.thenReturn(false)
@@ -129,11 +129,11 @@ class DisabledByPolicyInteractorTest : SysuiTestCase() {
}
private companion object {
- const val TEST_USER = 1
+
const val TEST_RESTRICTION = "test_restriction"
val TEST_COMPONENT_NAME = ComponentName("test.pkg", "test.cls")
-
- val ADMIN = EnforcedAdmin(TEST_COMPONENT_NAME, UserHandle(TEST_USER))
+ val TEST_USER = UserHandle(1)
+ val ADMIN = EnforcedAdmin(TEST_COMPONENT_NAME, TEST_USER)
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelInterfaceComplianceTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelInterfaceComplianceTest.kt
index 8c1e4771c299..1a4553558e28 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelInterfaceComplianceTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/tiles/viewmodel/QSTileViewModelInterfaceComplianceTest.kt
@@ -16,6 +16,7 @@
package com.android.systemui.qs.tiles.viewmodel
+import android.os.UserHandle
import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
@@ -31,7 +32,7 @@ import com.android.systemui.qs.tiles.base.interactor.FakeQSTileDataInteractor
import com.android.systemui.qs.tiles.base.interactor.FakeQSTileUserActionInteractor
import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper
import com.android.systemui.qs.tiles.base.logging.QSTileLogger
-import com.android.systemui.qs.tiles.base.viewmodel.BaseQSTileViewModel
+import com.android.systemui.qs.tiles.base.viewmodel.QSTileViewModelImpl
import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
@@ -84,14 +85,14 @@ class QSTileViewModelInterfaceComplianceTest : SysuiTestCase() {
assertThat(fakeQSTileDataInteractor.dataRequests).isNotEmpty()
assertThat(fakeQSTileDataInteractor.dataRequests.first())
- .isEqualTo(FakeQSTileDataInteractor.DataRequest(0))
+ .isEqualTo(FakeQSTileDataInteractor.DataRequest(UserHandle.of(0)))
}
private fun createViewModel(
scope: TestScope,
config: QSTileConfig = TEST_QS_TILE_CONFIG,
): QSTileViewModel =
- BaseQSTileViewModel(
+ QSTileViewModelImpl(
{ config },
{ fakeQSTileUserActionInteractor },
{ fakeQSTileDataInteractor },
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeDisabledByPolicyInteractor.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeDisabledByPolicyInteractor.kt
index f62bf6014374..1efa74b0551a 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeDisabledByPolicyInteractor.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeDisabledByPolicyInteractor.kt
@@ -16,6 +16,8 @@
package com.android.systemui.qs.tiles.base.interactor
+import android.os.UserHandle
+
class FakeDisabledByPolicyInteractor : DisabledByPolicyInteractor {
var handleResult: Boolean = false
@@ -23,7 +25,7 @@ class FakeDisabledByPolicyInteractor : DisabledByPolicyInteractor {
DisabledByPolicyInteractor.PolicyResult.TileEnabled
override suspend fun isDisabled(
- userId: Int,
+ user: UserHandle,
userRestriction: String?
): DisabledByPolicyInteractor.PolicyResult = policyResult
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeQSTileDataInteractor.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeQSTileDataInteractor.kt
index 55935961466d..2b3330f3a33b 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeQSTileDataInteractor.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/qs/tiles/base/interactor/FakeQSTileDataInteractor.kt
@@ -16,6 +16,7 @@
package com.android.systemui.qs.tiles.base.interactor
+import android.os.UserHandle
import javax.annotation.CheckReturnValue
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
@@ -38,16 +39,16 @@ class FakeQSTileDataInteractor<T>(
fun tryEmitAvailability(isAvailable: Boolean): Boolean = availabilityFlow.tryEmit(isAvailable)
suspend fun emitAvailability(isAvailable: Boolean) = availabilityFlow.emit(isAvailable)
- override fun tileData(userId: Int, triggers: Flow<DataUpdateTrigger>): Flow<T> {
- mutableDataRequests.add(DataRequest(userId))
+ override fun tileData(user: UserHandle, triggers: Flow<DataUpdateTrigger>): Flow<T> {
+ mutableDataRequests.add(DataRequest(user))
return triggers.flatMapLatest { dataFlow }
}
- override fun availability(userId: Int): Flow<Boolean> {
- mutableAvailabilityRequests.add(AvailabilityRequest(userId))
+ override fun availability(user: UserHandle): Flow<Boolean> {
+ mutableAvailabilityRequests.add(AvailabilityRequest(user))
return availabilityFlow
}
- data class DataRequest(val userId: Int)
- data class AvailabilityRequest(val userId: Int)
+ data class DataRequest(val user: UserHandle)
+ data class AvailabilityRequest(val user: UserHandle)
}