Commit 5ea0e6e8 authored by Kamila's avatar Kamila Committed by Commit Bot

Allow the user to disable permission prompts when disabled in Android (behind flag)

1. Enables modification of the toggle of Chrome Site Settings permissions which can be managed
in Android. This is done in order for the user to be able to disable these permissions in
settings, even when access is not granted to Chrome in Android.

The permissions modified are:
- Camera
- Location
- Microphone
- Notifications

2. Changes the string and makes it appear only when the permission is disabled for Chrome, but
the user hasn't disabled the permission in Chrome. (as per comments in patchset 5)

---------
Images
---------
Before
In any case when location is blocked for Chrome in Android:
https://imgur.com/a/6r2MMan

After
Location Blocked for Chrome and in Chrome: https://imgur.com/a/wsXfrzL
Location Blocked for Chrome but "Ask" in Chrome: https://imgur.com/a/qiq3XTP

---------
Note
---------
This cl was initially intended just to change the UI for Location permission, but the change
makes sense for all permissions similar to Location. The initial image with only the location
change until patchset 5 was: https://imgur.com/a/WjHqUZu


Bug: 814106
Change-Id: Iefd929cf85f83a6f1dd3155c75875c2d3f66829d
Reviewed-on: https://chromium-review.googlesource.com/c/1275853
Commit-Queue: Kamila Hasanbega <hkamila@google.com>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609301}
parent e259f019
......@@ -713,7 +713,7 @@ public class SingleCategoryPreferences extends PreferenceFragment
int contentType = mCategory.getContentSettingsType();
PreferenceScreen screen = getPreferenceScreen();
// Find all preferencs on the current preference screen. Some preferences are
// Find all preferences on the current preference screen. Some preferences are
// not needed for the current category and will be removed in the steps below.
ChromeSwitchPreference binaryToggle =
(ChromeSwitchPreference) screen.findPreference(BINARY_TOGGLE_KEY);
......@@ -724,51 +724,41 @@ public class SingleCategoryPreferences extends PreferenceFragment
Preference explainProtectedMediaKey = screen.findPreference(EXPLAIN_PROTECTED_MEDIA_KEY);
PreferenceGroup allowedGroup = (PreferenceGroup) screen.findPreference(ALLOWED_GROUP);
PreferenceGroup blockedGroup = (PreferenceGroup) screen.findPreference(BLOCKED_GROUP);
boolean permissionBlockedByOs = mCategory.showPermissionBlockedMessage(getActivity());
// For these categories, no binary, tri-state or custom toggles should be shown.
boolean hideAllToggles = mCategory.showSites(SiteSettingsCategory.Type.ALL_SITES)
boolean hideMainToggles = mCategory.showSites(SiteSettingsCategory.Type.ALL_SITES)
|| mCategory.showSites(SiteSettingsCategory.Type.USE_STORAGE)
|| mCategory.showPermissionBlockedMessage(getActivity());
|| (permissionBlockedByOs
&& !ChromeFeatureList.isEnabled(
ChromeFeatureList.ANDROID_SITE_SETTINGS_UI));
boolean hideSecondaryToggles = hideMainToggles || permissionBlockedByOs;
if (hideAllToggles) {
if (hideMainToggles) {
screen.removePreference(binaryToggle);
screen.removePreference(triStateToggle);
} else if (mRequiresTriStateSetting) {
screen.removePreference(binaryToggle);
configureTriStateToggle(triStateToggle, contentType);
} else {
screen.removePreference(triStateToggle);
configureBinaryToggle(binaryToggle, contentType);
}
if (permissionBlockedByOs) {
maybeShowOsWarning(screen);
}
if (hideSecondaryToggles) {
screen.removePreference(thirdPartyCookies);
screen.removePreference(notificationsVibrate);
screen.removePreference(explainProtectedMediaKey);
screen.removePreference(allowedGroup);
screen.removePreference(blockedGroup);
if (mCategory.showPermissionBlockedMessage(getActivity())) {
// Show the link to system settings since permission is disabled.
ChromeBasePreference osWarning = new ChromeBasePreference(getActivity(), null);
ChromeBasePreference osWarningExtra = new ChromeBasePreference(getActivity(), null);
mCategory.configurePermissionIsOffPreferences(
osWarning, osWarningExtra, getActivity(), true);
if (osWarning.getTitle() != null) {
screen.addPreference(osWarning);
}
if (osWarningExtra.getTitle() != null) {
screen.addPreference(osWarningExtra);
}
}
// Since all preferences are hidden, there's nothing to do further and we can
// simply return.
return;
}
// Now show and configure the binary toggle or the tri-state toggle, but not both.
// No early return in either case since we also need to configure the category
// specific toggles (e.g. third-party cookie) below.
if (mRequiresTriStateSetting) {
screen.removePreference(binaryToggle);
configureTriStateToggle(triStateToggle, contentType);
} else {
screen.removePreference(triStateToggle);
configureBinaryToggle(binaryToggle, contentType);
}
// Configure/hide the third-party cookie toggle, as needed.
if (mCategory.showSites(SiteSettingsCategory.Type.COOKIES)) {
thirdPartyCookies.setOnPreferenceChangeListener(this);
......@@ -802,6 +792,25 @@ public class SingleCategoryPreferences extends PreferenceFragment
blockedGroup.setOnPreferenceClickListener(this);
}
private void maybeShowOsWarning(PreferenceScreen screen) {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_SITE_SETTINGS_UI)
&& isBlocked()) {
return;
}
// Show the link to system settings since permission is disabled.
ChromeBasePreference osWarning = new ChromeBasePreference(getActivity(), null);
ChromeBasePreference osWarningExtra = new ChromeBasePreference(getActivity(), null);
mCategory.configurePermissionIsOffPreferences(
osWarning, osWarningExtra, getActivity(), true);
if (osWarning.getTitle() != null) {
screen.addPreference(osWarning);
}
if (osWarningExtra.getTitle() != null) {
screen.addPreference(osWarningExtra);
}
}
private void configureTriStateToggle(
TriStateSiteSettingsPreference triStateToggle, int contentType) {
triStateToggle.setOnPreferenceChangeListener(this);
......
......@@ -404,9 +404,14 @@ public class SiteSettingsCategory {
* @param plural Whether it applies to one per-app permission or multiple.
*/
protected String getMessageForEnablingOsPerAppPermission(Activity activity, boolean plural) {
return activity.getResources().getString(plural
? R.string.android_permission_off_plural
: R.string.android_permission_off);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.ANDROID_SITE_SETTINGS_UI)) {
return activity.getResources().getString(plural
? R.string.android_permission_also_off_plural
: R.string.android_permission_also_off);
} else {
return activity.getResources().getString(plural ? R.string.android_permission_off_plural
: R.string.android_permission_off);
}
}
/**
......
......@@ -1155,6 +1155,12 @@ Your Google account may have other forms of browsing history like searches and a
<message name="IDS_ANDROID_PERMISSION_OFF" desc="Text at the top of the Website list, explaining to the user that a permission, such as the location service, is turned off. Contains a link to the settings menu to change it.">
Turn on permission for Chrome in <ph name="BEGIN_LINK">&lt;link&gt;</ph>Android Settings<ph name="END_LINK">&lt;/link&gt;</ph>.
</message>
<message name="IDS_ANDROID_PERMISSION_ALSO_OFF" desc="The message to show when a permission needs to be turned on not just in Chrome, but also in Android settings.">
You also need to turn this permission on for Chrome. See <ph name="BEGIN_LINK">&lt;link&gt;</ph>Android Settings<ph name="END_LINK">&lt;/link&gt;</ph> for details.
</message>
<message name="IDS_ANDROID_PERMISSION_ALSO_OFF_PLURAL" desc="The message to show when a permission needs to be turned on not just in Chrome, but also in Android settings.">
You also need to turn these permissions on for Chrome. See <ph name="BEGIN_LINK">&lt;link&gt;</ph>Android Settings<ph name="END_LINK">&lt;/link&gt;</ph> for details.
</message>
<message name="IDS_ANDROID_LOCATION_OFF_GLOBALLY" desc="The message to show when Location has been turned off globally in Android. Contains a link to the settings menu to enable location.">
Location access is off for this device. Turn it on in <ph name="BEGIN_LINK">&lt;link&gt;</ph>Android Settings<ph name="END_LINK">&lt;/link&gt;</ph>.
</message>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment