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

Commit e49a1452 authored by Nate Myren's avatar Nate Myren
Browse files

Granted, ECM restricted settings should not be labeled as restricted

It is possible for an ECM restricted setting to also be granted. In this
case, the setting should be able to be toggled off, and the subheadings
should properly reflect the state.

Bug: 390196024
Test: atest RestrictedSwitchPreferenceTest
Flag: EXEMPT: minor bugfix
Change-Id: Ic2bd94bfafc1f7c39965a9818ba5484047e4d223
parent bba20c69
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import kotlinx.coroutines.flow.flowOn
data class EnhancedConfirmation(
    val key: String,
    val packageName: String,
    val isRestrictedSettingAllowed: Boolean?
)
data class Restrictions(
    val userId: Int = UserHandle.myUserId(),
@@ -92,6 +93,9 @@ internal class RestrictionsProviderImpl(
        }

        restrictions.enhancedConfirmation?.let { ec ->
            if (ec.isRestrictedSettingAllowed == true) {
                return NoRestricted
            }
            RestrictedLockUtilsInternal
                    .checkIfRequiresEnhancedConfirmation(context, ec.key,
                        ec.packageName)
+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ internal fun <T : AppRecord> TogglePermissionAppListModel<T>.TogglePermissionApp
        }
        RestrictedSwitchPreference(
            model = switchModel,
            restrictions = getRestrictions(userId, packageName),
            restrictions = getRestrictions(userId, packageName, isAllowed()),
            ifBlockedByAdminOverrideCheckedValueTo = switchifBlockedByAdminOverrideCheckedValueTo,
            restrictionsProviderFactory = restrictionsProviderFactory,
        )
+4 −1
Original line number Diff line number Diff line
@@ -116,12 +116,15 @@ fun <T : AppRecord> TogglePermissionAppListModel<T>.isChangeableWithSystemUidChe
fun <T : AppRecord> TogglePermissionAppListModel<T>.getRestrictions(
    userId: Int,
    packageName: String,
    isRestrictedSettingAllowed: Boolean?
) =
    Restrictions(
        userId = userId,
        keys = switchRestrictionKeys,
        enhancedConfirmation =
            enhancedConfirmationKey?.let { key -> EnhancedConfirmation(key, packageName) },
            enhancedConfirmationKey?.let {
                key -> EnhancedConfirmation(key, packageName, isRestrictedSettingAllowed)
                                         },
    )

interface TogglePermissionAppListProvider {
+2 −1
Original line number Diff line number Diff line
@@ -149,13 +149,14 @@ internal class TogglePermissionInternalAppListModel<T : AppRecord>(

    @Composable
    fun getSummary(record: T): () -> String {
        val allowed = listModel.isAllowed(record)
        val restrictions =
            listModel.getRestrictions(
                userId = record.app.userId,
                packageName = record.app.packageName,
                allowed()
            )
        val restrictedMode by restrictionsProviderFactory.rememberRestrictedMode(restrictions)
        val allowed = listModel.isAllowed(record)
        return RestrictedSwitchPreferenceModel.getSummary(
            context = context,
            summaryIfNoRestricted = { getSummaryIfNoRestricted(allowed()) },