From dbf4481cc3eea106992df2ac145269ab737b2f24 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 14 Apr 2016 08:54:45 -0400 Subject: [PATCH 1/2] Adjustment bundles are defusable. Bug: 28168811 Change-Id: I1699e6bfd03a5f117cc89585c03e235fe6a99456 --- .../NotificationManagerService.java | 101 +++++++++--------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 2d3ca1f83b795..cabdced361f90 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2186,16 +2186,18 @@ public class NotificationManagerService extends SystemService { // Clears the 'fake' auto-bunding summary. private void maybeClearAutobundleSummaryLocked(Adjustment adjustment) { - if (adjustment.getSignals() != null - && adjustment.getSignals().containsKey(Adjustment.NEEDS_AUTOGROUPING_KEY) + if (adjustment.getSignals() != null) { + Bundle.setDefusable(adjustment.getSignals(), true); + if (adjustment.getSignals().containsKey(Adjustment.NEEDS_AUTOGROUPING_KEY) && !adjustment.getSignals().getBoolean(Adjustment.NEEDS_AUTOGROUPING_KEY, false)) { - if (mAutobundledSummaries.containsKey(adjustment.getPackage())) { - // Clear summary. - final NotificationRecord removed = mNotificationsByKey.get( - mAutobundledSummaries.remove(adjustment.getPackage())); - if (removed != null) { - mNotificationList.remove(removed); - cancelNotificationLocked(removed, false, REASON_UNAUTOBUNDLED); + if (mAutobundledSummaries.containsKey(adjustment.getPackage())) { + // Clear summary. + final NotificationRecord removed = mNotificationsByKey.get( + mAutobundledSummaries.remove(adjustment.getPackage())); + if (removed != null) { + mNotificationList.remove(removed); + cancelNotificationLocked(removed, false, REASON_UNAUTOBUNDLED); + } } } } @@ -2203,47 +2205,50 @@ public class NotificationManagerService extends SystemService { // Posts a 'fake' summary for a package that has exceeded the solo-notification limit. private void maybeAddAutobundleSummary(Adjustment adjustment) { - if (adjustment.getSignals() != null - && adjustment.getSignals().getBoolean(Adjustment.NEEDS_AUTOGROUPING_KEY, false)) { - final String newAutoBundleKey = - adjustment.getSignals().getString(Adjustment.GROUP_KEY_OVERRIDE_KEY, null); - int userId = -1; - NotificationRecord summaryRecord = null; - synchronized (mNotificationList) { - if (!mAutobundledSummaries.containsKey(adjustment.getPackage()) - && newAutoBundleKey != null) { - // Add summary - final StatusBarNotification adjustedSbn - = mNotificationsByKey.get(adjustment.getKey()).sbn; + if (adjustment.getSignals() != null) { + Bundle.setDefusable(adjustment.getSignals(), true); + if (adjustment.getSignals().getBoolean(Adjustment.NEEDS_AUTOGROUPING_KEY, false)) { + final String newAutoBundleKey = + adjustment.getSignals().getString(Adjustment.GROUP_KEY_OVERRIDE_KEY, null); + int userId = -1; + NotificationRecord summaryRecord = null; + synchronized (mNotificationList) { + if (!mAutobundledSummaries.containsKey(adjustment.getPackage()) + && newAutoBundleKey != null) { + // Add summary + final StatusBarNotification adjustedSbn + = mNotificationsByKey.get(adjustment.getKey()).sbn; - final ApplicationInfo appInfo = - adjustedSbn.getNotification().extras.getParcelable( - Notification.EXTRA_BUILDER_APPLICATION_INFO); - final Bundle extras = new Bundle(); - extras.putParcelable(Notification.EXTRA_BUILDER_APPLICATION_INFO, appInfo); - final Notification summaryNotification = - new Notification.Builder(getContext()).setSmallIcon( - adjustedSbn.getNotification().getSmallIcon()) - .setGroupSummary(true) - .setGroup(newAutoBundleKey) - .setFlag(Notification.FLAG_AUTOGROUP_SUMMARY, true) - .setFlag(Notification.FLAG_GROUP_SUMMARY, true) - .build(); - summaryNotification.extras.putAll(extras); - final StatusBarNotification summarySbn = - new StatusBarNotification(adjustedSbn.getPackageName(), - adjustedSbn.getOpPkg(), - Integer.MAX_VALUE, Adjustment.GROUP_KEY_OVERRIDE_KEY, - adjustedSbn.getUid(), adjustedSbn.getInitialPid(), - summaryNotification, adjustedSbn.getUser(), newAutoBundleKey, - System.currentTimeMillis()); - summaryRecord = new NotificationRecord(getContext(), summarySbn); - mAutobundledSummaries.put(adjustment.getPackage(), summarySbn.getKey()); - userId = adjustedSbn.getUser().getIdentifier(); + final ApplicationInfo appInfo = + adjustedSbn.getNotification().extras.getParcelable( + Notification.EXTRA_BUILDER_APPLICATION_INFO); + final Bundle extras = new Bundle(); + extras.putParcelable(Notification.EXTRA_BUILDER_APPLICATION_INFO, appInfo); + final Notification summaryNotification = + new Notification.Builder(getContext()).setSmallIcon( + adjustedSbn.getNotification().getSmallIcon()) + .setGroupSummary(true) + .setGroup(newAutoBundleKey) + .setFlag(Notification.FLAG_AUTOGROUP_SUMMARY, true) + .setFlag(Notification.FLAG_GROUP_SUMMARY, true) + .build(); + summaryNotification.extras.putAll(extras); + final StatusBarNotification summarySbn = + new StatusBarNotification(adjustedSbn.getPackageName(), + adjustedSbn.getOpPkg(), + Integer.MAX_VALUE, Adjustment.GROUP_KEY_OVERRIDE_KEY, + adjustedSbn.getUid(), adjustedSbn.getInitialPid(), + summaryNotification, adjustedSbn.getUser(), + newAutoBundleKey, + System.currentTimeMillis()); + summaryRecord = new NotificationRecord(getContext(), summarySbn); + mAutobundledSummaries.put(adjustment.getPackage(), summarySbn.getKey()); + userId = adjustedSbn.getUser().getIdentifier(); + } + } + if (summaryRecord != null) { + mHandler.post(new EnqueueNotificationRunnable(userId, summaryRecord)); } - } - if (summaryRecord != null) { - mHandler.post(new EnqueueNotificationRunnable(userId, summaryRecord)); } } } From d28967f489996d1d74ff5c0bbb9c19d158efbf37 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 14 Apr 2016 09:37:08 -0400 Subject: [PATCH 2/2] Phone call vibrate should obey user preference. Bug: 27353237 Change-Id: I6b52e378c9e664600720025af30596be09aeb19d --- .../com/android/server/VibratorService.java | 6 +++++ .../statusbartest/NotificationTestList.java | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/services/core/java/com/android/server/VibratorService.java b/services/core/java/com/android/server/VibratorService.java index 2924cef09d17d..5ba07cf2c8a6d 100644 --- a/services/core/java/com/android/server/VibratorService.java +++ b/services/core/java/com/android/server/VibratorService.java @@ -454,6 +454,12 @@ public class VibratorService extends IVibratorService.Stub return; } + if (vib.mUsageHint == AudioAttributes.USAGE_NOTIFICATION_RINGTONE + && Settings.System.getInt( + mContext.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 0) == 0) { + return; + } + int mode = mAppOpsService.checkAudioOperation(AppOpsManager.OP_VIBRATE, vib.mUsageHint, vib.mUid, vib.mOpPkg); if (mode == AppOpsManager.MODE_ALLOWED) { diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java index 6c8be3978ccf9..a4aab7c268b0d 100644 --- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java @@ -25,6 +25,7 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; +import android.media.AudioAttributes; import android.os.Bundle; import android.os.Vibrator; import android.os.Handler; @@ -86,6 +87,28 @@ public class NotificationTestList extends TestActivity } private Test[] mTests = new Test[] { + new Test("Phone call") { + public void run() + { + Notification n = new Notification.Builder(NotificationTestList.this) + .setSmallIcon(R.drawable.icon2) + .setContentTitle("phone call") + .setLights(0xff0000ff, 1, 0) + .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) + .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + + getPackageName() + "/raw/ringer"), + new AudioAttributes.Builder().setUsage( + AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build()) + .setPriority(Notification.PRIORITY_MAX) + .setVibrate(new long[] { + 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, + 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, + 300, 400, 300, 400, 300, 400, 300, 400, 300, 400, 300, 400 }) + .setFullScreenIntent(makeIntent2(), true) + .build(); + mNM.notify(7001, n); + } + }, new Test("Post a group") { public void run() {