From edbb380950d60a5e7bcda04599fdf9cf43d18dbd Mon Sep 17 00:00:00 2001 From: Daniel Sandler Date: Tue, 13 Nov 2012 20:49:47 -0800 Subject: [PATCH] Notification vibration improvements: - When notifications vibrate as a fallback (that is, because they want to play a sound but the device is in vibrate mode), this no longer requires the VIBRATE permission. - As a bonus, if your notifications use DEFAULT_VIBRATE, you don't need the VIBRATE permission either. - If you specify a custom vibration pattern, you'll still need the VIBRATE permission for that. - Notifications vibrating in fallback mode use a different vibration pattern. - The DEFAULT_VIBRATE and fallback vibrate patterns are now specified in config.xml. Bug: 7531442 Change-Id: I7a2d8413d1becc53b9d31f0d1abbc2acc3f650c6 --- core/res/res/values/config.xml | 21 +++++++ core/res/res/values/symbols.xml | 2 + .../server/NotificationManagerService.java | 59 ++++++++++++++++--- 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 3b7d73a44cbc1..ea28a51fe5476 100755 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1000,4 +1000,25 @@ provisioning on some carriers, working around a bug (7305641) where if the preferred is used we don't try the others. --> false + + + + 0 + 150 + 200 + 250 + + + + + 0 + 33 + 150 + 50 + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 68a0289756816..68587321b2078 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1525,6 +1525,8 @@ + + diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java index f3a38f0c7cdba..70d37bfc82851 100755 --- a/services/java/com/android/server/NotificationManagerService.java +++ b/services/java/com/android/server/NotificationManagerService.java @@ -101,6 +101,7 @@ public class NotificationManagerService extends INotificationManager.Stub private static final int SHORT_DELAY = 2000; // 2 seconds private static final long[] DEFAULT_VIBRATE_PATTERN = {0, 250, 250, 250}; + private static final int VIBRATE_PATTERN_MAXLEN = 8 * 2 + 1; // up to eight bumps private static final int DEFAULT_STREAM_TYPE = AudioManager.STREAM_NOTIFICATION; private static final boolean SCORE_ONGOING_HIGHER = false; @@ -125,6 +126,9 @@ public class NotificationManagerService extends INotificationManager.Stub private int mDefaultNotificationLedOn; private int mDefaultNotificationLedOff; + private long[] mDefaultVibrationPattern; + private long[] mFallbackVibrationPattern; + private boolean mSystemReady; private int mDisabledNotifications; @@ -596,6 +600,19 @@ public class NotificationManagerService extends INotificationManager.Stub } } + static long[] getLongArray(Resources r, int resid, int maxlen, long[] def) { + int[] ar = r.getIntArray(resid); + if (ar == null) { + return def; + } + final int len = ar.length > maxlen ? maxlen : ar.length; + long[] out = new long[len]; + for (int i=0; i 1) { + // If you want your own vibration pattern, you need the VIBRATE permission + mVibrator.vibrate(notification.vibrate, + ((notification.flags & Notification.FLAG_INSISTENT) != 0) ? 0: -1); + } } }