For issue #8017 enable SitePermissionsWifiIntegration
parent
75aba7a2b4
commit
f9cc2ccfe2
|
@ -86,6 +86,7 @@ import org.mozilla.fenix.ext.sessionsOfType
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.settings.SupportUtils
|
import org.mozilla.fenix.settings.SupportUtils
|
||||||
import org.mozilla.fenix.theme.ThemeManager
|
import org.mozilla.fenix.theme.ThemeManager
|
||||||
|
import org.mozilla.fenix.wifi.SitePermissionsWifiIntegration
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,6 +120,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
|
||||||
private val fullScreenFeature = ViewBoundFeatureWrapper<FullScreenFeature>()
|
private val fullScreenFeature = ViewBoundFeatureWrapper<FullScreenFeature>()
|
||||||
private val swipeRefreshFeature = ViewBoundFeatureWrapper<SwipeRefreshFeature>()
|
private val swipeRefreshFeature = ViewBoundFeatureWrapper<SwipeRefreshFeature>()
|
||||||
private val webchannelIntegration = ViewBoundFeatureWrapper<FxaWebChannelFeature>()
|
private val webchannelIntegration = ViewBoundFeatureWrapper<FxaWebChannelFeature>()
|
||||||
|
private val sitePermissionWifiIntegration = ViewBoundFeatureWrapper<SitePermissionsWifiIntegration>()
|
||||||
|
|
||||||
var customTabSessionId: String? = null
|
var customTabSessionId: String? = null
|
||||||
|
|
||||||
|
@ -392,6 +394,15 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
|
||||||
view = view
|
view = view
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sitePermissionWifiIntegration.set(
|
||||||
|
feature = SitePermissionsWifiIntegration(
|
||||||
|
settings = context.settings(),
|
||||||
|
wifiConnectionMonitor = context.components.wifiConnectionMonitor
|
||||||
|
),
|
||||||
|
owner = this,
|
||||||
|
view = view
|
||||||
|
)
|
||||||
|
|
||||||
context.settings().setSitePermissionSettingListener(viewLifecycleOwner) {
|
context.settings().setSitePermissionSettingListener(viewLifecycleOwner) {
|
||||||
// If the user connects to WIFI while on the BrowserFragment, this will update the
|
// If the user connects to WIFI while on the BrowserFragment, this will update the
|
||||||
// SitePermissionsRules (specifically autoplay) accordingly
|
// SitePermissionsRules (specifically autoplay) accordingly
|
||||||
|
@ -536,6 +547,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
requireComponents.core.sessionManager.register(this, this, autoPause = true)
|
requireComponents.core.sessionManager.register(this, this, autoPause = true)
|
||||||
|
sitePermissionWifiIntegration.get()?.maybeAddWifiConnectedListener()
|
||||||
}
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
|
|
|
@ -19,11 +19,9 @@ import mozilla.components.lib.publicsuffixlist.PublicSuffixList
|
||||||
import mozilla.components.support.migration.state.MigrationStore
|
import mozilla.components.support.migration.state.MigrationStore
|
||||||
import org.mozilla.fenix.BuildConfig
|
import org.mozilla.fenix.BuildConfig
|
||||||
import org.mozilla.fenix.HomeActivity
|
import org.mozilla.fenix.HomeActivity
|
||||||
import org.mozilla.fenix.ext.settings
|
|
||||||
import org.mozilla.fenix.test.Mockable
|
import org.mozilla.fenix.test.Mockable
|
||||||
import org.mozilla.fenix.utils.ClipboardHandler
|
import org.mozilla.fenix.utils.ClipboardHandler
|
||||||
import org.mozilla.fenix.wifi.WifiConnectionMonitor
|
import org.mozilla.fenix.wifi.WifiConnectionMonitor
|
||||||
import org.mozilla.fenix.wifi.WifiIntegration
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
private const val DAY_IN_MINUTES = 24 * 60L
|
private const val DAY_IN_MINUTES = 24 * 60L
|
||||||
|
@ -110,12 +108,5 @@ class Components(private val context: Context) {
|
||||||
val migrationStore by lazy { MigrationStore() }
|
val migrationStore by lazy { MigrationStore() }
|
||||||
val performance by lazy { PerformanceComponent() }
|
val performance by lazy { PerformanceComponent() }
|
||||||
val push by lazy { Push(context, analytics.crashReporter) }
|
val push by lazy { Push(context, analytics.crashReporter) }
|
||||||
val wifiIntegration by lazy {
|
val wifiConnectionMonitor by lazy { WifiConnectionMonitor(context as Application) }
|
||||||
WifiIntegration(
|
|
||||||
settings = context.settings(),
|
|
||||||
wifiConnectionMonitor = WifiConnectionMonitor(
|
|
||||||
context as Application
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.settings.sitepermissions
|
package org.mozilla.fenix.settings.sitepermissions
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.net.Uri
|
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.ASK_TO_ALLOW
|
||||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.BLOCKED
|
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.BLOCKED
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
import org.mozilla.fenix.ext.components
|
|
||||||
import org.mozilla.fenix.ext.settings
|
import org.mozilla.fenix.ext.settings
|
||||||
import org.mozilla.fenix.ext.showToolbar
|
import org.mozilla.fenix.ext.showToolbar
|
||||||
import org.mozilla.fenix.settings.PhoneFeature
|
import org.mozilla.fenix.settings.PhoneFeature
|
||||||
|
@ -122,7 +120,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
|
||||||
// TODO replace with AUTOPLAY_ALLOW_ON_WIFI when
|
// TODO replace with AUTOPLAY_ALLOW_ON_WIFI when
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1621825 is fixed. This GV bug
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1621825 is fixed. This GV bug
|
||||||
// makes ALLOW_ALL behave as ALLOW_ON_WIFI
|
// 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
|
// TODO replace with AUTOPLAY_ALLOW_ON_WIFI when
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1621825 is fixed. This GV bug
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1621825 is fixed. This GV bug
|
||||||
|
@ -144,7 +142,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
|
||||||
visibility = View.VISIBLE
|
visibility = View.VISIBLE
|
||||||
text = getString(R.string.preference_option_autoplay_block_audio2)
|
text = getString(R.string.preference_option_autoplay_block_audio2)
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
saveActionInSettings(it.context, AUTOPLAY_BLOCK_AUDIBLE)
|
saveActionInSettings(AUTOPLAY_BLOCK_AUDIBLE)
|
||||||
}
|
}
|
||||||
restoreState(AUTOPLAY_BLOCK_AUDIBLE)
|
restoreState(AUTOPLAY_BLOCK_AUDIBLE)
|
||||||
} else {
|
} else {
|
||||||
|
@ -162,7 +160,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
|
||||||
getString(R.string.phone_feature_recommended)
|
getString(R.string.phone_feature_recommended)
|
||||||
)
|
)
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
saveActionInSettings(it.context, AUTOPLAY_BLOCK_ALL)
|
saveActionInSettings(AUTOPLAY_BLOCK_ALL)
|
||||||
}
|
}
|
||||||
restoreState(AUTOPLAY_BLOCK_ALL)
|
restoreState(AUTOPLAY_BLOCK_ALL)
|
||||||
} else {
|
} else {
|
||||||
|
@ -195,19 +193,18 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
|
||||||
* See [Settings.setAutoplayUserSetting] kdoc for an explanation of why this cannot follow the
|
* See [Settings.setAutoplayUserSetting] kdoc for an explanation of why this cannot follow the
|
||||||
* same code path as other permissions.
|
* same code path as other permissions.
|
||||||
*/
|
*/
|
||||||
private fun saveActionInSettings(context: Context, autoplaySetting: Int) {
|
private fun saveActionInSettings(autoplaySetting: Int) {
|
||||||
settings.setAutoplayUserSetting(autoplaySetting)
|
settings.setAutoplayUserSetting(autoplaySetting)
|
||||||
val (audible, inaudible) = when (autoplaySetting) {
|
val (audible, inaudible) = when (autoplaySetting) {
|
||||||
AUTOPLAY_ALLOW_ALL -> ALLOWED to ALLOWED
|
AUTOPLAY_ALLOW_ALL,
|
||||||
AUTOPLAY_ALLOW_ON_WIFI -> {
|
AUTOPLAY_ALLOW_ON_WIFI -> {
|
||||||
context.components.wifiIntegration.addWifiConnectedListener()
|
settings.setAutoplayUserSetting(AUTOPLAY_ALLOW_ON_WIFI)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
AUTOPLAY_BLOCK_AUDIBLE -> BLOCKED to ALLOWED
|
AUTOPLAY_BLOCK_AUDIBLE -> BLOCKED to ALLOWED
|
||||||
AUTOPLAY_BLOCK_ALL -> BLOCKED to BLOCKED
|
AUTOPLAY_BLOCK_ALL -> BLOCKED to BLOCKED
|
||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
context.components.wifiIntegration.removeWifiConnectedListener()
|
|
||||||
settings.setSitePermissionsPhoneFeatureAction(AUTOPLAY_AUDIBLE, audible)
|
settings.setSitePermissionsPhoneFeatureAction(AUTOPLAY_AUDIBLE, audible)
|
||||||
settings.setSitePermissionsPhoneFeatureAction(AUTOPLAY_INAUDIBLE, inaudible)
|
settings.setSitePermissionsPhoneFeatureAction(AUTOPLAY_INAUDIBLE, inaudible)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
package org.mozilla.fenix.wifi
|
package org.mozilla.fenix.wifi
|
||||||
|
|
||||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
||||||
|
import mozilla.components.support.base.feature.LifecycleAwareFeature
|
||||||
import org.mozilla.fenix.settings.PhoneFeature
|
import org.mozilla.fenix.settings.PhoneFeature
|
||||||
import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_ALLOW_ON_WIFI
|
import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_ALLOW_ON_WIFI
|
||||||
import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_BLOCK_ALL
|
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
|
* Handles implementation details of only setting up a WIFI connectivity listener if the current
|
||||||
* user settings require it.
|
* 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
|
* 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).
|
// 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.
|
||||||
fun start() { wifiConnectionMonitor.start() }
|
override fun start() { wifiConnectionMonitor.start() }
|
||||||
|
|
||||||
fun stop() { wifiConnectionMonitor.stop() }
|
override fun stop() { wifiConnectionMonitor.stop() }
|
||||||
}
|
}
|
Loading…
Reference in New Issue