commit 9fac3454a3bf9c06ae27a5a6c63f7d6af0b5b784 parent dbc1cfe4c79e848675b957fab79984f247db2355 Author: sarah541 <sarahkhan1107@hotmail.com> Date: Thu, 13 Nov 2025 18:10:45 +0000 Bug 1988705 - Disable ETP from Unifed Trust Panel if it's globally disabled r=android-reviewers,petru Differential Revision: https://phabricator.services.mozilla.com/D267869 Diffstat:
4 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/compose/MenuItem.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/compose/MenuItem.kt @@ -40,10 +40,12 @@ import androidx.compose.ui.semantics.collectionItemInfo import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.semantics.disabled import androidx.compose.ui.semantics.role +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.unit.dp +import mozilla.components.compose.base.modifier.thenConditional import mozilla.components.compose.base.theme.surfaceDimVariant import org.mozilla.fenix.R import org.mozilla.fenix.components.menu.MenuDialogTestTag.WEB_EXTENSION_ITEM @@ -289,6 +291,7 @@ internal fun MenuBadgeItem( description: String, badgeText: String, checked: Boolean, + enabled: Boolean = true, modifier: Modifier = Modifier, onClick: () -> Unit, ) { @@ -305,10 +308,16 @@ internal fun MenuBadgeItem( Row( modifier = modifier - .clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = LocalIndication.current, - ) { onClick() } + .thenConditional( + Modifier.clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = LocalIndication.current, + ) { onClick() }, + ) { enabled } + .thenConditional( + Modifier.semantics { disabled() }, + ) { !enabled } + .semantics { disabled() } .clip(shape = ROUNDED_CORNER_SHAPE) .background( color = MaterialTheme.colorScheme.surfaceDimVariant, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/trustpanel/TrustPanelFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/trustpanel/TrustPanelFragment.kt @@ -195,6 +195,7 @@ class TrustPanelFragment : BottomSheetDialogFragment() { val websitePermissions by store.observeAsState(initialValue = listOf()) { state -> state.websitePermissionsState.values } + val isGlobalTrackingProtectionEnabled = settings.shouldUseTrackingProtection permissionsCallback = { isGranted: Map<String, Boolean> -> if (isGranted.values.all { it }) { @@ -261,6 +262,7 @@ class TrustPanelFragment : BottomSheetDialogFragment() { websiteInfoState = store.state.websiteInfoState, icon = sessionState?.content?.icon, isTrackingProtectionEnabled = isTrackingProtectionEnabled, + isGlobalTrackingProtectionEnabled = isGlobalTrackingProtectionEnabled, isLocalPdf = args.isLocalPdf, numberOfTrackersBlocked = numberOfTrackersBlocked, websitePermissions = websitePermissions.filter { it.isVisible }, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/trustpanel/store/TrustPanelState.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/trustpanel/store/TrustPanelState.kt @@ -20,7 +20,7 @@ typealias WebsitePermissionsState = Map<PhoneFeature, WebsitePermission> * Value type that represents the state of the unified trust panel. * * @property baseDomain The base domain of the current site used to display the clear site data dialog. - * @property isTrackingProtectionEnabled Flag indicating whether enhanced tracking protection is enabled. + * @property isTrackingProtectionEnabled Flag indicating whether enhanced tracking protection is enabled for a site. * @property numberOfTrackersBlocked The numbers of trackers blocked by enhanced tracking protection. * @property bucketedTrackers Mapping of trackers sorted into different tracking protection categories. * @property detailedTrackerCategory The [TrackingProtectionCategory] which will be shown in the tracker diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/trustpanel/ui/ProtectionPanel.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/trustpanel/ui/ProtectionPanel.kt @@ -78,6 +78,7 @@ internal fun ProtectionPanel( websiteInfoState: WebsiteInfoState, icon: Bitmap?, isTrackingProtectionEnabled: Boolean, + isGlobalTrackingProtectionEnabled: Boolean, isLocalPdf: Boolean, numberOfTrackersBlocked: Int, websitePermissions: List<WebsitePermission>, @@ -88,6 +89,7 @@ internal fun ProtectionPanel( onAutoplayValueClick: (AutoplayValue) -> Unit, onToggleablePermissionClick: (WebsitePermission.Toggleable) -> Unit, ) { + val isSiteProtectionEnabled = isTrackingProtectionEnabled && isGlobalTrackingProtectionEnabled MenuScaffold( header = { ProtectionPanelHeader( @@ -99,27 +101,29 @@ internal fun ProtectionPanel( MenuGroup { ProtectionPanelBanner( isSecured = websiteInfoState.isSecured || isLocalPdf, - isTrackingProtectionEnabled = isTrackingProtectionEnabled || isLocalPdf, + isTrackingProtectionEnabled = isGlobalTrackingProtectionEnabled && + (isTrackingProtectionEnabled || isLocalPdf), ) if (!isLocalPdf) { MenuBadgeItem( label = stringResource(id = R.string.protection_panel_etp_toggle_label), - checked = isTrackingProtectionEnabled, - description = if (isTrackingProtectionEnabled) { + checked = isTrackingProtectionEnabled && isGlobalTrackingProtectionEnabled, + description = if (isTrackingProtectionEnabled && isGlobalTrackingProtectionEnabled) { stringResource(id = R.string.protection_panel_etp_toggle_enabled_description_2) } else { stringResource(id = R.string.protection_panel_etp_toggle_disabled_description_2) }, - badgeText = if (isTrackingProtectionEnabled) { + badgeText = if (isSiteProtectionEnabled) { stringResource(id = R.string.protection_panel_etp_toggle_on) } else { stringResource(id = R.string.protection_panel_etp_toggle_off) }, + enabled = (isSiteProtectionEnabled), onClick = onTrackingProtectionToggleClick, ) - if (!isTrackingProtectionEnabled) { + if (!(isSiteProtectionEnabled)) { MenuItem( label = stringResource(id = R.string.protection_panel_etp_disabled_no_trackers_blocked), beforeIconPainter = painterResource(id = iconsR.drawable.mozac_ic_shield_slash_critical_24), @@ -440,6 +444,7 @@ private fun ProtectionPanelPreview() { ), icon = null, isTrackingProtectionEnabled = true, + isGlobalTrackingProtectionEnabled = true, isLocalPdf = false, numberOfTrackersBlocked = 5, websitePermissions = listOf(