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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 URI uri = new URI(parts[1]); | 283 URI uri = new URI(parts[1]); |
| 284 if (uri.getHost() != null) return parts[1]; | 284 if (uri.getHost() != null) return parts[1]; |
| 285 } catch (URISyntaxException e) { | 285 } catch (URISyntaxException e) { |
| 286 Log.e(TAG, "Expected to find a valid url in the notification tag ext ra.", e); | 286 Log.e(TAG, "Expected to find a valid url in the notification tag ext ra.", e); |
| 287 return null; | 287 return null; |
| 288 } | 288 } |
| 289 return null; | 289 return null; |
| 290 } | 290 } |
| 291 | 291 |
| 292 /** | 292 /** |
| 293 * Generates the notfiication defaults from vibratePattern's size and silent . | |
| 294 * | |
| 295 * Use the system's default ringtone, vibration and indicator lights unless the notification | |
| 296 * has been marked as being silent, for example because it's low priority. | |
|
Peter Beverloo
2015/05/01 17:17:59
"for example because it's low priority." -> we don
Sanghyun Park
2015/05/04 07:00:43
Done.
| |
| 297 * If a vibration pattern is set, the notification should use the provided p attern | |
| 298 * rather than the defaulting to system settings. | |
| 299 * | |
| 300 * @param vibratePatternLength Vibration pattern's size for the Notification . | |
| 301 * @param silent Whether the default sound, vibration and lights should be s uppressed. | |
| 302 * @return The generated notification's default value. | |
| 303 * Returns 0 if silent is true. | |
|
Peter Beverloo
2015/05/01 17:17:59
No need for lines 303-306 in the description, one
Sanghyun Park
2015/05/04 07:00:43
Okay, I'll remove these lines.
| |
| 304 * Returns Notification.DEFAULT_ALL if silent is false and vibration 's length is 0. | |
| 305 * Returns Notification.DEFAULT_ALL & ~Notification.DEFAULT_VIBRATE | |
| 306 * if silent is false and vibration's length is greater than 0. | |
| 307 */ | |
| 308 @VisibleForTesting | |
| 309 static int makeDefaults(int vibratePatternLength, boolean silent) { | |
| 310 assert silent && vibratePatternLength == 0; | |
| 311 | |
| 312 if (silent) return 0; | |
| 313 | |
| 314 int defaults = Notification.DEFAULT_ALL; | |
| 315 if (vibratePatternLength > 0) { | |
| 316 defaults &= ~Notification.DEFAULT_VIBRATE; | |
| 317 } | |
| 318 return defaults; | |
| 319 } | |
| 320 | |
| 321 /** | |
| 322 * Generates the vibration pattern used in Android notification. | |
| 323 * | |
| 324 * In Android platform, the first value indicates the number of | |
|
Peter Beverloo
2015/05/01 17:17:59
nit: the linebreaks are kind of odd in this commen
Sanghyun Park
2015/05/04 07:00:44
Done.
| |
| 325 * milliseconds to wait before turning the vibrator on unlike Blink. | |
| 326 * So, we need to insert any value at the beginning of vibrate value. | |
| 327 * | |
| 328 * @param vibratePattern Vibration pattern for the Notification. | |
|
Peter Beverloo
2015/05/01 17:17:59
--> Vibration pattern following the Web Vibration
Sanghyun Park
2015/05/04 07:00:43
Done.
| |
| 329 * @return The generated vibration pattern for Android. | |
|
Peter Beverloo
2015/05/01 17:17:59
--> Vibration pattern following the Android syntax
Sanghyun Park
2015/05/04 07:00:43
Done.
| |
| 330 */ | |
| 331 @VisibleForTesting | |
| 332 static long[] makeVibratePattern(int[] vibratePattern) { | |
| 333 long[] pattern = new long[vibratePattern.length + 1]; | |
| 334 for (int i = 0; i < vibratePattern.length; ++i) { | |
| 335 pattern[i + 1] = vibratePattern[i]; | |
| 336 } | |
| 337 return pattern; | |
| 338 } | |
| 339 | |
| 340 /** | |
| 293 * Displays a notification with the given details. | 341 * Displays a notification with the given details. |
| 294 * | 342 * |
| 295 * @param persistentNotificationId The persistent id of the notification. | 343 * @param persistentNotificationId The persistent id of the notification. |
| 296 * @param origin Full text of the origin, including the protocol, owning thi s notification. | 344 * @param origin Full text of the origin, including the protocol, owning thi s notification. |
| 297 * @param tag A string identifier for this notification. If the tag is not e mpty, the new | 345 * @param tag A string identifier for this notification. If the tag is not e mpty, the new |
| 298 * notification will replace the previous notification with the s ame tag and origin, | 346 * notification will replace the previous notification with the s ame tag and origin, |
| 299 * if present. If no matching previous notification is present, t he new one will just | 347 * if present. If no matching previous notification is present, t he new one will just |
| 300 * be added. | 348 * be added. |
| 301 * @param title Title to be displayed in the notification. | 349 * @param title Title to be displayed in the notification. |
| 302 * @param body Message to be displayed in the notification. Will be trimmed to one line of | 350 * @param body Message to be displayed in the notification. Will be trimmed to one line of |
| 303 * text by the Android notification system. | 351 * text by the Android notification system. |
| 304 * @param icon Icon to be displayed in the notification. When this isn't a v alid Bitmap, a | 352 * @param icon Icon to be displayed in the notification. When this isn't a v alid Bitmap, a |
| 305 * default icon will be generated instead. | 353 * default icon will be generated instead. |
| 354 * @param vibratePattern Vibration pattern for the Notification. | |
|
Peter Beverloo
2015/05/01 17:17:59
--> Vibration pattern following the Web Vibration
Sanghyun Park
2015/05/04 07:00:43
Done.
| |
| 306 * @param silent Whether the default sound, vibration and lights should be s uppressed. | 355 * @param silent Whether the default sound, vibration and lights should be s uppressed. |
| 356 * @see https://developer.android.com/reference/android/app/Notification.htm l | |
| 307 */ | 357 */ |
| 308 @CalledByNative | 358 @CalledByNative |
| 309 private void displayNotification(long persistentNotificationId, String origi n, String tag, | 359 private void displayNotification(long persistentNotificationId, String origi n, String tag, |
| 310 String title, String body, Bitmap icon, boolean silent) { | 360 String title, String body, Bitmap icon, int[] vibratePattern, boolea n silent) { |
|
Peter Beverloo
2015/05/01 17:17:59
nit: rename this to vibrationPattern?
Sanghyun Park
2015/05/04 07:00:43
Done.
| |
| 311 if (icon == null || icon.getWidth() == 0) { | 361 if (icon == null || icon.getWidth() == 0) { |
| 312 icon = getIconGenerator().generateIconForUrl(origin, true); | 362 icon = getIconGenerator().generateIconForUrl(origin, true); |
| 313 } | 363 } |
| 314 | 364 |
| 315 Resources res = mAppContext.getResources(); | 365 Resources res = mAppContext.getResources(); |
| 316 | 366 |
| 317 // The data used to make each intent unique according to the rules of In tent#filterEquals. | 367 // The data used to make each intent unique according to the rules of In tent#filterEquals. |
| 318 // Without this, the pending intents derived from them may be reused, be cause extras are | 368 // Without this, the pending intents derived from them may be reused, be cause extras are |
| 319 // not taken into account for the filterEquals comparison. | 369 // not taken into account for the filterEquals comparison. |
| 320 Uri intentData = Uri.parse(origin).buildUpon().fragment( | 370 Uri intentData = Uri.parse(origin).buildUpon().fragment( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 340 NotificationConstants.ACTION_CLICK_NOTIFICATION, | 390 NotificationConstants.ACTION_CLICK_NOTIFICATION, |
| 341 persistentNotificationId, origin, tag, intentData)) | 391 persistentNotificationId, origin, tag, intentData)) |
| 342 .setDeleteIntent(getPendingIntent( | 392 .setDeleteIntent(getPendingIntent( |
| 343 NotificationConstants.ACTION_CLOSE_NOTIFICATION, | 393 NotificationConstants.ACTION_CLOSE_NOTIFICATION, |
| 344 persistentNotificationId, origin, tag, intentData)) | 394 persistentNotificationId, origin, tag, intentData)) |
| 345 .addAction(R.drawable.settings_cog, | 395 .addAction(R.drawable.settings_cog, |
| 346 res.getString(R.string.page_info_site_settings_button ), | 396 res.getString(R.string.page_info_site_settings_button ), |
| 347 pendingSettingsIntent) | 397 pendingSettingsIntent) |
| 348 .setSubText(origin); | 398 .setSubText(origin); |
| 349 | 399 |
| 350 // Use the system's default ringtone, vibration and indicator lights unl ess the notification | 400 notificationBuilder.setDefaults(makeDefaults(vibratePattern.length, sile nt)); |
| 351 // has been marked as being silent, for example because it's low priorit y. | 401 if (vibratePattern.length > 0) { |
| 352 if (!silent) notificationBuilder.setDefaults(Notification.DEFAULT_ALL); | 402 notificationBuilder.setVibrate(makeVibratePattern(vibratePattern)); |
| 403 } | |
| 353 | 404 |
| 354 String platformTag = makePlatformTag(persistentNotificationId, origin, t ag); | 405 String platformTag = makePlatformTag(persistentNotificationId, origin, t ag); |
| 355 mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilde r.build()); | 406 mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilde r.build()); |
| 356 } | 407 } |
| 357 | 408 |
| 358 /** | 409 /** |
| 359 * Ensures the existance of an icon generator, which is created lazily. | 410 * Ensures the existance of an icon generator, which is created lazily. |
| 360 * | 411 * |
| 361 * @return The icon generator which can be used. | 412 * @return The icon generator which can be used. |
| 362 */ | 413 */ |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 origin, tag); | 487 origin, tag); |
| 437 } | 488 } |
| 438 | 489 |
| 439 private static native void nativeInitializeNotificationUIManager(); | 490 private static native void nativeInitializeNotificationUIManager(); |
| 440 | 491 |
| 441 private native boolean nativeOnNotificationClicked(long nativeNotificationUI ManagerAndroid, | 492 private native boolean nativeOnNotificationClicked(long nativeNotificationUI ManagerAndroid, |
| 442 long persistentNotificationId, String origin, String tag); | 493 long persistentNotificationId, String origin, String tag); |
| 443 private native boolean nativeOnNotificationClosed(long nativeNotificationUIM anagerAndroid, | 494 private native boolean nativeOnNotificationClosed(long nativeNotificationUIM anagerAndroid, |
| 444 long persistentNotificationId, String origin, String tag); | 495 long persistentNotificationId, String origin, String tag); |
| 445 } | 496 } |
| OLD | NEW |