Commit d03acd3d authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Clank: use PrefService instead of PrefServiceBridge for notifications.

Bug: 1071603
Change-Id: Icbb428e40d2dad8b807ce2298da0a3c01ffcf11d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2288328
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789600}
parent 9e128b59
...@@ -38,7 +38,7 @@ import org.chromium.chrome.browser.ChromeApplication; ...@@ -38,7 +38,7 @@ import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.browserservices.TrustedWebActivityClient; import org.chromium.chrome.browser.browserservices.TrustedWebActivityClient;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer; import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.notifications.channels.SiteChannelsManager; import org.chromium.chrome.browser.notifications.channels.SiteChannelsManager;
import org.chromium.chrome.browser.preferences.PrefServiceBridge; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.settings.SettingsLauncher; import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.SettingsLauncherImpl; import org.chromium.chrome.browser.settings.SettingsLauncherImpl;
import org.chromium.chrome.browser.usage_stats.NotificationSuspender; import org.chromium.chrome.browser.usage_stats.NotificationSuspender;
...@@ -54,6 +54,7 @@ import org.chromium.components.browser_ui.site_settings.SingleWebsiteSettings; ...@@ -54,6 +54,7 @@ import org.chromium.components.browser_ui.site_settings.SingleWebsiteSettings;
import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory; import org.chromium.components.browser_ui.site_settings.SiteSettingsCategory;
import org.chromium.components.url_formatter.SchemeDisplay; import org.chromium.components.url_formatter.SchemeDisplay;
import org.chromium.components.url_formatter.UrlFormatter; import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.components.webapk.lib.client.WebApkValidator; import org.chromium.components.webapk.lib.client.WebApkValidator;
import org.chromium.url.URI; import org.chromium.url.URI;
import org.chromium.webapk.lib.client.WebApkIdentityServiceClient; import org.chromium.webapk.lib.client.WebApkIdentityServiceClient;
...@@ -469,7 +470,7 @@ public class NotificationPlatformBridge { ...@@ -469,7 +470,7 @@ public class NotificationPlatformBridge {
* @param scopeUrl The scope of the service worker registered by the site where the notification * @param scopeUrl The scope of the service worker registered by the site where the notification
* comes from. * comes from.
* @param profileId Id of the profile that showed the notification. * @param profileId Id of the profile that showed the notification.
* @param incognito if the session of the profile is an off the record one. * @param profile The profile that showed the notification.
* @param title Title to be displayed in the notification. * @param title Title to be displayed in the notification.
* @param body Message to be displayed in the notification. Will be trimmed to one line of * @param body Message to be displayed in the notification. Will be trimmed to one line of
* text by the Android notification system. * text by the Android notification system.
...@@ -490,16 +491,19 @@ public class NotificationPlatformBridge { ...@@ -490,16 +491,19 @@ public class NotificationPlatformBridge {
@CalledByNative @CalledByNative
private void displayNotification(final String notificationId, private void displayNotification(final String notificationId,
@NotificationType final int notificationType, final String origin, @NotificationType final int notificationType, final String origin,
final String scopeUrl, final String profileId, final boolean incognito, final String scopeUrl, final String profileId, final Profile profile,
final String title, final String body, final Bitmap image, final Bitmap icon, final String title, final String body, final Bitmap image, final Bitmap icon,
final Bitmap badge, final int[] vibrationPattern, final long timestamp, final Bitmap badge, final int[] vibrationPattern, final long timestamp,
final boolean renotify, final boolean silent, final ActionInfo[] actions) { final boolean renotify, final boolean silent, final ActionInfo[] actions) {
final boolean vibrateEnabled = UserPrefs.get(Profile.getLastUsedRegularProfile())
.getBoolean(NOTIFICATIONS_VIBRATE_ENABLED);
final boolean incognito = profile.isOffTheRecord();
// TODO(peter): by-pass this check for non-Web Notification types. // TODO(peter): by-pass this check for non-Web Notification types.
getWebApkPackage(scopeUrl).then( getWebApkPackage(scopeUrl).then(
(Callback<String>) (webApkPackage) (Callback<String>) (webApkPackage)
-> displayNotificationInternal(notificationId, notificationType, origin, -> displayNotificationInternal(notificationId, notificationType, origin,
scopeUrl, profileId, incognito, title, body, image, icon, badge, scopeUrl, profileId, incognito, vibrateEnabled, title, body, image,
vibrationPattern, timestamp, renotify, silent, actions, icon, badge, vibrationPattern, timestamp, renotify, silent, actions,
webApkPackage)); webApkPackage));
} }
...@@ -517,18 +521,19 @@ public class NotificationPlatformBridge { ...@@ -517,18 +521,19 @@ public class NotificationPlatformBridge {
/** Called after querying whether the browser backs the given WebAPK. */ /** Called after querying whether the browser backs the given WebAPK. */
private void displayNotificationInternal(String notificationId, private void displayNotificationInternal(String notificationId,
@NotificationType int notificationType, String origin, String scopeUrl, @NotificationType int notificationType, String origin, String scopeUrl,
String profileId, boolean incognito, String title, String body, Bitmap image, String profileId, boolean incognito, boolean vibrateEnabled, String title, String body,
Bitmap icon, Bitmap badge, int[] vibrationPattern, long timestamp, boolean renotify, Bitmap image, Bitmap icon, Bitmap badge, int[] vibrationPattern, long timestamp,
boolean silent, ActionInfo[] actions, String webApkPackage) { boolean renotify, boolean silent, ActionInfo[] actions, String webApkPackage) {
NotificationPlatformBridgeJni.get().storeCachedWebApkPackageForNotificationId( NotificationPlatformBridgeJni.get().storeCachedWebApkPackageForNotificationId(
mNativeNotificationPlatformBridge, NotificationPlatformBridge.this, notificationId, mNativeNotificationPlatformBridge, NotificationPlatformBridge.this, notificationId,
webApkPackage); webApkPackage);
// Record whether it's known whether notifications can be shown to the user at all. // Record whether it's known whether notifications can be shown to the user at all.
NotificationSystemStatusUtil.recordAppNotificationStatusHistogram(); NotificationSystemStatusUtil.recordAppNotificationStatusHistogram();
NotificationBuilderBase notificationBuilder = prepareNotificationBuilder(notificationId, NotificationBuilderBase notificationBuilder =
notificationType, origin, scopeUrl, profileId, incognito, title, body, image, icon, prepareNotificationBuilder(notificationId, notificationType, origin, scopeUrl,
badge, vibrationPattern, timestamp, renotify, silent, actions, webApkPackage); profileId, incognito, vibrateEnabled, title, body, image, icon, badge,
vibrationPattern, timestamp, renotify, silent, actions, webApkPackage);
// Delegate notification to WebAPK. // Delegate notification to WebAPK.
if (!webApkPackage.isEmpty()) { if (!webApkPackage.isEmpty()) {
...@@ -569,9 +574,9 @@ public class NotificationPlatformBridge { ...@@ -569,9 +574,9 @@ public class NotificationPlatformBridge {
private NotificationBuilderBase prepareNotificationBuilder(String notificationId, private NotificationBuilderBase prepareNotificationBuilder(String notificationId,
@NotificationType int notificationType, String origin, String scopeUrl, @NotificationType int notificationType, String origin, String scopeUrl,
String profileId, boolean incognito, String title, String body, Bitmap image, String profileId, boolean incognito, boolean vibrateEnabled, String title, String body,
Bitmap icon, Bitmap badge, int[] vibrationPattern, long timestamp, boolean renotify, Bitmap image, Bitmap icon, Bitmap badge, int[] vibrationPattern, long timestamp,
boolean silent, ActionInfo[] actions, String webApkPackage) { boolean renotify, boolean silent, ActionInfo[] actions, String webApkPackage) {
Context context = ContextUtils.getApplicationContext(); Context context = ContextUtils.getApplicationContext();
PendingIntentProvider clickIntent = makePendingIntent(context, PendingIntentProvider clickIntent = makePendingIntent(context,
...@@ -628,8 +633,6 @@ public class NotificationPlatformBridge { ...@@ -628,8 +633,6 @@ public class NotificationPlatformBridge {
// The Android framework applies a fallback vibration pattern for the sound when the device // The Android framework applies a fallback vibration pattern for the sound when the device
// is in vibrate mode, there is no custom pattern, and the vibration default has been // is in vibrate mode, there is no custom pattern, and the vibration default has been
// disabled. To truly prevent vibration, provide a custom empty pattern. // disabled. To truly prevent vibration, provide a custom empty pattern.
boolean vibrateEnabled =
PrefServiceBridge.getInstance().getBoolean(NOTIFICATIONS_VIBRATE_ENABLED);
if (!vibrateEnabled) { if (!vibrateEnabled) {
vibrationPattern = EMPTY_VIBRATION_PATTERN; vibrationPattern = EMPTY_VIBRATION_PATTERN;
} }
......
...@@ -38,7 +38,6 @@ import org.chromium.chrome.R; ...@@ -38,7 +38,6 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.engagement.SiteEngagementService; import org.chromium.chrome.browser.engagement.SiteEngagementService;
import org.chromium.chrome.browser.flags.ChromeSwitches; import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.permissions.PermissionTestRule; import org.chromium.chrome.browser.permissions.PermissionTestRule;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -49,6 +48,7 @@ import org.chromium.components.content_settings.ContentSettingValues; ...@@ -49,6 +48,7 @@ import org.chromium.components.content_settings.ContentSettingValues;
import org.chromium.components.permissions.PermissionDialogController; import org.chromium.components.permissions.PermissionDialogController;
import org.chromium.components.url_formatter.SchemeDisplay; import org.chromium.components.url_formatter.SchemeDisplay;
import org.chromium.components.url_formatter.UrlFormatter; import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
...@@ -444,8 +444,8 @@ public class NotificationPlatformBridgeTest { ...@@ -444,8 +444,8 @@ public class NotificationPlatformBridgeTest {
// Disable notification vibration in preferences. // Disable notification vibration in preferences.
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() ()
-> PrefServiceBridge.getInstance().setBoolean( -> UserPrefs.get(Profile.getLastUsedRegularProfile())
NOTIFICATIONS_VIBRATE_ENABLED, false)); .setBoolean(NOTIFICATIONS_VIBRATE_ENABLED, false));
Notification notification = showAndGetNotification("MyNotification", notificationOptions); Notification notification = showAndGetNotification("MyNotification", notificationOptions);
...@@ -494,8 +494,8 @@ public class NotificationPlatformBridgeTest { ...@@ -494,8 +494,8 @@ public class NotificationPlatformBridgeTest {
// By default, vibration is enabled in notifications. // By default, vibration is enabled in notifications.
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() ()
-> Assert.assertTrue(PrefServiceBridge.getInstance().getBoolean( -> Assert.assertTrue(UserPrefs.get(Profile.getLastUsedRegularProfile())
NOTIFICATIONS_VIBRATE_ENABLED))); .getBoolean(NOTIFICATIONS_VIBRATE_ENABLED)));
Notification notification = showAndGetNotification("MyNotification", "{ vibrate: 42 }"); Notification notification = showAndGetNotification("MyNotification", "{ vibrate: 42 }");
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "chrome/browser/notifications/notification_common.h" #include "chrome/browser/notifications/notification_common.h"
#include "chrome/browser/notifications/notification_display_service_impl.h" #include "chrome/browser/notifications/notification_display_service_impl.h"
#include "chrome/browser/notifications/platform_notification_service_impl.h" #include "chrome/browser/notifications/platform_notification_service_impl.h"
#include "chrome/browser/profiles/profile_android.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "components/content_settings/core/common/pref_names.h" #include "components/content_settings/core/common/pref_names.h"
...@@ -276,6 +277,8 @@ void NotificationPlatformBridgeAndroid::Display( ...@@ -276,6 +277,8 @@ void NotificationPlatformBridgeAndroid::Display(
ConvertUTF8ToJavaString(env, notification.id()); ConvertUTF8ToJavaString(env, notification.id());
ScopedJavaLocalRef<jstring> j_origin = ScopedJavaLocalRef<jstring> j_origin =
ConvertUTF8ToJavaString(env, origin_url.spec()); ConvertUTF8ToJavaString(env, origin_url.spec());
ScopedJavaLocalRef<jobject> android_profile =
ProfileAndroid::FromProfile(profile)->GetJavaObject();
ScopedJavaLocalRef<jstring> title = ScopedJavaLocalRef<jstring> title =
ConvertUTF16ToJavaString(env, notification.title()); ConvertUTF16ToJavaString(env, notification.title());
ScopedJavaLocalRef<jstring> body = ScopedJavaLocalRef<jstring> body =
...@@ -309,7 +312,7 @@ void NotificationPlatformBridgeAndroid::Display( ...@@ -309,7 +312,7 @@ void NotificationPlatformBridgeAndroid::Display(
Java_NotificationPlatformBridge_displayNotification( Java_NotificationPlatformBridge_displayNotification(
env, java_object_, j_notification_id, j_notification_type, j_origin, env, java_object_, j_notification_id, j_notification_type, j_origin,
j_scope_url, j_profile_id, profile->IsOffTheRecord(), title, body, image, j_scope_url, j_profile_id, android_profile, title, body, image,
notification_icon, badge, vibration_pattern, notification_icon, badge, vibration_pattern,
notification.timestamp().ToJavaTime(), notification.renotify(), notification.timestamp().ToJavaTime(), notification.renotify(),
notification.silent(), actions); notification.silent(), actions);
......
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