From 042f7dd697d9cc93f436a6450e1ac99a62ff12e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 4 Dec 2020 00:41:59 +0100 Subject: [PATCH] [fenix] Add support for EME permission. This accompanies the changes in https://github.com/mozilla-mobile/android-components/pull/9121. Closes https://github.com/mozilla-mobile/fenix/issues/1175 --- .../org/mozilla/fenix/settings/Extensions.kt | 2 ++ .../mozilla/fenix/settings/PhoneFeature.kt | 5 +++- .../quicksettings/WebsitePermissionsView.kt | 4 +++ ...itePermissionsDetailsExceptionsFragment.kt | 2 ++ ...tePermissionsManagePhoneFeatureFragment.kt | 8 +++++ .../java/org/mozilla/fenix/utils/Settings.kt | 7 +++-- .../res/layout/quicksettings_permissions.xml | 29 +++++++++++++++++-- app/src/main/res/values/preference_keys.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ ...issions_details_exceptions_preferences.xml | 6 ++++ .../res/xml/site_permissions_preferences.xml | 7 +++++ .../QuickSettingsFragmentStoreTest.kt | 2 ++ .../org/mozilla/fenix/utils/SettingsTest.kt | 20 ++++++++++++- 13 files changed, 89 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt b/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt index b264461855..2ede851aac 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt @@ -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) } /** diff --git a/app/src/main/java/org/mozilla/fenix/settings/PhoneFeature.kt b/app/src/main/java/org/mozilla/fenix/settings/PhoneFeature.kt index 31ca24ecb0..46e9d13e11 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/PhoneFeature.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/PhoneFeature.kt @@ -31,7 +31,8 @@ enum class PhoneFeature(val androidPermissionsList: Array) : 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) : 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) : 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 } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt index 44d0f85768..fbfb00e03f 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/quicksettings/WebsitePermissionsView.kt @@ -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 ) ) ) diff --git a/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt index cda13889c6..5b4d0aa992 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt @@ -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() } diff --git a/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsManagePhoneFeatureFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsManagePhoneFeatureFragment.kt index d96f44836e..5acba52b31 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsManagePhoneFeatureFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsManagePhoneFeatureFragment.kt @@ -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 } diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 985572be6b..6a27905ded 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -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 -> diff --git a/app/src/main/res/layout/quicksettings_permissions.xml b/app/src/main/res/layout/quicksettings_permissions.xml index 1acf683622..9aa2e1be9a 100644 --- a/app/src/main/res/layout/quicksettings_permissions.xml +++ b/app/src/main/res/layout/quicksettings_permissions.xml @@ -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" /> + + + + diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 4f8d45e6e9..556aec5736 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -111,6 +111,7 @@ pref_key_browser_feature_autoplay pref_key_browser_feature_autoplay_inaudible pref_key_browser_feature_persistent_storage + pref_key_browser_feature_media_key_system_access pref_key_phone_feature_camera pref_key_phone_feature_location pref_key_phone_feature_microphone diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aafc1dfb97..50e0972750 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -843,6 +843,8 @@ Notification Persistent Storage + + DRM-controlled content Ask to allow diff --git a/app/src/main/res/xml/site_permissions_details_exceptions_preferences.xml b/app/src/main/res/xml/site_permissions_details_exceptions_preferences.xml index ee2767fd56..8513deb5e4 100644 --- a/app/src/main/res/xml/site_permissions_details_exceptions_preferences.xml +++ b/app/src/main/res/xml/site_permissions_details_exceptions_preferences.xml @@ -34,6 +34,12 @@ android:title="@string/preference_phone_feature_persistent_storage" android:summary="@string/preference_option_phone_feature_ask_to_allow"/> + + diff --git a/app/src/main/res/xml/site_permissions_preferences.xml b/app/src/main/res/xml/site_permissions_preferences.xml index 85e8229446..b51956e709 100644 --- a/app/src/main/res/xml/site_permissions_preferences.xml +++ b/app/src/main/res/xml/site_permissions_preferences.xml @@ -43,6 +43,13 @@ android:summary="@string/preference_option_phone_feature_ask_to_allow" app:allowDividerBelow="true"/> + +