1
0
Fork 0

For issue #8017 enable SitePermissionsWifiIntegration

master
Arturo Mejia 2020-03-24 14:23:15 -04:00
parent 75aba7a2b4
commit f9cc2ccfe2
4 changed files with 26 additions and 22 deletions

View File

@ -86,6 +86,7 @@ import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration
import java.lang.ref.WeakReference
/**
@ -119,6 +120,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
private val fullScreenFeature = ViewBoundFeatureWrapper<FullScreenFeature>()
private val swipeRefreshFeature = ViewBoundFeatureWrapper<SwipeRefreshFeature>()
private val webchannelIntegration = ViewBoundFeatureWrapper<FxaWebChannelFeature>()
private val sitePermissionWifiIntegration = ViewBoundFeatureWrapper<SitePermissionsWifiIntegration>()
var customTabSessionId: String? = null
@ -392,6 +394,15 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
view = view
)
sitePermissionWifiIntegration.set(
feature = SitePermissionsWifiIntegration(
settings = context.settings(),
wifiConnectionMonitor = context.components.wifiConnectionMonitor
),
owner = this,
view = view
)
context.settings().setSitePermissionSettingListener(viewLifecycleOwner) {
// If the user connects to WIFI while on the BrowserFragment, this will update the
// SitePermissionsRules (specifically autoplay) accordingly
@ -536,6 +547,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
override fun onStart() {
super.onStart()
requireComponents.core.sessionManager.register(this, this, autoPause = true)
sitePermissionWifiIntegration.get()?.maybeAddWifiConnectedListener()
}
@CallSuper

View File

@ -19,11 +19,9 @@ import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import mozilla.components.support.migration.state.MigrationStore
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.test.Mockable
import org.mozilla.fenix.utils.ClipboardHandler
import org.mozilla.fenix.wifi.WifiConnectionMonitor
import org.mozilla.fenix.wifi.WifiIntegration
import java.util.concurrent.TimeUnit
private const val DAY_IN_MINUTES = 24 * 60L
@ -110,12 +108,5 @@ class Components(private val context: Context) {
val migrationStore by lazy { MigrationStore() }
val performance by lazy { PerformanceComponent() }
val push by lazy { Push(context, analytics.crashReporter) }
val wifiIntegration by lazy {
WifiIntegration(
settings = context.settings(),
wifiConnectionMonitor = WifiConnectionMonitor(
context as Application
)
)
}
val wifiConnectionMonitor by lazy { WifiConnectionMonitor(context as Application) }
}

View File

@ -4,7 +4,6 @@
package org.mozilla.fenix.settings.sitepermissions
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.net.Uri
@ -30,7 +29,6 @@ import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.AL
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.ASK_TO_ALLOW
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.BLOCKED
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.settings.PhoneFeature
@ -122,7 +120,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
// TODO replace with AUTOPLAY_ALLOW_ON_WIFI when
// https://bugzilla.mozilla.org/show_bug.cgi?id=1621825 is fixed. This GV bug
// makes ALLOW_ALL behave as ALLOW_ON_WIFI
saveActionInSettings(it.context, AUTOPLAY_ALLOW_ALL)
saveActionInSettings(AUTOPLAY_ALLOW_ALL)
}
// TODO replace with AUTOPLAY_ALLOW_ON_WIFI when
// https://bugzilla.mozilla.org/show_bug.cgi?id=1621825 is fixed. This GV bug
@ -144,7 +142,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
visibility = View.VISIBLE
text = getString(R.string.preference_option_autoplay_block_audio2)
setOnClickListener {
saveActionInSettings(it.context, AUTOPLAY_BLOCK_AUDIBLE)
saveActionInSettings(AUTOPLAY_BLOCK_AUDIBLE)
}
restoreState(AUTOPLAY_BLOCK_AUDIBLE)
} else {
@ -162,7 +160,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
getString(R.string.phone_feature_recommended)
)
setOnClickListener {
saveActionInSettings(it.context, AUTOPLAY_BLOCK_ALL)
saveActionInSettings(AUTOPLAY_BLOCK_ALL)
}
restoreState(AUTOPLAY_BLOCK_ALL)
} else {
@ -195,19 +193,18 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
* See [Settings.setAutoplayUserSetting] kdoc for an explanation of why this cannot follow the
* same code path as other permissions.
*/
private fun saveActionInSettings(context: Context, autoplaySetting: Int) {
private fun saveActionInSettings(autoplaySetting: Int) {
settings.setAutoplayUserSetting(autoplaySetting)
val (audible, inaudible) = when (autoplaySetting) {
AUTOPLAY_ALLOW_ALL -> ALLOWED to ALLOWED
AUTOPLAY_ALLOW_ALL,
AUTOPLAY_ALLOW_ON_WIFI -> {
context.components.wifiIntegration.addWifiConnectedListener()
settings.setAutoplayUserSetting(AUTOPLAY_ALLOW_ON_WIFI)
return
}
AUTOPLAY_BLOCK_AUDIBLE -> BLOCKED to ALLOWED
AUTOPLAY_BLOCK_ALL -> BLOCKED to BLOCKED
else -> return
}
context.components.wifiIntegration.removeWifiConnectedListener()
settings.setSitePermissionsPhoneFeatureAction(AUTOPLAY_AUDIBLE, audible)
settings.setSitePermissionsPhoneFeatureAction(AUTOPLAY_INAUDIBLE, inaudible)
}

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.wifi
import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.support.base.feature.LifecycleAwareFeature
import org.mozilla.fenix.settings.PhoneFeature
import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_ALLOW_ON_WIFI
import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_BLOCK_ALL
@ -14,7 +15,10 @@ import org.mozilla.fenix.utils.Settings
* Handles implementation details of only setting up a WIFI connectivity listener if the current
* user settings require it.
*/
class WifiIntegration(private val settings: Settings, private val wifiConnectionMonitor: WifiConnectionMonitor) {
class SitePermissionsWifiIntegration(
private val settings: Settings,
private val wifiConnectionMonitor: WifiConnectionMonitor
) : LifecycleAwareFeature {
/**
* Adds listener for autplay setting [AUTOPLAY_ALLOW_ON_WIFI]. Sets all autoplay to allowed when
@ -51,7 +55,7 @@ class WifiIntegration(private val settings: Settings, private val wifiConnection
// 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
// activity startup.
fun start() { wifiConnectionMonitor.start() }
override fun start() { wifiConnectionMonitor.start() }
fun stop() { wifiConnectionMonitor.stop() }
override fun stop() { wifiConnectionMonitor.stop() }
}