2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/5636 - Unregisters wifiConnectedListener when setting changes, sets default blocked

This commit is contained in:
ekager 2020-06-22 21:41:28 -04:00 committed by Emily Kager
parent f93119660c
commit 34b326f313
2 changed files with 21 additions and 6 deletions

View File

@ -184,7 +184,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
AUTOPLAY_ALLOW_ALL, AUTOPLAY_ALLOW_ALL,
AUTOPLAY_ALLOW_ON_WIFI -> { AUTOPLAY_ALLOW_ON_WIFI -> {
settings.setAutoplayUserSetting(AUTOPLAY_ALLOW_ON_WIFI) settings.setAutoplayUserSetting(AUTOPLAY_ALLOW_ON_WIFI)
return BLOCKED to BLOCKED
} }
AUTOPLAY_BLOCK_AUDIBLE -> BLOCKED to ALLOWED AUTOPLAY_BLOCK_AUDIBLE -> BLOCKED to ALLOWED
AUTOPLAY_BLOCK_ALL -> BLOCKED to BLOCKED AUTOPLAY_BLOCK_ALL -> BLOCKED to BLOCKED

View File

@ -21,15 +21,26 @@ class SitePermissionsWifiIntegration(
) : LifecycleAwareFeature { ) : LifecycleAwareFeature {
/** /**
* Adds listener for autplay setting [AUTOPLAY_ALLOW_ON_WIFI]. Sets all autoplay to allowed when * Adds listener for autoplay setting [AUTOPLAY_ALLOW_ON_WIFI]. Sets all autoplay to allowed when
* WIFI is connected, blocked otherwise. * WIFI is connected, blocked otherwise.
*/ */
private val wifiConnectedListener: ((Boolean) -> Unit) by lazy { private val wifiConnectedListener: ((Boolean) -> Unit) by lazy {
{ connected: Boolean -> { connected: Boolean ->
val setting = val setting =
if (connected) SitePermissionsRules.Action.ALLOWED else SitePermissionsRules.Action.BLOCKED if (connected) SitePermissionsRules.Action.ALLOWED else SitePermissionsRules.Action.BLOCKED
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.AUTOPLAY_AUDIBLE, setting) if (settings.getAutoplayUserSetting(default = AUTOPLAY_BLOCK_ALL) == AUTOPLAY_ALLOW_ON_WIFI) {
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.AUTOPLAY_INAUDIBLE, setting) settings.setSitePermissionsPhoneFeatureAction(
PhoneFeature.AUTOPLAY_AUDIBLE,
setting
)
settings.setSitePermissionsPhoneFeatureAction(
PhoneFeature.AUTOPLAY_INAUDIBLE,
setting
)
} else {
// The autoplay setting has changed, we can remove the listener
removeWifiConnectedListener()
}
} }
} }
@ -55,7 +66,11 @@ class SitePermissionsWifiIntegration(
// only works while WIFI is active, so we are not using AUTOPLAY_ALLOW_ON_WIFI (or this class). // only works while WIFI is active, so we are not using AUTOPLAY_ALLOW_ON_WIFI (or this class).
// Once that is fixed, [start] and [maybeAddWifiConnectedListener] will need to be called on // Once that is fixed, [start] and [maybeAddWifiConnectedListener] will need to be called on
// activity startup. // activity startup.
override fun start() { wifiConnectionMonitor.start() } override fun start() {
wifiConnectionMonitor.start()
}
override fun stop() { wifiConnectionMonitor.stop() } override fun stop() {
wifiConnectionMonitor.stop()
}
} }