Add support for EME permission.

This accompanies the changes in mozilla-mobile/android-components#9121.

Closes #1175
This commit is contained in:
Emilio Cobos Álvarez 2020-12-04 00:41:59 +01:00 committed by Christian Sadilek
parent f2191bdbb5
commit 9d5afd501e
13 changed files with 89 additions and 6 deletions

View File

@ -26,6 +26,7 @@ fun SitePermissions.get(field: PhoneFeature) = when (field) {
PhoneFeature.AUTOPLAY_AUDIBLE -> autoplayAudible
PhoneFeature.AUTOPLAY_INAUDIBLE -> autoplayInaudible
PhoneFeature.PERSISTENT_STORAGE -> localStorage
PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS -> mediaKeySystemAccess
}
fun SitePermissions.update(field: PhoneFeature, value: SitePermissions.Status) = when (field) {
@ -36,6 +37,7 @@ fun SitePermissions.update(field: PhoneFeature, value: SitePermissions.Status) =
PhoneFeature.AUTOPLAY_AUDIBLE -> copy(autoplayAudible = value)
PhoneFeature.AUTOPLAY_INAUDIBLE -> copy(autoplayInaudible = value)
PhoneFeature.PERSISTENT_STORAGE -> copy(localStorage = value)
PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS -> copy(mediaKeySystemAccess = value)
}
/**

View File

@ -31,7 +31,8 @@ enum class PhoneFeature(val androidPermissionsList: Array<String>) : Parcelable
NOTIFICATION(emptyArray()),
AUTOPLAY_AUDIBLE(emptyArray()),
AUTOPLAY_INAUDIBLE(emptyArray()),
PERSISTENT_STORAGE(emptyArray());
PERSISTENT_STORAGE(emptyArray()),
MEDIA_KEY_SYSTEM_ACCESS(emptyArray());
fun isAndroidPermissionGranted(context: Context): Boolean {
return context.isPermissionGranted(androidPermissionsList.asIterable())
@ -80,6 +81,7 @@ enum class PhoneFeature(val androidPermissionsList: Array<String>) : Parcelable
MICROPHONE -> context.getString(R.string.preference_phone_feature_microphone)
NOTIFICATION -> context.getString(R.string.preference_phone_feature_notification)
PERSISTENT_STORAGE -> context.getString(R.string.preference_phone_feature_persistent_storage)
MEDIA_KEY_SYSTEM_ACCESS -> context.getString(R.string.preference_phone_feature_media_key_system_access)
AUTOPLAY_AUDIBLE, AUTOPLAY_INAUDIBLE -> context.getString(R.string.preference_browser_feature_autoplay)
}
}
@ -98,6 +100,7 @@ enum class PhoneFeature(val androidPermissionsList: Array<String>) : Parcelable
AUTOPLAY_AUDIBLE -> R.string.pref_key_browser_feature_autoplay_audible
AUTOPLAY_INAUDIBLE -> R.string.pref_key_browser_feature_autoplay_inaudible
PERSISTENT_STORAGE -> R.string.pref_key_browser_feature_persistent_storage
MEDIA_KEY_SYSTEM_ACCESS -> R.string.pref_key_browser_feature_media_key_system_access
}
}

View File

@ -67,6 +67,10 @@ class WebsitePermissionsView(
PhoneFeature.PERSISTENT_STORAGE to PermissionViewHolder(
view.persistentStorageLabel,
view.persistentStorageStatus
),
PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS to PermissionViewHolder(
view.mediaKeySystemAccessLabel,
view.mediaKeySystemAccessStatus
)
)
)

View File

@ -26,6 +26,7 @@ import org.mozilla.fenix.settings.PhoneFeature.LOCATION
import org.mozilla.fenix.settings.PhoneFeature.MICROPHONE
import org.mozilla.fenix.settings.PhoneFeature.NOTIFICATION
import org.mozilla.fenix.settings.PhoneFeature.PERSISTENT_STORAGE
import org.mozilla.fenix.settings.PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS
import org.mozilla.fenix.settings.requirePreference
class SitePermissionsDetailsExceptionsFragment : PreferenceFragmentCompat() {
@ -59,6 +60,7 @@ class SitePermissionsDetailsExceptionsFragment : PreferenceFragmentCompat() {
initPhoneFeature(MICROPHONE)
initPhoneFeature(NOTIFICATION)
initPhoneFeature(PERSISTENT_STORAGE)
initPhoneFeature(MEDIA_KEY_SYSTEM_ACCESS)
bindClearPermissionsButton()
}

View File

@ -33,6 +33,7 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.settings.PhoneFeature.AUTOPLAY_AUDIBLE
import org.mozilla.fenix.settings.PhoneFeature.AUTOPLAY_INAUDIBLE
import org.mozilla.fenix.settings.PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS
import org.mozilla.fenix.settings.setStartCheckedIndicator
import org.mozilla.fenix.utils.Settings
@ -132,6 +133,13 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() {
saveActionInSettings(AUTOPLAY_BLOCK_AUDIBLE)
}
restoreState(AUTOPLAY_BLOCK_AUDIBLE)
} else if (args.phoneFeature == MEDIA_KEY_SYSTEM_ACCESS) {
visibility = View.VISIBLE
text = getString(R.string.preference_option_phone_feature_allowed)
setOnClickListener {
saveActionInSettings(ALLOWED)
}
restoreState(ALLOWED)
} else {
visibility = View.GONE
}

View File

@ -746,7 +746,8 @@ class Settings(private val appContext: Context) : PreferencesHolder {
camera = getSitePermissionsPhoneFeatureAction(PhoneFeature.CAMERA),
autoplayAudible = getSitePermissionsPhoneFeatureAutoplayAction(PhoneFeature.AUTOPLAY_AUDIBLE),
autoplayInaudible = getSitePermissionsPhoneFeatureAutoplayAction(PhoneFeature.AUTOPLAY_INAUDIBLE),
persistentStorage = getSitePermissionsPhoneFeatureAction(PhoneFeature.PERSISTENT_STORAGE)
persistentStorage = getSitePermissionsPhoneFeatureAction(PhoneFeature.PERSISTENT_STORAGE),
mediaKeySystemAccess = getSitePermissionsPhoneFeatureAction(PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS)
)
}
@ -757,7 +758,9 @@ class Settings(private val appContext: Context) : PreferencesHolder {
PhoneFeature.LOCATION,
PhoneFeature.CAMERA,
PhoneFeature.AUTOPLAY_AUDIBLE,
PhoneFeature.AUTOPLAY_INAUDIBLE
PhoneFeature.AUTOPLAY_INAUDIBLE,
PhoneFeature.PERSISTENT_STORAGE,
PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS
).map { it.getPreferenceKey(appContext) }
preferences.registerOnSharedPreferenceChangeListener(lifecycleOwner) { _, key ->

View File

@ -120,7 +120,7 @@
app:drawableStartCompat="@drawable/ic_storage"
android:text="@string/preference_phone_feature_persistent_storage"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/mediaKeySystemAccessLabel"
app:layout_constraintEnd_toStartOf="@id/persistentStorageStatus"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />
@ -131,10 +131,35 @@
android:layout_width="wrap_content"
android:layout_height="@dimen/quicksettings_item_height"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/mediaKeySystemAccessStatus"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/persistentStorageLabel"
tools:text="@string/preference_option_phone_feature_blocked"
tools:visibility="visible" />
<TextView
android:id="@+id/mediaKeySystemAccessLabel"
style="@style/QuickSettingsText.Icon"
android:layout_width="0dp"
android:layout_height="@dimen/quicksettings_item_height"
app:drawableStartCompat="@drawable/ic_link"
android:text="@string/preference_phone_feature_media_key_system_access"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/mediaKeySystemAccessStatus"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible" />
<TextView
android:id="@+id/mediaKeySystemAccessStatus"
style="@style/QuickSettingsText.PermissionItemEnd"
android:layout_width="wrap_content"
android:layout_height="@dimen/quicksettings_item_height"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/mediaKeySystemAccessLabel"
tools:text="@string/preference_option_phone_feature_blocked"
tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -111,6 +111,7 @@
<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_browser_feature_persistent_storage" translatable="false">pref_key_browser_feature_persistent_storage</string>
<string name="pref_key_browser_feature_media_key_system_access" translatable="false">pref_key_browser_feature_media_key_system_access</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>

View File

@ -843,6 +843,8 @@
<string name="preference_phone_feature_notification">Notification</string>
<!-- Preference for altering the persistent storage access for all websites -->
<string name="preference_phone_feature_persistent_storage">Persistent Storage</string>
<!-- Preference for altering the EME access for all websites -->
<string name="preference_phone_feature_media_key_system_access">DRM-controlled content</string>
<!-- Label that indicates that a permission must be asked always -->
<string name="preference_option_phone_feature_ask_to_allow">Ask to allow</string>
<!-- Label that indicates that a permission must be blocked -->

View File

@ -34,6 +34,12 @@
android:title="@string/preference_phone_feature_persistent_storage"
android:summary="@string/preference_option_phone_feature_ask_to_allow"/>
<androidx.preference.Preference
android:icon="@drawable/ic_link"
android:key="@string/pref_key_browser_feature_media_key_system_access"
android:title="@string/preference_phone_feature_media_key_system_access"
android:summary="@string/preference_option_phone_feature_ask_to_allow"/>
<androidx.preference.Preference
android:key="@string/pref_key_exceptions_clear_site_permissions"
android:layout="@layout/layout_clear_permission_button"/>

View File

@ -43,6 +43,13 @@
android:summary="@string/preference_option_phone_feature_ask_to_allow"
app:allowDividerBelow="true"/>
<androidx.preference.Preference
android:icon="@drawable/ic_link"
android:key="@string/pref_key_browser_feature_media_key_system_access"
android:title="@string/preference_phone_feature_media_key_system_access"
android:summary="@string/preference_option_phone_feature_ask_to_allow"
app:allowDividerBelow="true"/>
<androidx.preference.Preference
android:icon="@drawable/ic_internet"
android:key="@string/pref_key_show_site_exceptions"

View File

@ -95,6 +95,7 @@ class QuickSettingsFragmentStoreTest {
every { permissions.notification } returns SitePermissions.Status.BLOCKED
every { permissions.location } returns SitePermissions.Status.ALLOWED
every { permissions.localStorage } returns SitePermissions.Status.ALLOWED
every { permissions.mediaKeySystemAccess } returns SitePermissions.Status.NO_DECISION
every { permissions.autoplayAudible } returns SitePermissions.Status.BLOCKED
every { permissions.autoplayInaudible } returns SitePermissions.Status.BLOCKED
every { appSettings.getAutoplayUserSetting(any()) } returns AUTOPLAY_BLOCK_ALL
@ -113,6 +114,7 @@ class QuickSettingsFragmentStoreTest {
assertNotNull(state[PhoneFeature.AUTOPLAY_AUDIBLE])
assertNotNull(state[PhoneFeature.AUTOPLAY_INAUDIBLE])
assertNotNull(state[PhoneFeature.PERSISTENT_STORAGE])
assertNotNull(state[PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS])
}
@Test

View File

@ -32,7 +32,8 @@ class SettingsTest {
notification = ASK_TO_ALLOW,
autoplayAudible = AutoplayAction.BLOCKED,
autoplayInaudible = AutoplayAction.BLOCKED,
persistentStorage = ASK_TO_ALLOW
persistentStorage = ASK_TO_ALLOW,
mediaKeySystemAccess = ASK_TO_ALLOW
)
@Before
@ -608,6 +609,23 @@ class SettingsTest {
)
}
@Test
fun getSitePermissionsCustomSettingsRules_mediaKeySystemAccess() {
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS, ALLOWED)
assertEquals(
defaultPermissions.copy(mediaKeySystemAccess = ALLOWED),
settings.getSitePermissionsCustomSettingsRules()
)
settings.setSitePermissionsPhoneFeatureAction(PhoneFeature.MEDIA_KEY_SYSTEM_ACCESS, BLOCKED)
assertEquals(
defaultPermissions.copy(mediaKeySystemAccess = BLOCKED),
settings.getSitePermissionsCustomSettingsRules()
)
}
@Test
fun overrideAmoCollection() {
// When just created