Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 690f1204 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Fix issue with auto-adding work tile

When a work profile is created, it is first created as disabled, and
then enabled when it's verified (all this done by DPM).

ManagedProfileControllerImpl, which is what WorkModeTile uses to verify
that there's a work profile available, only returns true if there's an
Enabled work profile. However, WorkTileAutoAddable was adding the tile
when the profile was created, regardless of the enabled state. This made
it so the tile was immediately destroyed if auto-added.

With this change, we explicitly require in WorkTileAutoAddable that the
profile is enabled, matching what ManagedProfileControllerImpl does and
also the correct behavior. UserTracker will send a profiles changed both
when the profile is added as disabled and when it's enabled, so that is
not a problem.

Test: atest WorkTileAutoAddableTest
Test: manual, create a work profile first as disabled and then enable it
Flag: ACONFIG com.android.systemui.qs_new_pipeline NEXTFOOD
Fixes: 325595352
Change-Id: Ib741135315e7a4787049129ba2918bd68bc7484b
parent 26e89044
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.qs.pipeline.domain.autoaddable

import android.content.pm.UserInfo
import android.content.pm.UserInfo.FLAG_DISABLED
import android.content.pm.UserInfo.FLAG_FULL
import android.content.pm.UserInfo.FLAG_MANAGED_PROFILE
import android.content.pm.UserInfo.FLAG_PRIMARY
@@ -73,14 +74,14 @@ class WorkTileAutoAddableTest : SysuiTestCase() {
    fun changeInProfiles_hasManagedProfile_sendsAddSignal() = runTest {
        val signal by collectLastValue(underTest.autoAddSignal(0))

        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK), selectedUserIndex = 0)
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK_ENABLED), selectedUserIndex = 0)

        assertThat(signal).isEqualTo(AutoAddSignal.Add(SPEC))
    }

    @Test
    fun changeInProfiles_noManagedProfile_sendsRemoveSignal() = runTest {
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK), selectedUserIndex = 0)
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK_ENABLED), selectedUserIndex = 0)

        val signal by collectLastValue(underTest.autoAddSignal(0))

@@ -89,9 +90,18 @@ class WorkTileAutoAddableTest : SysuiTestCase() {
        assertThat(signal).isEqualTo(AutoAddSignal.Remove(SPEC))
    }

    @Test
    fun changeInProfile_hasDisabledManagedProfile_noAddSignal() = runTest {
        val signal by collectLastValue(underTest.autoAddSignal(0))

        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK_DISABLED), selectedUserIndex = 0)

        assertThat(signal).isNotInstanceOf(AutoAddSignal.Add::class.java)
    }

    @Test
    fun startingWithManagedProfile_sendsAddSignal() = runTest {
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK), selectedUserIndex = 0)
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK_ENABLED), selectedUserIndex = 0)

        val signal by collectLastValue(underTest.autoAddSignal(0))

@@ -102,14 +112,14 @@ class WorkTileAutoAddableTest : SysuiTestCase() {
    fun userChangeToUserWithProfile_noSignalForOriginalUser() = runTest {
        val signal by collectLastValue(underTest.autoAddSignal(0))

        userTracker.set(listOf(USER_INFO_1, USER_INFO_WORK), selectedUserIndex = 0)
        userTracker.set(listOf(USER_INFO_1, USER_INFO_WORK_ENABLED), selectedUserIndex = 0)

        assertThat(signal).isNotEqualTo(AutoAddSignal.Add(SPEC))
    }

    @Test
    fun userChangeToUserWithoutProfile_noSignalForOriginalUser() = runTest {
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK), selectedUserIndex = 0)
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK_ENABLED), selectedUserIndex = 0)
        val signal by collectLastValue(underTest.autoAddSignal(0))

        userTracker.set(listOf(USER_INFO_1), selectedUserIndex = 0)
@@ -137,7 +147,7 @@ class WorkTileAutoAddableTest : SysuiTestCase() {

    @Test
    fun restoreDataWithWorkTile_currentlyManagedProfile_doesntTriggerRemove() = runTest {
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK), selectedUserIndex = 0)
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK_ENABLED), selectedUserIndex = 0)
        val userId = 0
        val signals by collectValues(underTest.autoAddSignal(userId))
        runCurrent()
@@ -164,7 +174,7 @@ class WorkTileAutoAddableTest : SysuiTestCase() {

    @Test
    fun restoreDataWithoutWorkTile_managedProfile_doesntTriggerRemove() = runTest {
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK), selectedUserIndex = 0)
        userTracker.set(listOf(USER_INFO_0, USER_INFO_WORK_ENABLED), selectedUserIndex = 0)
        val userId = 0
        val signals by collectValues(underTest.autoAddSignal(userId))
        runCurrent()
@@ -180,7 +190,9 @@ class WorkTileAutoAddableTest : SysuiTestCase() {
        private val SPEC = TileSpec.create(WorkModeTile.TILE_SPEC)
        private val USER_INFO_0 = UserInfo(0, "", FLAG_PRIMARY or FLAG_FULL)
        private val USER_INFO_1 = UserInfo(1, "", FLAG_FULL)
        private val USER_INFO_WORK = UserInfo(10, "", FLAG_PROFILE or FLAG_MANAGED_PROFILE)
        private val USER_INFO_WORK_DISABLED =
            UserInfo(10, "", FLAG_PROFILE or FLAG_MANAGED_PROFILE or FLAG_DISABLED)
        private val USER_INFO_WORK_ENABLED = UserInfo(10, "", FLAG_PROFILE or FLAG_MANAGED_PROFILE)

        private fun createRestoreWithWorkTile(userId: Int): RestoreData {
            return RestoreData(
+2 −1
Original line number Diff line number Diff line
@@ -64,7 +64,8 @@ constructor(
            fun maybeSend(profiles: List<UserInfo>) {
                if (profiles.any { it.id == userId }) {
                    // We are looking at the profiles of the correct user.
                    if (profiles.any { it.isManagedProfile }) {
                    // They need to be a managed enabled profile.
                    if (profiles.any { it.isManagedProfile && it.isEnabled }) {
                        trySend(
                            AutoAddSignal.Add(
                                spec,
+3 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ interface UserTracker : UserContentResolverProvider, UserContextProvider {
     * List of profiles associated with the current user.
     *
     * Quiet work profiles will still appear here, but will have the `QUIET_MODE` flag.
     *
     * Disabled work profiles will also appear here. Listeners will be notified when profiles go
     * from disabled to enabled (as UserInfo are immutable) with the updated list.
     */
    val userProfiles: List<UserInfo>