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

Commit f0ed0127 authored by Hani Kazmi's avatar Hani Kazmi Committed by Android (Google) Code Review
Browse files

Merge changes from topics "ecm-manager", "ecm-tests" into main

* changes:
  Replace ECM AppOps call with service
  Wired remaining SpecialAppAccess for ECM.
parents 86aee184 1f255895
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -219,7 +219,6 @@ public class RestrictedLockUtils {
        }
    }


    /**
     * Shows restricted setting dialog.
     *
+1 −2
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import kotlinx.coroutines.flow.flowOn

data class EnhancedConfirmation(
    val key: String,
    val uid: Int,
    val packageName: String,
)
data class Restrictions(
@@ -91,7 +90,7 @@ internal class RestrictionsProviderImpl(
        restrictions.enhancedConfirmation?.let { ec ->
            RestrictedLockUtilsInternal
                    .checkIfRequiresEnhancedConfirmation(context, ec.key,
                        ec.uid, ec.packageName)
                        ec.packageName)
                    ?.let { intent -> return BlockedByEcmImpl(context = context, intent = intent) }
        }

+0 −1
Original line number Diff line number Diff line
@@ -159,7 +159,6 @@ internal fun <T : AppRecord> TogglePermissionAppListModel<T>.TogglePermissionApp
            keys = switchRestrictionKeys,
            enhancedConfirmation = enhancedConfirmationKey?.let { EnhancedConfirmation(
                key = it,
                uid = checkNotNull(applicationInfo).uid,
                packageName = packageName) })
        RestrictedSwitchPreference(switchModel, restrictions, restrictionsProviderFactory)
        InfoPageAdditionalContent(record, isAllowed)
+1 −3
Original line number Diff line number Diff line
@@ -150,15 +150,13 @@ internal class TogglePermissionInternalAppListModel<T : AppRecord>(

    @Composable
    fun getSummary(record: T): () -> String {
        val restrictions = remember(record.app.userId,
                record.app.uid, record.app.packageName) {
        val restrictions = remember(record.app.userId, record.app.packageName) {
            Restrictions(
                userId = record.app.userId,
                keys = listModel.switchRestrictionKeys,
                enhancedConfirmation = listModel.enhancedConfirmationKey?.let {
                    EnhancedConfirmation(
                        key = it,
                        uid = record.app.uid,
                        packageName = record.app.packageName)
                })
        }
+25 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.settingslib.spaprivileged.model.enterprise.BaseUserRestricted
import com.android.settingslib.spaprivileged.model.enterprise.NoRestricted
import com.android.settingslib.spaprivileged.model.enterprise.Restrictions
import com.android.settingslib.spaprivileged.tests.testutils.FakeBlockedByAdmin
import com.android.settingslib.spaprivileged.tests.testutils.FakeBlockedByEcm
import com.android.settingslib.spaprivileged.tests.testutils.FakeRestrictionsProvider
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
@@ -44,6 +45,7 @@ class RestrictedSwitchPreferenceTest {
    val composeTestRule = createComposeRule()

    private val fakeBlockedByAdmin = FakeBlockedByAdmin()
    private val fakeBlockedByEcm = FakeBlockedByEcm()

    private val fakeRestrictionsProvider = FakeRestrictionsProvider()

@@ -141,6 +143,29 @@ class RestrictedSwitchPreferenceTest {
        assertThat(fakeBlockedByAdmin.sendShowAdminSupportDetailsIntentIsCalled).isTrue()
    }

    @Test
    fun whenBlockedByEcm_disabled() {
        val restrictions = Restrictions(userId = USER_ID, keys = listOf(RESTRICTION_KEY))
        fakeRestrictionsProvider.restrictedMode = fakeBlockedByEcm

        setContent(restrictions)

        composeTestRule.onNodeWithText(TITLE).assertIsDisplayed().assertIsEnabled()
        composeTestRule.onNodeWithText(FakeBlockedByEcm.SUMMARY).assertIsDisplayed()
        composeTestRule.onNode(isOn()).assertIsDisplayed()
    }

    @Test
    fun whenBlockedByEcm_click() {
        val restrictions = Restrictions(userId = USER_ID, keys = listOf(RESTRICTION_KEY))
        fakeRestrictionsProvider.restrictedMode = fakeBlockedByEcm

        setContent(restrictions)
        composeTestRule.onRoot().performClick()

        assertThat(fakeBlockedByEcm.showRestrictedSettingsDetailsIsCalled).isTrue()
    }

    private fun setContent(restrictions: Restrictions) {
        composeTestRule.setContent {
            RestrictedSwitchPreference(switchPreferenceModel, restrictions) { _, _ ->
Loading