Skip to content

Commit

Permalink
For issue mozilla-mobile#8017 enable SitePermissionsWifiIntegration
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 committed Mar 24, 2020
1 parent 79dc133 commit 3c29280
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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

/**
Expand Down Expand Up @@ -118,6 +119,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

Expand Down Expand Up @@ -391,6 +393,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
Expand Down Expand Up @@ -535,6 +546,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
override fun onStart() {
super.onStart()
requireComponents.core.sessionManager.register(this, this, autoPause = true)
sitePermissionWifiIntegration.get()?.maybeAddWifiConnectedListener()
}

@CallSuper
Expand Down
11 changes: 1 addition & 10 deletions app/src/main/java/org/mozilla/fenix/components/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import mozilla.components.support.migration.state.MigrationStore
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
Expand Down Expand Up @@ -100,12 +98,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) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -123,7 +121,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
Expand All @@ -145,7 +143,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 {
Expand All @@ -163,7 +161,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 {
Expand Down Expand Up @@ -196,19 +194,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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand 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
Expand Down Expand Up @@ -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() }
}

0 comments on commit 3c29280

Please sign in to comment.