Commit ffd993b4 authored by Jordan Oroshiba's avatar Jordan Oroshiba Committed by Chromium LUCI CQ

Fix issue when coming out of notification settings.

This fixes bug where if looking at site settings in PageInfo or through SingleWebsiteSettings and view Notification preference on Android O+, the notification icon will be duplicated upon returning to setting pages.

Bug: 1163799
Change-Id: I7705b8c4d3bf55cb09ab171ee40e1b9f6c29ef22
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2617463
Commit-Queue: Jordan Oroshiba <oroshiba@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarEhimare Okoyomon <eokoyomon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842604}
parent e240c0b7
...@@ -682,12 +682,16 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -682,12 +682,16 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
return; return;
} }
if (requestCode == REQUEST_CODE_NOTIFICATION_CHANNEL_SETTINGS) { if (requestCode == REQUEST_CODE_NOTIFICATION_CHANNEL_SETTINGS) {
@ContentSettingValues
int newPermission =
mSite.getContentSetting(getSiteSettingsDelegate().getBrowserContextHandle(),
ContentSettingsType.NOTIFICATIONS);
// User has navigated back from system channel settings on O+. Ensure notification // User has navigated back from system channel settings on O+. Ensure notification
// preference is up to date, since they might have toggled it from channel settings. // preference is up to date, since they might have toggled it from channel settings.
Preference notificationsPreference = Preference notificationsPreference =
findPreference(getPreferenceKey(ContentSettingsType.NOTIFICATIONS)); findPreference(getPreferenceKey(ContentSettingsType.NOTIFICATIONS));
if (notificationsPreference != null) { if (notificationsPreference != null) {
setUpNotificationsPreference(notificationsPreference, false /* isEmbargoed */); onPreferenceChange(notificationsPreference, (Object) newPermission);
} }
// To ensure UMA receives notification revocations, we detect if the setting has changed // To ensure UMA receives notification revocations, we detect if the setting has changed
...@@ -695,10 +699,6 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -695,10 +699,6 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
// permission, but do not return immediately to Chrome (e.g. they close the permissions // permission, but do not return immediately to Chrome (e.g. they close the permissions
// activity, instead of hitting the back button), but prevents us from having to check // activity, instead of hitting the back button), but prevents us from having to check
// for changes each time Chrome becomes active. // for changes each time Chrome becomes active.
@ContentSettingValues
int newPermission =
mSite.getContentSetting(getSiteSettingsDelegate().getBrowserContextHandle(),
ContentSettingsType.NOTIFICATIONS);
if (mPreviousNotificationPermission == ContentSettingValues.ALLOW if (mPreviousNotificationPermission == ContentSettingValues.ALLOW
&& newPermission != ContentSettingValues.ALLOW) { && newPermission != ContentSettingValues.ALLOW) {
WebsitePreferenceBridgeJni.get().reportNotificationRevokedForOrigin( WebsitePreferenceBridgeJni.get().reportNotificationRevokedForOrigin(
...@@ -936,10 +936,10 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -936,10 +936,10 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
preference.setIcon(getContentSettingsIcon(contentType, value, true)); preference.setIcon(getContentSettingsIcon(contentType, value, true));
} }
preference.setOrder(++mMaxPermissionOrder);
// These preferences are persisted elsewhere, using SharedPreferences // These preferences are persisted elsewhere, using SharedPreferences
// can cause issues with keys matching up with value. // can cause issues with keys matching up with value.
preference.setPersistent(false); preference.setPersistent(false);
preference.setOrder(++mMaxPermissionOrder);
getPreferenceScreen().addPreference(preference); getPreferenceScreen().addPreference(preference);
} }
...@@ -1117,11 +1117,14 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment ...@@ -1117,11 +1117,14 @@ public class SingleWebsiteSettings extends SiteSettingsPreferenceFragment
@ContentSettingValues @ContentSettingValues
int permission; int permission;
if (preference instanceof ListPreference) { if (newValue instanceof Boolean) {
permission = ContentSetting.fromString((String) newValue);
} else {
permission = permission =
(Boolean) newValue ? ContentSettingValues.ALLOW : ContentSettingValues.BLOCK; (Boolean) newValue ? ContentSettingValues.ALLOW : ContentSettingValues.BLOCK;
// TODO(crbug.com/1165765): Remove when ListPreferences are no longer used.
} else if (newValue instanceof String) {
permission = ContentSetting.fromString((String) newValue);
} else {
permission = (Integer) newValue;
} }
mSite.setContentSetting(browserContextHandle, type, permission); mSite.setContentSetting(browserContextHandle, type, permission);
......
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