parent
0f609b1888
commit
69c6de7cd4
|
@ -72,7 +72,6 @@ class Core(private val context: Context) {
|
|||
automaticFontSizeAdjustment = context.settings().shouldUseAutoSize,
|
||||
fontInflationEnabled = context.settings().shouldUseAutoSize,
|
||||
suspendMediaWhenInactive = !FeatureFlags.mediaIntegration,
|
||||
allowAutoplayMedia = context.settings().isAutoPlayEnabled,
|
||||
forceUserScalableContent = context.settings().forceEnableZoom
|
||||
)
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ fun SitePermissions.toggle(featurePhone: PhoneFeature): SitePermissions {
|
|||
PhoneFeature.LOCATION -> copy(location = location.toggle())
|
||||
PhoneFeature.MICROPHONE -> copy(microphone = microphone.toggle())
|
||||
PhoneFeature.NOTIFICATION -> copy(notification = notification.toggle())
|
||||
PhoneFeature.AUTOPLAY -> copy() // not supported by GV or A-C yet
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE -> copy(autoplayAudible = autoplayAudible.toggle())
|
||||
PhoneFeature.AUTOPLAY_INAUDIBLE -> copy(autoplayInaudible = autoplayInaudible.toggle())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,19 +21,21 @@ const val ID_CAMERA_PERMISSION = 0
|
|||
const val ID_LOCATION_PERMISSION = 1
|
||||
const val ID_MICROPHONE_PERMISSION = 2
|
||||
const val ID_NOTIFICATION_PERMISSION = 3
|
||||
const val ID_AUTOPLAY_PERMISSION = 4
|
||||
const val ID_AUTOPLAY_AUDIBLE_PERMISSION = 4
|
||||
const val ID_AUTOPLAY_INAUDIBLE_PERMISSION = 5
|
||||
|
||||
enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>) {
|
||||
CAMERA(ID_CAMERA_PERMISSION, arrayOf(CAMERA_PERMISSION)),
|
||||
LOCATION(ID_LOCATION_PERMISSION, arrayOf(ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION)),
|
||||
MICROPHONE(ID_MICROPHONE_PERMISSION, arrayOf(RECORD_AUDIO)),
|
||||
NOTIFICATION(ID_NOTIFICATION_PERMISSION, emptyArray()),
|
||||
AUTOPLAY(ID_AUTOPLAY_PERMISSION, emptyArray());
|
||||
AUTOPLAY_AUDIBLE(ID_AUTOPLAY_AUDIBLE_PERMISSION, emptyArray()),
|
||||
AUTOPLAY_INAUDIBLE(ID_AUTOPLAY_INAUDIBLE_PERMISSION, emptyArray());
|
||||
|
||||
fun isAndroidPermissionGranted(context: Context): Boolean {
|
||||
return when (this) {
|
||||
CAMERA, LOCATION, MICROPHONE -> context.isPermissionGranted(androidPermissionsList.asIterable())
|
||||
NOTIFICATION, AUTOPLAY -> true
|
||||
NOTIFICATION, AUTOPLAY_AUDIBLE, AUTOPLAY_INAUDIBLE -> true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +49,7 @@ enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>)
|
|||
when (isAndroidPermissionGranted(context)) {
|
||||
false -> R.string.phone_feature_blocked_by_android
|
||||
else -> when (this) {
|
||||
AUTOPLAY -> {
|
||||
AUTOPLAY_AUDIBLE, AUTOPLAY_INAUDIBLE -> {
|
||||
when (getStatus(sitePermissions, settings)) {
|
||||
SitePermissions.Status.BLOCKED -> R.string.preference_option_autoplay_blocked
|
||||
SitePermissions.Status.ALLOWED -> R.string.preference_option_autoplay_allowed
|
||||
|
@ -80,7 +82,7 @@ enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>)
|
|||
LOCATION -> context.getString(R.string.preference_phone_feature_location)
|
||||
MICROPHONE -> context.getString(R.string.preference_phone_feature_microphone)
|
||||
NOTIFICATION -> context.getString(R.string.preference_phone_feature_notification)
|
||||
AUTOPLAY -> context.getString(R.string.preference_browser_feature_autoplay)
|
||||
AUTOPLAY_AUDIBLE, AUTOPLAY_INAUDIBLE -> context.getString(R.string.preference_browser_feature_autoplay)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +92,8 @@ enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>)
|
|||
LOCATION -> context.getPreferenceKey(R.string.pref_key_phone_feature_location)
|
||||
MICROPHONE -> context.getPreferenceKey(R.string.pref_key_phone_feature_microphone)
|
||||
NOTIFICATION -> context.getPreferenceKey(R.string.pref_key_phone_feature_notification)
|
||||
AUTOPLAY -> context.getPreferenceKey(R.string.pref_key_browser_feature_autoplay)
|
||||
AUTOPLAY_AUDIBLE -> context.getPreferenceKey(R.string.pref_key_browser_feature_autoplay_audible)
|
||||
AUTOPLAY_INAUDIBLE -> context.getPreferenceKey(R.string.pref_key_browser_feature_autoplay_inaudible)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +102,8 @@ enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>)
|
|||
|
||||
fun getDefault(): SitePermissionsRules.Action {
|
||||
return when (this) {
|
||||
AUTOPLAY -> SitePermissionsRules.Action.BLOCKED
|
||||
AUTOPLAY_AUDIBLE -> SitePermissionsRules.Action.BLOCKED
|
||||
AUTOPLAY_INAUDIBLE -> SitePermissionsRules.Action.ALLOWED
|
||||
else -> SitePermissionsRules.Action.ASK_TO_ALLOW
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +115,8 @@ enum class PhoneFeature(val id: Int, val androidPermissionsList: Array<String>)
|
|||
LOCATION -> sitePermissions.location
|
||||
MICROPHONE -> sitePermissions.microphone
|
||||
NOTIFICATION -> sitePermissions.notification
|
||||
AUTOPLAY -> SitePermissions.Status.NO_DECISION // No support from GV or A-C yet
|
||||
AUTOPLAY_AUDIBLE -> sitePermissions.autoplayAudible
|
||||
AUTOPLAY_INAUDIBLE -> sitePermissions.autoplayInaudible
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -162,6 +162,8 @@ class DefaultQuickSettingsController(
|
|||
is WebsitePermission.Microphone -> PhoneFeature.MICROPHONE
|
||||
is WebsitePermission.Notification -> PhoneFeature.NOTIFICATION
|
||||
is WebsitePermission.Location -> PhoneFeature.LOCATION
|
||||
is WebsitePermission.AutoplayAudible -> PhoneFeature.AUTOPLAY_AUDIBLE
|
||||
is WebsitePermission.AutoplayInaudible -> PhoneFeature.AUTOPLAY_INAUDIBLE
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -176,7 +178,6 @@ class DefaultQuickSettingsController(
|
|||
val defaultEnabled = false
|
||||
val defaultVisible = false
|
||||
val defaultBlockedByAndroid = false
|
||||
val defaultWebsitePermission: WebsitePermission? = null
|
||||
|
||||
return when (this) {
|
||||
PhoneFeature.CAMERA -> WebsitePermission.Camera(
|
||||
|
@ -191,7 +192,12 @@ class DefaultQuickSettingsController(
|
|||
PhoneFeature.NOTIFICATION -> WebsitePermission.Notification(
|
||||
defaultStatus, defaultVisible, defaultEnabled, defaultBlockedByAndroid
|
||||
)
|
||||
PhoneFeature.AUTOPLAY -> defaultWebsitePermission!! // fail-fast
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE -> WebsitePermission.AutoplayAudible(
|
||||
defaultStatus, defaultVisible, defaultEnabled, defaultBlockedByAndroid
|
||||
)
|
||||
PhoneFeature.AUTOPLAY_INAUDIBLE -> WebsitePermission.AutoplayInaudible(
|
||||
defaultStatus, defaultVisible, defaultEnabled, defaultBlockedByAndroid
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -140,12 +140,18 @@ class QuickSettingsFragmentStore(
|
|||
PhoneFeature.NOTIFICATION.toWebsitePermission(context, permissions, settings)
|
||||
val locationPermission =
|
||||
PhoneFeature.LOCATION.toWebsitePermission(context, permissions, settings)
|
||||
val autoplayAudiblePermission =
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE.toWebsitePermission(context, permissions, settings)
|
||||
val autoplayInaudiblePermission =
|
||||
PhoneFeature.AUTOPLAY_INAUDIBLE.toWebsitePermission(context, permissions, settings)
|
||||
val shouldBeVisible = cameraPermission.isVisible || microphonePermission.isVisible ||
|
||||
notificationPermission.isVisible || locationPermission.isVisible
|
||||
notificationPermission.isVisible || locationPermission.isVisible ||
|
||||
autoplayAudiblePermission.isVisible || autoplayInaudiblePermission.isVisible
|
||||
|
||||
return WebsitePermissionsState(
|
||||
shouldBeVisible, cameraPermission, microphonePermission,
|
||||
notificationPermission, locationPermission
|
||||
notificationPermission, locationPermission, autoplayAudiblePermission,
|
||||
autoplayInaudiblePermission
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -159,7 +165,6 @@ class QuickSettingsFragmentStore(
|
|||
settings: Settings
|
||||
): WebsitePermission {
|
||||
val status = getPermissionStatus(context, permissions, settings)
|
||||
val nonexistentPermission: WebsitePermission? = null
|
||||
return when (this) {
|
||||
PhoneFeature.CAMERA -> WebsitePermission.Camera(
|
||||
status.status, status.isVisible, status.isEnabled, status.isBlockedByAndroid
|
||||
|
@ -173,7 +178,12 @@ class QuickSettingsFragmentStore(
|
|||
PhoneFeature.NOTIFICATION -> WebsitePermission.Notification(
|
||||
status.status, status.isVisible, status.isEnabled, status.isBlockedByAndroid
|
||||
)
|
||||
PhoneFeature.AUTOPLAY -> nonexistentPermission!! // fail-fast
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE -> WebsitePermission.AutoplayAudible(
|
||||
status.status, status.isVisible, status.isEnabled, status.isBlockedByAndroid
|
||||
)
|
||||
PhoneFeature.AUTOPLAY_INAUDIBLE -> WebsitePermission.AutoplayInaudible(
|
||||
status.status, status.isVisible, status.isEnabled, status.isBlockedByAndroid
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +264,9 @@ data class WebsitePermissionsState(
|
|||
val camera: WebsitePermission,
|
||||
val microphone: WebsitePermission,
|
||||
val notification: WebsitePermission,
|
||||
val location: WebsitePermission
|
||||
val location: WebsitePermission,
|
||||
val autoplayAudible: WebsitePermission,
|
||||
val autoplayInaudible: WebsitePermission
|
||||
) : State
|
||||
|
||||
/**
|
||||
|
@ -390,6 +402,55 @@ sealed class WebsitePermission {
|
|||
name = name
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains all information about the *autoplay audible* permission.
|
||||
*/
|
||||
data class AutoplayAudible(
|
||||
override val status: String,
|
||||
override val isVisible: Boolean,
|
||||
override val isEnabled: Boolean,
|
||||
override val isBlockedByAndroid: Boolean,
|
||||
val name: String = "AutoplayAudible" // helps to resolve the overload resolution ambiguity for the copy() method
|
||||
) : WebsitePermission() {
|
||||
override fun copy(
|
||||
status: String,
|
||||
isVisible: Boolean,
|
||||
isEnabled: Boolean,
|
||||
isBlockedByAndroid: Boolean
|
||||
) = copy(
|
||||
status = status,
|
||||
isVisible = isVisible,
|
||||
isEnabled = isEnabled,
|
||||
isBlockedByAndroid = isBlockedByAndroid,
|
||||
name = name
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains all information about the *autoplay inaudible* permission.
|
||||
*/
|
||||
data class AutoplayInaudible(
|
||||
override val status: String,
|
||||
override val isVisible: Boolean,
|
||||
override val isEnabled: Boolean,
|
||||
override val isBlockedByAndroid: Boolean,
|
||||
// helps to resolve the overload resolution ambiguity for the copy() method
|
||||
val name: String = "AutoplayInaudible"
|
||||
) : WebsitePermission() {
|
||||
override fun copy(
|
||||
status: String,
|
||||
isVisible: Boolean,
|
||||
isEnabled: Boolean,
|
||||
isBlockedByAndroid: Boolean
|
||||
) = copy(
|
||||
status = status,
|
||||
isVisible = isVisible,
|
||||
isEnabled = isEnabled,
|
||||
isBlockedByAndroid = isBlockedByAndroid,
|
||||
name = name
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
|
@ -504,6 +565,22 @@ object WebsitePermissionsStateReducer {
|
|||
isEnabled = action.updatedEnabledStatus
|
||||
)
|
||||
)
|
||||
is WebsitePermission.AutoplayAudible -> {
|
||||
return state.copy(
|
||||
autoplayAudible = state.autoplayAudible.copy(
|
||||
status = action.updatedStatus,
|
||||
isEnabled = action.updatedEnabledStatus
|
||||
)
|
||||
)
|
||||
}
|
||||
is WebsitePermission.AutoplayInaudible -> {
|
||||
return state.copy(
|
||||
autoplayInaudible = state.autoplayInaudible.copy(
|
||||
status = action.updatedStatus,
|
||||
isEnabled = action.updatedEnabledStatus
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,11 @@ class SitePermissionsFragment : PreferenceFragmentCompat() {
|
|||
}
|
||||
|
||||
private fun bindCategoryPhoneFeatures() {
|
||||
PhoneFeature.values().forEach(::initPhoneFeature)
|
||||
PhoneFeature.values()
|
||||
// Autoplay inaudible should be set in the same menu as autoplay audible, so it does
|
||||
// not need to be bound
|
||||
.filter { it != PhoneFeature.AUTOPLAY_INAUDIBLE }
|
||||
.forEach(::initPhoneFeature)
|
||||
}
|
||||
|
||||
private fun initPhoneFeature(phoneFeature: PhoneFeature) {
|
||||
|
|
|
@ -160,7 +160,8 @@ class SitePermissionsManageExceptionsPhoneFeatureFragment : Fragment() {
|
|||
PhoneFeature.LOCATION -> sitePermissions.copy(location = status)
|
||||
PhoneFeature.MICROPHONE -> sitePermissions.copy(microphone = status)
|
||||
PhoneFeature.NOTIFICATION -> sitePermissions.copy(notification = status)
|
||||
PhoneFeature.AUTOPLAY -> sitePermissions.copy() // not supported by GV or A-C yet
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE -> sitePermissions.copy(autoplayAudible = status)
|
||||
PhoneFeature.AUTOPLAY_INAUDIBLE -> sitePermissions.copy(autoplayInaudible = status)
|
||||
}
|
||||
lifecycleScope.launch(IO) {
|
||||
requireComponents.core.permissionStorage.updateSitePermissions(updatedSitePermissions)
|
||||
|
|
|
@ -21,10 +21,10 @@ import android.widget.Button
|
|||
import android.widget.RadioButton
|
||||
import androidx.fragment.app.Fragment
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.ALLOWED
|
||||
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.requireComponents
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.showToolbar
|
||||
import org.mozilla.fenix.settings.PhoneFeature
|
||||
|
@ -75,7 +75,8 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
|
|||
private fun initFirstRadio(rootView: View) {
|
||||
val radio = rootView.findViewById<RadioButton>(R.id.ask_to_allow_radio)
|
||||
val askToAllowText = when (phoneFeature) {
|
||||
PhoneFeature.AUTOPLAY -> getString(R.string.preference_option_autoplay_blocked)
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE ->
|
||||
getString(R.string.preference_option_autoplay_blocked)
|
||||
else -> getString(R.string.preference_option_phone_feature_ask_to_allow)
|
||||
}
|
||||
val recommendedText = getString(R.string.phone_feature_recommended)
|
||||
|
@ -102,14 +103,9 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
|
|||
append(recommendedSpannable)
|
||||
this
|
||||
}
|
||||
val expectedAction = if (phoneFeature == PhoneFeature.AUTOPLAY) BLOCKED else ASK_TO_ALLOW
|
||||
val expectedAction = if (phoneFeature == PhoneFeature.AUTOPLAY_AUDIBLE) BLOCKED else ASK_TO_ALLOW
|
||||
radio.setOnClickListener {
|
||||
if (phoneFeature == PhoneFeature.AUTOPLAY) {
|
||||
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.AUTOPLAY, expectedAction)
|
||||
requireComponents.core.engine.settings.allowAutoplayMedia = false
|
||||
} else {
|
||||
saveActionInSettings(expectedAction)
|
||||
}
|
||||
saveActionInSettings(expectedAction)
|
||||
}
|
||||
radio.restoreState(expectedAction)
|
||||
}
|
||||
|
@ -124,17 +120,13 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
|
|||
private fun initSecondRadio(rootView: View) {
|
||||
val radio = rootView.findViewById<RadioButton>(R.id.block_radio)
|
||||
radio.text = when (phoneFeature) {
|
||||
PhoneFeature.AUTOPLAY -> getString(R.string.preference_option_autoplay_allowed)
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE, PhoneFeature.AUTOPLAY_INAUDIBLE ->
|
||||
getString(R.string.preference_option_autoplay_allowed)
|
||||
else -> getString(R.string.preference_option_phone_feature_blocked)
|
||||
}
|
||||
val expectedAction = if (phoneFeature == PhoneFeature.AUTOPLAY) ASK_TO_ALLOW else BLOCKED
|
||||
val expectedAction = if (phoneFeature == PhoneFeature.AUTOPLAY_AUDIBLE) ALLOWED else BLOCKED
|
||||
radio.setOnClickListener {
|
||||
if (phoneFeature == PhoneFeature.AUTOPLAY) {
|
||||
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.AUTOPLAY, expectedAction)
|
||||
requireComponents.core.engine.settings.allowAutoplayMedia = true
|
||||
} else {
|
||||
saveActionInSettings(expectedAction)
|
||||
}
|
||||
saveActionInSettings(expectedAction)
|
||||
}
|
||||
radio.restoreState(expectedAction)
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import androidx.annotation.VisibleForTesting
|
|||
import androidx.annotation.VisibleForTesting.PRIVATE
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.AutoplayAction
|
||||
import mozilla.components.support.ktx.android.content.PreferencesHolder
|
||||
import mozilla.components.support.ktx.android.content.booleanPreference
|
||||
import mozilla.components.support.ktx.android.content.floatPreference
|
||||
|
@ -47,18 +48,32 @@ class Settings private constructor(
|
|||
|
||||
private const val BLOCKED_INT = 0
|
||||
private const val ASK_TO_ALLOW_INT = 1
|
||||
private const val ALLOWED_INT = 2
|
||||
private const val CFR_COUNT_CONDITION_FOCUS_INSTALLED = 1
|
||||
private const val CFR_COUNT_CONDITION_FOCUS_NOT_INSTALLED = 3
|
||||
|
||||
private fun actionToInt(action: Action) = when (action) {
|
||||
private fun Action.toInt() = when (this) {
|
||||
Action.BLOCKED -> BLOCKED_INT
|
||||
Action.ASK_TO_ALLOW -> ASK_TO_ALLOW_INT
|
||||
Action.ALLOWED -> ALLOWED_INT
|
||||
}
|
||||
|
||||
private fun intToAction(action: Int) = when (action) {
|
||||
private fun AutoplayAction.toInt() = when (this) {
|
||||
AutoplayAction.BLOCKED -> BLOCKED_INT
|
||||
AutoplayAction.ALLOWED -> ALLOWED_INT
|
||||
}
|
||||
|
||||
private fun Int.toAction() = when (this) {
|
||||
BLOCKED_INT -> Action.BLOCKED
|
||||
ASK_TO_ALLOW_INT -> Action.ASK_TO_ALLOW
|
||||
else -> throw InvalidParameterException("$action is not a valid SitePermissionsRules.Action")
|
||||
ALLOWED_INT -> Action.ALLOWED
|
||||
else -> throw InvalidParameterException("$this is not a valid SitePermissionsRules.Action")
|
||||
}
|
||||
|
||||
private fun Int.toAutoplayAction() = when (this) {
|
||||
BLOCKED_INT -> AutoplayAction.BLOCKED
|
||||
ALLOWED_INT -> AutoplayAction.ALLOWED
|
||||
else -> throw InvalidParameterException("$this is not a valid SitePermissionsRules.AutoplayAction")
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -145,7 +160,7 @@ class Settings private constructor(
|
|||
)
|
||||
|
||||
val isAutoPlayEnabled = getSitePermissionsPhoneFeatureAction(
|
||||
PhoneFeature.AUTOPLAY, Action.BLOCKED
|
||||
PhoneFeature.AUTOPLAY_AUDIBLE, Action.BLOCKED
|
||||
) != Action.BLOCKED
|
||||
|
||||
private var trackingProtectionOnboardingShownThisSession = false
|
||||
|
@ -418,13 +433,18 @@ class Settings private constructor(
|
|||
feature: PhoneFeature,
|
||||
default: Action = Action.ASK_TO_ALLOW
|
||||
) =
|
||||
intToAction(preferences.getInt(feature.getPreferenceKey(appContext), actionToInt(default)))
|
||||
preferences.getInt(feature.getPreferenceKey(appContext), default.toInt()).toAction()
|
||||
|
||||
fun getSitePermissionsPhoneFeatureAutoplayAction(
|
||||
feature: PhoneFeature,
|
||||
default: AutoplayAction = AutoplayAction.BLOCKED
|
||||
) = preferences.getInt(feature.getPreferenceKey(appContext), default.toInt()).toAutoplayAction()
|
||||
|
||||
fun setSitePermissionsPhoneFeatureAction(
|
||||
feature: PhoneFeature,
|
||||
value: Action
|
||||
) {
|
||||
preferences.edit().putInt(feature.getPreferenceKey(appContext), actionToInt(value)).apply()
|
||||
preferences.edit().putInt(feature.getPreferenceKey(appContext), value.toInt()).apply()
|
||||
}
|
||||
|
||||
fun getSitePermissionsCustomSettingsRules(): SitePermissionsRules {
|
||||
|
@ -432,7 +452,10 @@ class Settings private constructor(
|
|||
notification = getSitePermissionsPhoneFeatureAction(PhoneFeature.NOTIFICATION),
|
||||
microphone = getSitePermissionsPhoneFeatureAction(PhoneFeature.MICROPHONE),
|
||||
location = getSitePermissionsPhoneFeatureAction(PhoneFeature.LOCATION),
|
||||
camera = getSitePermissionsPhoneFeatureAction(PhoneFeature.CAMERA)
|
||||
camera = getSitePermissionsPhoneFeatureAction(PhoneFeature.CAMERA),
|
||||
autoplayAudible = getSitePermissionsPhoneFeatureAutoplayAction(PhoneFeature.AUTOPLAY_AUDIBLE),
|
||||
// TODO autoplayInaudible will be hardcoded until additional options are added in #8017
|
||||
autoplayInaudible = AutoplayAction.ALLOWED
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,8 @@
|
|||
<string name="pref_key_show_site_exceptions" translatable="false">pref_key_show_site_exceptions</string>
|
||||
<string name="pref_key_recommended_settings" translatable="false">pref_key_recommended_settings</string>
|
||||
<string name="pref_key_custom_settings" translatable="false">pref_key_custom_settings</string>
|
||||
<string name="pref_key_browser_feature_autoplay" translatable="false">pref_key_browser_feature_autoplay</string>
|
||||
<string name="pref_key_browser_feature_autoplay_audible" translatable="false">pref_key_browser_feature_autoplay</string>
|
||||
<string name="pref_key_browser_feature_autoplay_inaudible" translatable="false">pref_key_browser_feature_autoplay_inaudible</string>
|
||||
<string name="pref_key_phone_feature_camera" translatable="false">pref_key_phone_feature_camera</string>
|
||||
<string name="pref_key_phone_feature_location" translatable="false">pref_key_phone_feature_location</string>
|
||||
<string name="pref_key_phone_feature_microphone" translatable="false">pref_key_phone_feature_microphone</string>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<androidx.preference.Preference
|
||||
android:icon="@drawable/ic_autoplay_enabled"
|
||||
android:key="@string/pref_key_browser_feature_autoplay"
|
||||
android:key="@string/pref_key_browser_feature_autoplay_audible"
|
||||
android:title="@string/preference_browser_feature_autoplay"
|
||||
android:summary="@string/preference_option_autoplay_blocked"/>
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import androidx.navigation.NavDirections
|
|||
import assertk.assertAll
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isFailure
|
||||
import assertk.assertions.isInstanceOf
|
||||
import assertk.assertions.isSameAs
|
||||
import assertk.assertions.isTrue
|
||||
|
@ -270,8 +269,10 @@ class DefaultQuickSettingsControllerTest {
|
|||
.isInstanceOf(WebsitePermission.Notification::class)
|
||||
assertThat(PhoneFeature.LOCATION.getCorrespondingPermission())
|
||||
.isInstanceOf(WebsitePermission.Location::class)
|
||||
assertThat { PhoneFeature.AUTOPLAY.getCorrespondingPermission() }
|
||||
.isFailure().isInstanceOf(KotlinNullPointerException::class)
|
||||
assertThat(PhoneFeature.AUTOPLAY_AUDIBLE.getCorrespondingPermission())
|
||||
.isInstanceOf(WebsitePermission.AutoplayAudible::class)
|
||||
assertThat(PhoneFeature.AUTOPLAY_INAUDIBLE.getCorrespondingPermission())
|
||||
.isInstanceOf(WebsitePermission.AutoplayInaudible::class)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,6 +119,8 @@ class QuickSettingsFragmentStoreTest {
|
|||
every { permissions.microphone } returns SitePermissions.Status.NO_DECISION
|
||||
every { permissions.notification } returns SitePermissions.Status.BLOCKED
|
||||
every { permissions.location } returns SitePermissions.Status.ALLOWED
|
||||
every { permissions.autoplayAudible } returns SitePermissions.Status.BLOCKED
|
||||
every { permissions.autoplayInaudible } returns SitePermissions.Status.BLOCKED
|
||||
|
||||
val state = QuickSettingsFragmentStore.createWebsitePermissionState(
|
||||
context, permissions, appSettings
|
||||
|
@ -132,6 +134,8 @@ class QuickSettingsFragmentStoreTest {
|
|||
assertThat(state.microphone).isNotNull()
|
||||
assertThat(state.notification).isNotNull()
|
||||
assertThat(state.location).isNotNull()
|
||||
assertThat(state.autoplayAudible).isNotNull()
|
||||
assertThat(state.autoplayInaudible).isNotNull()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,10 +194,14 @@ class QuickSettingsFragmentStoreTest {
|
|||
val microphonePermissionName = "Microphone"
|
||||
val notificationPermissionName = "Notification"
|
||||
val locationPermissionName = "Location"
|
||||
val autoplayAudiblePermissionName = "AutoplayAudible"
|
||||
val autoplayInaudiblePermissionName = "AutoplayInaudible"
|
||||
val initialCameraStatus = "initialCameraStatus"
|
||||
val initialMicStatus = "initialMicStatus"
|
||||
val initialNotificationStatus = "initialNotificationStatus"
|
||||
val initialLocationStatus = "initialLocationStatus"
|
||||
val initialAutoplayAudibleStatus = "initialAutoplayAudibleStatus"
|
||||
val initialAutoplayInaudibleStatus = "initialAutoplayInaudibleStatus"
|
||||
val updatedMicrophoneStatus = "updatedNotificationStatus"
|
||||
val updatedMicrophoneEnabledStatus = false
|
||||
val defaultVisibilityStatus = true
|
||||
|
@ -217,6 +225,14 @@ class QuickSettingsFragmentStoreTest {
|
|||
location = WebsitePermission.Location(
|
||||
initialLocationStatus, defaultVisibilityStatus,
|
||||
defaultEnabledStatus, defaultBlockedByAndroidStatus, locationPermissionName
|
||||
),
|
||||
autoplayAudible = WebsitePermission.AutoplayAudible(
|
||||
initialAutoplayAudibleStatus, defaultVisibilityStatus,
|
||||
defaultEnabledStatus, defaultBlockedByAndroidStatus, autoplayAudiblePermissionName
|
||||
),
|
||||
autoplayInaudible = WebsitePermission.AutoplayInaudible(
|
||||
initialAutoplayInaudibleStatus, defaultVisibilityStatus,
|
||||
defaultEnabledStatus, defaultBlockedByAndroidStatus, autoplayInaudiblePermissionName
|
||||
)
|
||||
)
|
||||
val initialState = QuickSettingsFragmentState(
|
||||
|
|
|
@ -6,8 +6,10 @@ package org.mozilla.fenix.utils
|
|||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.ALLOWED
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.ASK_TO_ALLOW
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action.BLOCKED
|
||||
import mozilla.components.feature.sitepermissions.SitePermissionsRules.AutoplayAction
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
|
@ -388,7 +390,7 @@ class SettingsTest {
|
|||
// When just created
|
||||
// Then
|
||||
assertEquals(
|
||||
allAskToAllow(),
|
||||
defaultPermissions(),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
}
|
||||
|
@ -400,7 +402,7 @@ class SettingsTest {
|
|||
|
||||
// Then
|
||||
assertEquals(
|
||||
allAskToAllow().copy(camera = BLOCKED),
|
||||
defaultPermissions().copy(camera = BLOCKED),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
}
|
||||
|
@ -412,7 +414,7 @@ class SettingsTest {
|
|||
|
||||
// Then
|
||||
assertEquals(
|
||||
allAskToAllow().copy(notification = BLOCKED),
|
||||
defaultPermissions().copy(notification = BLOCKED),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
}
|
||||
|
@ -424,7 +426,7 @@ class SettingsTest {
|
|||
|
||||
// Then
|
||||
assertEquals(
|
||||
allAskToAllow().copy(location = BLOCKED),
|
||||
defaultPermissions().copy(location = BLOCKED),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
}
|
||||
|
@ -436,7 +438,34 @@ class SettingsTest {
|
|||
|
||||
// Then
|
||||
assertEquals(
|
||||
allAskToAllow().copy(microphone = BLOCKED),
|
||||
defaultPermissions().copy(microphone = BLOCKED),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSitePermissionsCustomSettingsRules_autoplayAudible() {
|
||||
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.AUTOPLAY_AUDIBLE, ALLOWED)
|
||||
|
||||
assertEquals(
|
||||
defaultPermissions().copy(autoplayAudible = ALLOWED),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getSitePermissionsCustomSettingsRules_autoplayInaudible() {
|
||||
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.AUTOPLAY_INAUDIBLE, ALLOWED)
|
||||
|
||||
assertEquals(
|
||||
defaultPermissions(),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
|
||||
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.AUTOPLAY_INAUDIBLE, BLOCKED)
|
||||
|
||||
assertEquals(
|
||||
defaultPermissions(),
|
||||
settings.getSitePermissionsCustomSettingsRules()
|
||||
)
|
||||
}
|
||||
|
@ -450,9 +479,11 @@ private fun Settings.clear() {
|
|||
preferences.clearAndCommit()
|
||||
}
|
||||
|
||||
private fun allAskToAllow() = SitePermissionsRules(
|
||||
private fun defaultPermissions() = SitePermissionsRules(
|
||||
camera = ASK_TO_ALLOW,
|
||||
location = ASK_TO_ALLOW,
|
||||
microphone = ASK_TO_ALLOW,
|
||||
notification = ASK_TO_ALLOW
|
||||
notification = ASK_TO_ALLOW,
|
||||
autoplayAudible = AutoplayAction.BLOCKED,
|
||||
autoplayInaudible = AutoplayAction.ALLOWED
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue