Loading packages/SystemUI/src/com/android/systemui/supervision/data/repository/SupervisionRepository.kt +13 −1 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.systemui.supervision.data.repository import android.annotation.SuppressLint import android.annotation.WorkerThread import android.app.admin.DevicePolicyManager import android.app.role.RoleManager import android.app.supervision.SupervisionManager import android.app.supervision.SupervisionManager.SupervisionListener import android.content.ComponentName import android.content.Context import android.content.pm.UserInfo import android.os.UserHandle Loading Loading @@ -57,6 +59,7 @@ constructor( supervisionManagerProvider: Provider<SupervisionManager>, userRepository: UserRepository, private val roleManager: RoleManager, private val devicePolicyManager: DevicePolicyManager, @Application private val context: Context, @Background private val backgroundDispatcher: CoroutineDispatcher, ) : SupervisionRepository { Loading Loading @@ -88,9 +91,18 @@ constructor( roleManager.getRoleHoldersAsUser(RoleManager.ROLE_SYSTEM_SUPERVISION, userHandle) val supervisionRoleHolders = roleManager.getRoleHoldersAsUser(RoleManager.ROLE_SUPERVISION, userHandle) val po = devicePolicyManager.getProfileOwnerAsUser(userHandle) val defaultSupervisionComponent = ComponentName.unflattenFromString( context.getString( com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent ) ) val isSupervisionProfileOwner = po != null && po == defaultSupervisionComponent val isOnDeviceSupervision = systemSupervisionRoleHolders.isNotEmpty() && systemSupervisionRoleHolders.none { supervisionRoleHolders.contains(it) } systemSupervisionRoleHolders.none { supervisionRoleHolders.contains(it) } && !isSupervisionProfileOwner return if (isOnDeviceSupervision) { SupervisionModel( Loading packages/SystemUI/tests/src/com/android/systemui/supervision/data/repository/SupervisionRepositoryImplTest.kt +62 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,12 @@ package com.android.systemui.supervision.data.repository import android.app.admin.DevicePolicyManager import android.app.admin.devicePolicyManager import android.app.role.RoleManager import android.app.role.roleManager import android.app.supervision.SupervisionManager import android.content.ComponentName import android.os.UserHandle import android.platform.test.flag.junit.SetFlagsRule import androidx.test.ext.junit.runners.AndroidJUnit4 Loading Loading @@ -65,6 +68,7 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { private val testScope = kosmos.testScope private val roleManager: RoleManager = kosmos.roleManager private val supervisionManager: SupervisionManager = kosmos.supervisionManager private val devicePolicyManager: DevicePolicyManager = kosmos.devicePolicyManager private val userRepository: FakeUserRepository = kosmos.fakeUserRepository private val supervisionListenerCaptor = argumentCaptor<SupervisionManager.SupervisionListener>() Loading @@ -77,6 +81,7 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { roleManager = roleManager, supervisionManagerProvider = { supervisionManager }, userRepository = userRepository, devicePolicyManager = devicePolicyManager, context = context, backgroundDispatcher = kosmos.testDispatcher, ) Loading Loading @@ -206,6 +211,60 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { ) } @Test fun getProperties_isSupervisionProfileOwner_returnsParentalControlsResources() = testScope.runTest { val currentSupervisionModel by collectLastValue(underTest.supervision) assertNotNull(currentSupervisionModel) verify(supervisionManager) .registerSupervisionListener(supervisionListenerCaptor.capture()) verify(supervisionManager).isSupervisionEnabledForUser(eq(USER_ID)) whenever( roleManager.getRoleHoldersAsUser( eq(RoleManager.ROLE_SYSTEM_SUPERVISION), eq(UserHandle.of(USER_ID)), ) ) .thenReturn(listOf(SYSTEM_SUPERVISION_APP_PACKAGE_NAME)) whenever( roleManager.getRoleHoldersAsUser( eq(RoleManager.ROLE_SUPERVISION), eq(UserHandle.of(USER_ID)), ) ) .thenReturn(listOf(SUPERVISION_APP_PACKAGE_NAME)) whenever(devicePolicyManager.getProfileOwnerAsUser(eq(UserHandle.of(USER_ID)))) .thenReturn(SUPERVISION_COMPONENT) context .getOrCreateTestableResources() .addOverride( com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent, SUPERVISION_COMPONENT_STR, ) supervisionListenerCaptor.lastValue.onSupervisionEnabled(USER_ID) val expectedLabel = context.getString(R.string.status_bar_supervision) val expectedIcon = context.getDrawable(R.drawable.ic_supervision) val expectedDisclaimerText = context.getString(R.string.monitoring_description_parental_controls) val expectedFooterText = context.getString(R.string.quick_settings_disclosure_parental_controls) assertEquals(expectedLabel, currentSupervisionModel!!.label) assertTrue(currentSupervisionModel!!.icon.toBitmap()!!.sameAs(expectedIcon.toBitmap())) assertEquals(expectedDisclaimerText, currentSupervisionModel!!.disclaimerText) assertEquals(expectedFooterText, currentSupervisionModel!!.footerText) verify(roleManager) .getRoleHoldersAsUser(eq(RoleManager.ROLE_SUPERVISION), eq(UserHandle.of(USER_ID))) verify(roleManager) .getRoleHoldersAsUser( eq(RoleManager.ROLE_SYSTEM_SUPERVISION), eq(UserHandle.of(USER_ID)), ) } @Test fun getProperties_supervisionIsDisabled_returnsNull() = testScope.runTest { Loading Loading @@ -243,6 +302,9 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { const val USER_ID = FakeUserRepository.DEFAULT_SELECTED_USER const val SYSTEM_SUPERVISION_APP_PACKAGE_NAME = "com.abc.xyz.SystemSupervisionApp" const val SUPERVISION_APP_PACKAGE_NAME = "com.abc.xyz.SupervisionApp" const val SUPERVISION_COMPONENT_STR = "com.google.android.gms/.kids.account.receiver.ProfileOwnerReceiver" val SUPERVISION_COMPONENT = ComponentName.unflattenFromString(SUPERVISION_COMPONENT_STR) val USER_HANDLE: UserHandle = UserHandle.of(FakeUserRepository.DEFAULT_SELECTED_USER) } } packages/SystemUI/tests/utils/src/com/android/systemui/qs/footer/FooterActionsTestUtils.kt +3 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.qs.footer import android.app.admin.DevicePolicyManager import android.app.role.RoleManager import android.app.supervision.SupervisionManager import android.content.Context Loading Loading @@ -189,6 +190,7 @@ class FooterActionsTestUtils( private fun supervisionRepository( roleManager: RoleManager = mock(), supervisionManager: SupervisionManager = mock(), devicePolicyManager: DevicePolicyManager = mock(), userRepository: UserRepository = FakeUserRepository(), @Application context: Context = this.context.applicationContext, bgDispatcher: CoroutineDispatcher = StandardTestDispatcher(scheduler), Loading @@ -197,6 +199,7 @@ class FooterActionsTestUtils( { supervisionManager }, userRepository, roleManager, devicePolicyManager, context, bgDispatcher, ) Loading packages/SystemUI/tests/utils/src/com/android/systemui/supervision/data/repository/SupervisionRepositoryKosmos.kt +2 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.supervision.data.repository import android.app.admin.devicePolicyManager import android.app.role.roleManager import android.content.applicationContext import com.android.systemui.kosmos.Kosmos Loading @@ -29,6 +30,7 @@ var Kosmos.supervisionRepository by roleManager = roleManager, supervisionManagerProvider = { supervisionManager }, userRepository = userRepository, devicePolicyManager = devicePolicyManager, context = applicationContext, backgroundDispatcher = testDispatcher, ) Loading Loading
packages/SystemUI/src/com/android/systemui/supervision/data/repository/SupervisionRepository.kt +13 −1 Original line number Diff line number Diff line Loading @@ -18,9 +18,11 @@ package com.android.systemui.supervision.data.repository import android.annotation.SuppressLint import android.annotation.WorkerThread import android.app.admin.DevicePolicyManager import android.app.role.RoleManager import android.app.supervision.SupervisionManager import android.app.supervision.SupervisionManager.SupervisionListener import android.content.ComponentName import android.content.Context import android.content.pm.UserInfo import android.os.UserHandle Loading Loading @@ -57,6 +59,7 @@ constructor( supervisionManagerProvider: Provider<SupervisionManager>, userRepository: UserRepository, private val roleManager: RoleManager, private val devicePolicyManager: DevicePolicyManager, @Application private val context: Context, @Background private val backgroundDispatcher: CoroutineDispatcher, ) : SupervisionRepository { Loading Loading @@ -88,9 +91,18 @@ constructor( roleManager.getRoleHoldersAsUser(RoleManager.ROLE_SYSTEM_SUPERVISION, userHandle) val supervisionRoleHolders = roleManager.getRoleHoldersAsUser(RoleManager.ROLE_SUPERVISION, userHandle) val po = devicePolicyManager.getProfileOwnerAsUser(userHandle) val defaultSupervisionComponent = ComponentName.unflattenFromString( context.getString( com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent ) ) val isSupervisionProfileOwner = po != null && po == defaultSupervisionComponent val isOnDeviceSupervision = systemSupervisionRoleHolders.isNotEmpty() && systemSupervisionRoleHolders.none { supervisionRoleHolders.contains(it) } systemSupervisionRoleHolders.none { supervisionRoleHolders.contains(it) } && !isSupervisionProfileOwner return if (isOnDeviceSupervision) { SupervisionModel( Loading
packages/SystemUI/tests/src/com/android/systemui/supervision/data/repository/SupervisionRepositoryImplTest.kt +62 −0 Original line number Diff line number Diff line Loading @@ -16,9 +16,12 @@ package com.android.systemui.supervision.data.repository import android.app.admin.DevicePolicyManager import android.app.admin.devicePolicyManager import android.app.role.RoleManager import android.app.role.roleManager import android.app.supervision.SupervisionManager import android.content.ComponentName import android.os.UserHandle import android.platform.test.flag.junit.SetFlagsRule import androidx.test.ext.junit.runners.AndroidJUnit4 Loading Loading @@ -65,6 +68,7 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { private val testScope = kosmos.testScope private val roleManager: RoleManager = kosmos.roleManager private val supervisionManager: SupervisionManager = kosmos.supervisionManager private val devicePolicyManager: DevicePolicyManager = kosmos.devicePolicyManager private val userRepository: FakeUserRepository = kosmos.fakeUserRepository private val supervisionListenerCaptor = argumentCaptor<SupervisionManager.SupervisionListener>() Loading @@ -77,6 +81,7 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { roleManager = roleManager, supervisionManagerProvider = { supervisionManager }, userRepository = userRepository, devicePolicyManager = devicePolicyManager, context = context, backgroundDispatcher = kosmos.testDispatcher, ) Loading Loading @@ -206,6 +211,60 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { ) } @Test fun getProperties_isSupervisionProfileOwner_returnsParentalControlsResources() = testScope.runTest { val currentSupervisionModel by collectLastValue(underTest.supervision) assertNotNull(currentSupervisionModel) verify(supervisionManager) .registerSupervisionListener(supervisionListenerCaptor.capture()) verify(supervisionManager).isSupervisionEnabledForUser(eq(USER_ID)) whenever( roleManager.getRoleHoldersAsUser( eq(RoleManager.ROLE_SYSTEM_SUPERVISION), eq(UserHandle.of(USER_ID)), ) ) .thenReturn(listOf(SYSTEM_SUPERVISION_APP_PACKAGE_NAME)) whenever( roleManager.getRoleHoldersAsUser( eq(RoleManager.ROLE_SUPERVISION), eq(UserHandle.of(USER_ID)), ) ) .thenReturn(listOf(SUPERVISION_APP_PACKAGE_NAME)) whenever(devicePolicyManager.getProfileOwnerAsUser(eq(UserHandle.of(USER_ID)))) .thenReturn(SUPERVISION_COMPONENT) context .getOrCreateTestableResources() .addOverride( com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent, SUPERVISION_COMPONENT_STR, ) supervisionListenerCaptor.lastValue.onSupervisionEnabled(USER_ID) val expectedLabel = context.getString(R.string.status_bar_supervision) val expectedIcon = context.getDrawable(R.drawable.ic_supervision) val expectedDisclaimerText = context.getString(R.string.monitoring_description_parental_controls) val expectedFooterText = context.getString(R.string.quick_settings_disclosure_parental_controls) assertEquals(expectedLabel, currentSupervisionModel!!.label) assertTrue(currentSupervisionModel!!.icon.toBitmap()!!.sameAs(expectedIcon.toBitmap())) assertEquals(expectedDisclaimerText, currentSupervisionModel!!.disclaimerText) assertEquals(expectedFooterText, currentSupervisionModel!!.footerText) verify(roleManager) .getRoleHoldersAsUser(eq(RoleManager.ROLE_SUPERVISION), eq(UserHandle.of(USER_ID))) verify(roleManager) .getRoleHoldersAsUser( eq(RoleManager.ROLE_SYSTEM_SUPERVISION), eq(UserHandle.of(USER_ID)), ) } @Test fun getProperties_supervisionIsDisabled_returnsNull() = testScope.runTest { Loading Loading @@ -243,6 +302,9 @@ class SupervisionRepositoryImplTest : SysuiTestCase() { const val USER_ID = FakeUserRepository.DEFAULT_SELECTED_USER const val SYSTEM_SUPERVISION_APP_PACKAGE_NAME = "com.abc.xyz.SystemSupervisionApp" const val SUPERVISION_APP_PACKAGE_NAME = "com.abc.xyz.SupervisionApp" const val SUPERVISION_COMPONENT_STR = "com.google.android.gms/.kids.account.receiver.ProfileOwnerReceiver" val SUPERVISION_COMPONENT = ComponentName.unflattenFromString(SUPERVISION_COMPONENT_STR) val USER_HANDLE: UserHandle = UserHandle.of(FakeUserRepository.DEFAULT_SELECTED_USER) } }
packages/SystemUI/tests/utils/src/com/android/systemui/qs/footer/FooterActionsTestUtils.kt +3 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.qs.footer import android.app.admin.DevicePolicyManager import android.app.role.RoleManager import android.app.supervision.SupervisionManager import android.content.Context Loading Loading @@ -189,6 +190,7 @@ class FooterActionsTestUtils( private fun supervisionRepository( roleManager: RoleManager = mock(), supervisionManager: SupervisionManager = mock(), devicePolicyManager: DevicePolicyManager = mock(), userRepository: UserRepository = FakeUserRepository(), @Application context: Context = this.context.applicationContext, bgDispatcher: CoroutineDispatcher = StandardTestDispatcher(scheduler), Loading @@ -197,6 +199,7 @@ class FooterActionsTestUtils( { supervisionManager }, userRepository, roleManager, devicePolicyManager, context, bgDispatcher, ) Loading
packages/SystemUI/tests/utils/src/com/android/systemui/supervision/data/repository/SupervisionRepositoryKosmos.kt +2 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.supervision.data.repository import android.app.admin.devicePolicyManager import android.app.role.roleManager import android.content.applicationContext import com.android.systemui.kosmos.Kosmos Loading @@ -29,6 +30,7 @@ var Kosmos.supervisionRepository by roleManager = roleManager, supervisionManagerProvider = { supervisionManager }, userRepository = userRepository, devicePolicyManager = devicePolicyManager, context = applicationContext, backgroundDispatcher = testDispatcher, ) Loading