Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.notifications; | 5 package org.chromium.chrome.browser.notifications; |
| 6 | 6 |
| 7 import android.app.Notification; | 7 import android.app.Notification; |
| 8 import android.app.NotificationManager; | 8 import android.app.NotificationManager; |
| 9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 import org.chromium.base.ContextUtils; | 23 import org.chromium.base.ContextUtils; |
| 24 import org.chromium.base.Log; | 24 import org.chromium.base.Log; |
| 25 import org.chromium.base.VisibleForTesting; | 25 import org.chromium.base.VisibleForTesting; |
| 26 import org.chromium.base.annotations.CalledByNative; | 26 import org.chromium.base.annotations.CalledByNative; |
| 27 import org.chromium.base.library_loader.ProcessInitException; | 27 import org.chromium.base.library_loader.ProcessInitException; |
| 28 import org.chromium.base.metrics.RecordHistogram; | 28 import org.chromium.base.metrics.RecordHistogram; |
| 29 import org.chromium.base.metrics.RecordUserAction; | 29 import org.chromium.base.metrics.RecordUserAction; |
| 30 import org.chromium.chrome.R; | 30 import org.chromium.chrome.R; |
| 31 import org.chromium.chrome.browser.ChromeSwitches; | 31 import org.chromium.chrome.browser.ChromeSwitches; |
| 32 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | 32 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 33 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | |
| 33 import org.chromium.chrome.browser.preferences.Preferences; | 34 import org.chromium.chrome.browser.preferences.Preferences; |
| 34 import org.chromium.chrome.browser.preferences.PreferencesLauncher; | 35 import org.chromium.chrome.browser.preferences.PreferencesLauncher; |
| 35 import org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences ; | 36 import org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences ; |
| 36 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; | 37 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; |
| 37 import org.chromium.chrome.browser.preferences.website.SiteSettingsCategory; | 38 import org.chromium.chrome.browser.preferences.website.SiteSettingsCategory; |
| 38 import org.chromium.chrome.browser.util.UrlUtilities; | 39 import org.chromium.chrome.browser.util.UrlUtilities; |
| 39 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 40 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
| 40 import org.chromium.webapk.lib.client.WebApkValidator; | 41 import org.chromium.webapk.lib.client.WebApkValidator; |
| 41 | 42 |
| 42 import java.net.URI; | 43 import java.net.URI; |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 URI uri = new URI(parts[1]); | 405 URI uri = new URI(parts[1]); |
| 405 if (uri.getHost() != null) return parts[1]; | 406 if (uri.getHost() != null) return parts[1]; |
| 406 } catch (URISyntaxException e) { | 407 } catch (URISyntaxException e) { |
| 407 Log.e(TAG, "Expected to find a valid url in the notification tag ext ra.", e); | 408 Log.e(TAG, "Expected to find a valid url in the notification tag ext ra.", e); |
| 408 return null; | 409 return null; |
| 409 } | 410 } |
| 410 return null; | 411 return null; |
| 411 } | 412 } |
| 412 | 413 |
| 413 /** | 414 /** |
| 414 * Generates the notfiication defaults from vibrationPattern's size and sile nt. | 415 * Generates the notification defaults from vibrationPattern's size and sile nt. |
| 415 * | 416 * |
| 416 * Use the system's default ringtone, vibration and indicator lights unless the notification | 417 * Use the system's default ringtone, vibration and indicator lights unless the notification |
| 417 * has been marked as being silent. | 418 * has been marked as being silent. |
| 418 * If a vibration pattern is set, the notification should use the provided p attern | 419 * If a vibration pattern is set, the notification should use the provided p attern |
| 419 * rather than the defaulting to system settings. | 420 * rather than defaulting to the system settings. |
| 420 * | 421 * |
| 421 * @param vibrationPatternLength Vibration pattern's size for the Notificati on. | 422 * @param vibrationPatternLength Vibration pattern's size for the Notificati on. |
| 422 * @param silent Whether the default sound, vibration and lights should be s uppressed. | 423 * @param silent Whether the default sound, vibration and lights should be s uppressed. |
| 424 * @param vibrateEnabled Whether vibration is enabled in preferences. | |
| 423 * @return The generated notification's default value. | 425 * @return The generated notification's default value. |
| 424 */ | 426 */ |
| 425 @VisibleForTesting | 427 @VisibleForTesting |
| 426 static int makeDefaults(int vibrationPatternLength, boolean silent) { | 428 static int makeDefaults(int vibrationPatternLength, boolean silent, boolean vibrateEnabled) { |
| 427 assert !silent || vibrationPatternLength == 0; | 429 assert !silent || vibrationPatternLength == 0; |
| 428 | 430 |
| 429 if (silent) return 0; | 431 if (silent) return 0; |
| 430 | 432 |
| 431 int defaults = Notification.DEFAULT_ALL; | 433 int defaults = Notification.DEFAULT_ALL; |
| 432 if (vibrationPatternLength > 0) { | 434 if (vibrationPatternLength > 0 || !vibrateEnabled) { |
| 433 defaults &= ~Notification.DEFAULT_VIBRATE; | 435 defaults &= ~Notification.DEFAULT_VIBRATE; |
| 434 } | 436 } |
| 435 return defaults; | 437 return defaults; |
| 436 } | 438 } |
| 437 | 439 |
| 438 /** | 440 /** |
| 439 * Generates the vibration pattern used in Android notification. | 441 * Generates the vibration pattern used in Android notification. |
| 440 * | 442 * |
| 441 * Android takes a long array where the first entry indicates the number of milliseconds to wait | 443 * Android takes a long array where the first entry indicates the number of milliseconds to wait |
| 442 * prior to starting the vibration, whereas Chrome follows the syntax of the Web Vibration API. | 444 * prior to starting the vibration, whereas Chrome follows the syntax of the Web Vibration API. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 // the label and icon provided here only affect Android Wear, so don't a bbreviate them. | 547 // the label and icon provided here only affect Android Wear, so don't a bbreviate them. |
| 546 boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLa youts(); | 548 boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLa youts(); |
| 547 int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_co g; | 549 int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_co g; |
| 548 CharSequence settingsTitle = abbreviateSiteSettings | 550 CharSequence settingsTitle = abbreviateSiteSettings |
| 549 ? res.getString(R.string.notification_site_ settings_button) | 551 ? res.getString(R.string.notification_site_ settings_button) |
| 550 : res.getString(R.string.page_info_site_set tings_button); | 552 : res.getString(R.string.page_info_site_set tings_button); |
| 551 // If the settings button is displayed together with the other buttons i t has to be the last | 553 // If the settings button is displayed together with the other buttons i t has to be the last |
| 552 // one, so add it after the other actions. | 554 // one, so add it after the other actions. |
| 553 notificationBuilder.addSettingsAction(settingsIconId, settingsTitle, pen dingSettingsIntent); | 555 notificationBuilder.addSettingsAction(settingsIconId, settingsTitle, pen dingSettingsIntent); |
| 554 | 556 |
| 555 notificationBuilder.setDefaults(makeDefaults(vibrationPattern.length, si lent)); | 557 // The Android framework applies a fallback vibration pattern for the so und when the device |
| 556 if (vibrationPattern.length > 0) { | 558 // is in vibrate mode, there is no custom pattern, and the vibration def ault has been |
| 557 notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern )); | 559 // disabled. To truly prevent vibration, provide a custom empty pattern. |
| 560 boolean vibrateEnabled = PrefServiceBridge.getInstance().isNotifications VibrateEnabled(); | |
| 561 if (!vibrateEnabled) { | |
| 562 vibrationPattern = new int[0]; | |
|
gone
2016/06/07 17:32:54
Might it be clearer to add a
private static final
Michael van Ouwerkerk
2016/06/08 13:28:13
Done.
| |
| 558 } | 563 } |
| 564 notificationBuilder.setDefaults( | |
| 565 makeDefaults(vibrationPattern.length, silent, vibrateEnabled)); | |
| 566 notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern)); | |
| 559 | 567 |
| 560 String platformTag = makePlatformTag(persistentNotificationId, origin, t ag); | 568 String platformTag = makePlatformTag(persistentNotificationId, origin, t ag); |
| 561 if (webApkPackage.isEmpty()) { | 569 if (webApkPackage.isEmpty()) { |
| 562 mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBu ilder.build()); | 570 mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBu ilder.build()); |
| 563 } else { | 571 } else { |
| 564 WebApkNotificationClient.notifyNotification( | 572 WebApkNotificationClient.notifyNotification( |
| 565 webApkPackage, notificationBuilder, platformTag, PLATFORM_ID ); | 573 webApkPackage, notificationBuilder, platformTag, PLATFORM_ID ); |
| 566 } | 574 } |
| 567 } | 575 } |
| 568 | 576 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 | 733 |
| 726 private static native void nativeInitializeNotificationPlatformBridge(); | 734 private static native void nativeInitializeNotificationPlatformBridge(); |
| 727 | 735 |
| 728 private native void nativeOnNotificationClicked(long nativeNotificationPlatf ormBridgeAndroid, | 736 private native void nativeOnNotificationClicked(long nativeNotificationPlatf ormBridgeAndroid, |
| 729 long persistentNotificationId, String origin, String profileId, bool ean incognito, | 737 long persistentNotificationId, String origin, String profileId, bool ean incognito, |
| 730 String tag, String webApkPackage, int actionIndex); | 738 String tag, String webApkPackage, int actionIndex); |
| 731 private native void nativeOnNotificationClosed(long nativeNotificationPlatfo rmBridgeAndroid, | 739 private native void nativeOnNotificationClosed(long nativeNotificationPlatfo rmBridgeAndroid, |
| 732 long persistentNotificationId, String origin, String profileId, bool ean incognito, | 740 long persistentNotificationId, String origin, String profileId, bool ean incognito, |
| 733 String tag, boolean byUser); | 741 String tag, boolean byUser); |
| 734 } | 742 } |
| OLD | NEW |