diff options
| author | 2018-12-14 21:58:34 +0000 | |
|---|---|---|
| committer | 2018-12-14 21:58:34 +0000 | |
| commit | b4ee870ecafe67fe8bab6abb1ec201cbd63f8b14 (patch) | |
| tree | 34b545f5fd4245c482399584ad6f873107ddbf6a | |
| parent | 5f861a8185760b8c0b5f94d4f9ae40bf2349f231 (diff) | |
| parent | 7306b9055421a6cae934a858f0827f797eade261 (diff) | |
Merge "Hides audibly alerted icon after 30 seconds."
16 files changed, 183 insertions, 145 deletions
diff --git a/api/current.txt b/api/current.txt index 63bbad29cc0a..9d865b60e667 100644 --- a/api/current.txt +++ b/api/current.txt @@ -41084,12 +41084,12 @@ package android.service.notification { public static class NotificationListenerService.Ranking { ctor public NotificationListenerService.Ranking(); - method public boolean audiblyAlerted(); method public boolean canShowBadge(); method public android.app.NotificationChannel getChannel(); method public int getImportance(); method public java.lang.CharSequence getImportanceExplanation(); method public java.lang.String getKey(); + method public long getLastAudiblyAlertedMillis(); method public java.lang.String getOverrideGroupKey(); method public int getRank(); method public int getSuppressedVisualEffects(); diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java index 1fe97b79fd69..6d2f85679cff 100644 --- a/core/java/android/service/notification/NotificationListenerService.java +++ b/core/java/android/service/notification/NotificationListenerService.java @@ -1482,7 +1482,7 @@ public abstract class NotificationListenerService extends Service { private boolean mShowBadge; private @UserSentiment int mUserSentiment = USER_SENTIMENT_NEUTRAL; private boolean mHidden; - private boolean mAudiblyAlerted; + private long mLastAudiblyAlertedMs; private boolean mNoisy; private ArrayList<Notification.Action> mSmartActions; private ArrayList<CharSequence> mSmartReplies; @@ -1650,12 +1650,12 @@ public abstract class NotificationListenerService extends Service { } /** - * Returns whether this notification alerted the user via sound or vibration. + * Returns the last time this notification alerted the user via sound or vibration. * - * @return true if the notification alerted the user, false otherwise. + * @return the time of the last alerting behavior, in milliseconds. */ - public boolean audiblyAlerted() { - return mAudiblyAlerted; + public long getLastAudiblyAlertedMillis() { + return mLastAudiblyAlertedMs; } /** @hide */ @@ -1672,7 +1672,7 @@ public abstract class NotificationListenerService extends Service { CharSequence explanation, String overrideGroupKey, NotificationChannel channel, ArrayList<String> overridePeople, ArrayList<SnoozeCriterion> snoozeCriteria, boolean showBadge, - int userSentiment, boolean hidden, boolean audiblyAlerted, + int userSentiment, boolean hidden, long lastAudiblyAlertedMs, boolean noisy, ArrayList<Notification.Action> smartActions, ArrayList<CharSequence> smartReplies) { mKey = key; @@ -1690,7 +1690,7 @@ public abstract class NotificationListenerService extends Service { mShowBadge = showBadge; mUserSentiment = userSentiment; mHidden = hidden; - mAudiblyAlerted = audiblyAlerted; + mLastAudiblyAlertedMs = lastAudiblyAlertedMs; mNoisy = noisy; mSmartActions = smartActions; mSmartReplies = smartReplies; @@ -1743,7 +1743,7 @@ public abstract class NotificationListenerService extends Service { private ArrayMap<String, Boolean> mShowBadge; private ArrayMap<String, Integer> mUserSentiment; private ArrayMap<String, Boolean> mHidden; - private ArrayMap<String, Boolean> mAudiblyAlerted; + private ArrayMap<String, Long> mLastAudiblyAlerted; private ArrayMap<String, Boolean> mNoisy; private ArrayMap<String, ArrayList<Notification.Action>> mSmartActions; private ArrayMap<String, ArrayList<CharSequence>> mSmartReplies; @@ -1776,7 +1776,7 @@ public abstract class NotificationListenerService extends Service { getImportance(key), getImportanceExplanation(key), getOverrideGroupKey(key), getChannel(key), getOverridePeople(key), getSnoozeCriteria(key), getShowBadge(key), getUserSentiment(key), getHidden(key), - getAudiblyAlerted(key), getNoisy(key), getSmartActions(key), + getLastAudiblyAlerted(key), getNoisy(key), getSmartActions(key), getSmartReplies(key)); return rank >= 0; } @@ -1915,14 +1915,14 @@ public abstract class NotificationListenerService extends Service { return hidden == null ? false : hidden.booleanValue(); } - private boolean getAudiblyAlerted(String key) { + private long getLastAudiblyAlerted(String key) { synchronized (this) { - if (mAudiblyAlerted == null) { - buildAudiblyAlertedLocked(); + if (mLastAudiblyAlerted == null) { + buildLastAudiblyAlertedLocked(); } } - Boolean audiblyAlerted = mAudiblyAlerted.get(key); - return audiblyAlerted == null ? false : audiblyAlerted.booleanValue(); + Long lastAudibleAlerted = mLastAudiblyAlerted.get(key); + return lastAudibleAlerted == null ? -1 : lastAudibleAlerted.longValue(); } private boolean getNoisy(String key) { @@ -1994,6 +1994,14 @@ public abstract class NotificationListenerService extends Service { return newMap; } + private ArrayMap<String, Long> buildLongMapFromBundle(Bundle bundle) { + ArrayMap<String, Long> newMap = new ArrayMap<>(bundle.size()); + for (String key : bundle.keySet()) { + newMap.put(key, bundle.getLong(key)); + } + return newMap; + } + // Locked by 'this' private void buildVisibilityOverridesLocked() { mVisibilityOverrides = buildIntMapFromBundle(mRankingUpdate.getVisibilityOverrides()); @@ -2070,8 +2078,8 @@ public abstract class NotificationListenerService extends Service { } // Locked by 'this' - private void buildAudiblyAlertedLocked() { - mAudiblyAlerted = buildBooleanMapFromBundle(mRankingUpdate.getAudiblyAlerted()); + private void buildLastAudiblyAlertedLocked() { + mLastAudiblyAlerted = buildLongMapFromBundle(mRankingUpdate.getLastAudiblyAlerted()); } // Locked by 'this' diff --git a/core/java/android/service/notification/NotificationRankingUpdate.java b/core/java/android/service/notification/NotificationRankingUpdate.java index f80df93364f4..ebaeff8ff33c 100644 --- a/core/java/android/service/notification/NotificationRankingUpdate.java +++ b/core/java/android/service/notification/NotificationRankingUpdate.java @@ -39,7 +39,7 @@ public class NotificationRankingUpdate implements Parcelable { private final Bundle mHidden; private final Bundle mSmartActions; private final Bundle mSmartReplies; - private final Bundle mAudiblyAlerted; + private final Bundle mLastAudiblyAlerted; private final Bundle mNoisy; public NotificationRankingUpdate(String[] keys, String[] interceptedKeys, @@ -47,7 +47,7 @@ public class NotificationRankingUpdate implements Parcelable { int[] importance, Bundle explanation, Bundle overrideGroupKeys, Bundle channels, Bundle overridePeople, Bundle snoozeCriteria, Bundle showBadge, Bundle userSentiment, Bundle hidden, Bundle smartActions, - Bundle smartReplies, Bundle audiblyAlerted, Bundle noisy) { + Bundle smartReplies, Bundle lastAudiblyAlerted, Bundle noisy) { mKeys = keys; mInterceptedKeys = interceptedKeys; mVisibilityOverrides = visibilityOverrides; @@ -63,7 +63,7 @@ public class NotificationRankingUpdate implements Parcelable { mHidden = hidden; mSmartActions = smartActions; mSmartReplies = smartReplies; - mAudiblyAlerted = audiblyAlerted; + mLastAudiblyAlerted = lastAudiblyAlerted; mNoisy = noisy; } @@ -84,7 +84,7 @@ public class NotificationRankingUpdate implements Parcelable { mHidden = in.readBundle(); mSmartActions = in.readBundle(); mSmartReplies = in.readBundle(); - mAudiblyAlerted = in.readBundle(); + mLastAudiblyAlerted = in.readBundle(); mNoisy = in.readBundle(); } @@ -110,7 +110,7 @@ public class NotificationRankingUpdate implements Parcelable { out.writeBundle(mHidden); out.writeBundle(mSmartActions); out.writeBundle(mSmartReplies); - out.writeBundle(mAudiblyAlerted); + out.writeBundle(mLastAudiblyAlerted); out.writeBundle(mNoisy); } @@ -185,8 +185,8 @@ public class NotificationRankingUpdate implements Parcelable { return mSmartReplies; } - public Bundle getAudiblyAlerted() { - return mAudiblyAlerted; + public Bundle getLastAudiblyAlerted() { + return mLastAudiblyAlerted; } public Bundle getNoisy() { diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index 4a5ccdff0dd3..ada78532d63f 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -340,7 +340,7 @@ public class NotificationHeaderView extends ViewGroup { } /** Updates icon visibility based on the noisiness of the notification. */ - public void setAudiblyAlerted(boolean audiblyAlerted) { + public void setRecentlyAudiblyAlerted(boolean audiblyAlerted) { mAudiblyAlertedIcon.setVisibility(audiblyAlerted ? View.VISIBLE : View.GONE); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java index dc3a60786ce2..0702f1b9f1fe 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java @@ -437,7 +437,7 @@ public class NotificationViewHierarchyManager { } row.showAppOpsIcons(entry.mActiveAppOps); - row.setAudiblyAlerted(entry.audiblyAlerted); + row.setLastAudiblyAlertedMs(entry.lastAudiblyAlertedMs); } Trace.beginSection("NotificationPresenter#onUpdateRowStates"); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationData.java index f543b4622611..ae9f323c2ebf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationData.java @@ -103,7 +103,7 @@ public class NotificationData { public String key; public StatusBarNotification notification; public NotificationChannel channel; - public boolean audiblyAlerted; + public long lastAudiblyAlertedMs; public boolean noisy; public int importance; public StatusBarIconView icon; @@ -172,7 +172,7 @@ public class NotificationData { public void populateFromRanking(@NonNull Ranking ranking) { channel = ranking.getChannel(); - audiblyAlerted = ranking.audiblyAlerted(); + lastAudiblyAlertedMs = ranking.getLastAudiblyAlertedMillis(); importance = ranking.getImportance(); snoozeCriteria = ranking.getSnoozeCriteria(); userSentiment = ranking.getUserSentiment(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java index 16a3849a6eec..5e244f81d021 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java @@ -32,6 +32,7 @@ import android.content.pm.PackageManager; import android.database.ContentObserver; import android.os.Build; import android.os.Bundle; +import android.os.Handler; import android.os.PowerManager; import android.os.RemoteException; import android.os.ServiceManager; @@ -96,6 +97,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.concurrent.TimeUnit; /** * NotificationEntryManager is responsible for the adding, removing, and updating of notifications. @@ -110,6 +112,8 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. private static final boolean ENABLE_HEADS_UP = true; private static final String SETTING_HEADS_UP_TICKER = "ticker_gets_heads_up"; + public static final long RECENTLY_ALERTED_THRESHOLD_MS = TimeUnit.SECONDS.toMillis(30); + private final NotificationMessagingUtil mMessagingUtil; protected final Context mContext; protected final HashMap<String, NotificationData.Entry> mPendingNotifications = new HashMap<>(); @@ -139,6 +143,9 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. private NotificationListener mNotificationListener; private ShadeController mShadeController; + private final Handler mDeferredNotificationViewUpdateHandler; + private Runnable mUpdateNotificationViewsCallback; + protected IDreamManager mDreamManager; protected IStatusBarService mBarService; private NotificationPresenter mPresenter; @@ -259,6 +266,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. mBubbleController.setDismissListener(this /* bubbleEventListener */); mNotificationData = new NotificationData(); Dependency.get(InitController.class).addPostInitTask(this::onPostInit); + mDeferredNotificationViewUpdateHandler = new Handler(); } private void onPostInit() { @@ -301,6 +309,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. NotificationListContainer listContainer, Callback callback, HeadsUpManager headsUpManager) { mPresenter = presenter; + mUpdateNotificationViewsCallback = mPresenter::updateNotificationViews; mCallback = callback; mHeadsUpManager = headsUpManager; mNotificationData.setHeadsUpManager(mHeadsUpManager); @@ -540,6 +549,17 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. tagForeground(shadeEntry.notification); updateNotifications(); mCallback.onNotificationAdded(shadeEntry); + + maybeScheduleUpdateNotificationViews(shadeEntry); + } + + private void maybeScheduleUpdateNotificationViews(NotificationData.Entry entry) { + long audibleAlertTimeout = RECENTLY_ALERTED_THRESHOLD_MS + - (System.currentTimeMillis() - entry.lastAudiblyAlertedMs); + if (audibleAlertTimeout > 0) { + mDeferredNotificationViewUpdateHandler.postDelayed( + mUpdateNotificationViewsCallback, audibleAlertTimeout); + } } /** @@ -937,6 +957,8 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater. } mCallback.onNotificationUpdated(notification); + + maybeScheduleUpdateNotificationViews(entry); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java index 383446c00d37..91d08fffa642 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java @@ -87,6 +87,7 @@ import com.android.systemui.statusbar.StatusBarIconView; import com.android.systemui.statusbar.notification.AboveShelfChangedListener; import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; import com.android.systemui.statusbar.notification.NotificationData; +import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.NotificationUtils; import com.android.systemui.statusbar.notification.VisualStabilityManager; import com.android.systemui.statusbar.notification.logging.NotificationCounters; @@ -1689,14 +1690,17 @@ public class ExpandableNotificationRow extends ActivatableNotificationView mPublicLayout.showAppOpsIcons(activeOps); } - /** Sets whether the notification being displayed audibly alerted the user. */ - public void setAudiblyAlerted(boolean audiblyAlerted) { + /** Sets the last time the notification being displayed audibly alerted the user. */ + public void setLastAudiblyAlertedMs(long lastAudiblyAlertedMs) { if (NotificationUtils.useNewInterruptionModel(mContext)) { + boolean recentlyAudiblyAlerted = System.currentTimeMillis() - lastAudiblyAlertedMs + < NotificationEntryManager.RECENTLY_ALERTED_THRESHOLD_MS; if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() != null) { - mChildrenContainer.getHeaderView().setAudiblyAlerted(audiblyAlerted); + mChildrenContainer.getHeaderView().setRecentlyAudiblyAlerted( + recentlyAudiblyAlerted); } - mPrivateLayout.setAudiblyAlerted(audiblyAlerted); - mPublicLayout.setAudiblyAlerted(audiblyAlerted); + mPrivateLayout.setRecentlyAudiblyAlerted(recentlyAudiblyAlerted); + mPublicLayout.setRecentlyAudiblyAlerted(recentlyAudiblyAlerted); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java index edd54ca936fa..6bc39c82f8bf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java @@ -1615,15 +1615,15 @@ public class NotificationContentView extends FrameLayout { } /** Sets whether the notification being displayed audibly alerted the user. */ - public void setAudiblyAlerted(boolean audiblyAlerted) { + public void setRecentlyAudiblyAlerted(boolean audiblyAlerted) { if (mContractedChild != null && mContractedWrapper.getNotificationHeader() != null) { - mContractedWrapper.getNotificationHeader().setAudiblyAlerted(audiblyAlerted); + mContractedWrapper.getNotificationHeader().setRecentlyAudiblyAlerted(audiblyAlerted); } if (mExpandedChild != null && mExpandedWrapper.getNotificationHeader() != null) { - mExpandedWrapper.getNotificationHeader().setAudiblyAlerted(audiblyAlerted); + mExpandedWrapper.getNotificationHeader().setRecentlyAudiblyAlerted(audiblyAlerted); } if (mHeadsUpChild != null && mHeadsUpWrapper.getNotificationHeader() != null) { - mHeadsUpWrapper.getNotificationHeader().setAudiblyAlerted(audiblyAlerted); + mHeadsUpWrapper.getNotificationHeader().setRecentlyAudiblyAlerted(audiblyAlerted); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java index 8e88ed0556bf..def7513bc7dd 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationDataTest.java @@ -475,14 +475,14 @@ public class NotificationDataTest extends SysuiTestCase { outRanking.getImportance(), outRanking.getImportanceExplanation(), outRanking.getOverrideGroupKey(), outRanking.getChannel(), null, null, outRanking.canShowBadge(), outRanking.getUserSentiment(), true, - false, false, null, null); + -1, false, null, null); } else if (key.equals(TEST_EXEMPT_DND_VISUAL_SUPPRESSION_KEY)) { outRanking.populate(key, outRanking.getRank(), outRanking.matchesInterruptionFilter(), outRanking.getVisibilityOverride(), 255, outRanking.getImportance(), outRanking.getImportanceExplanation(), outRanking.getOverrideGroupKey(), outRanking.getChannel(), null, null, - outRanking.canShowBadge(), outRanking.getUserSentiment(), true, false, + outRanking.canShowBadge(), outRanking.getUserSentiment(), true, -1, false, null, null); } else { outRanking.populate(key, outRanking.getRank(), @@ -490,7 +490,7 @@ public class NotificationDataTest extends SysuiTestCase { outRanking.getVisibilityOverride(), outRanking.getSuppressedVisualEffects(), outRanking.getImportance(), outRanking.getImportanceExplanation(), outRanking.getOverrideGroupKey(), NOTIFICATION_CHANNEL, null, null, - outRanking.canShowBadge(), outRanking.getUserSentiment(), false, false, + outRanking.canShowBadge(), outRanking.getUserSentiment(), false, -1, false, null, null); } return true; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java index 8706e214db8e..904e5b99b0ab 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java @@ -167,7 +167,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase { 0, NotificationManager.IMPORTANCE_DEFAULT, null, null, - null, null, null, true, sentiment, false, false, false, null, null); + null, null, null, true, sentiment, false, -1, false, null, null); return true; }).when(mRankingMap).getRanking(eq(key), any(NotificationListenerService.Ranking.class)); } @@ -185,7 +185,7 @@ public class NotificationEntryManagerTest extends SysuiTestCase { NotificationManager.IMPORTANCE_DEFAULT, null, null, null, null, null, true, - NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL, false, false, + NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL, false, -1, false, smartActions, null); return true; }).when(mRankingMap).getRanking(eq(key), any(NotificationListenerService.Ranking.class)); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 36a027a8fcd0..3d8763439086 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -47,17 +47,12 @@ import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_CRITICAL; import static android.os.IServiceManager.DUMP_FLAG_PRIORITY_NORMAL; import static android.os.UserHandle.USER_NULL; import static android.os.UserHandle.USER_SYSTEM; -import static android.service.notification.NotificationListenerService - .HINT_HOST_DISABLE_CALL_EFFECTS; +import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS; import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_EFFECTS; -import static android.service.notification.NotificationListenerService - .HINT_HOST_DISABLE_NOTIFICATION_EFFECTS; -import static android.service.notification.NotificationListenerService - .NOTIFICATION_CHANNEL_OR_GROUP_ADDED; -import static android.service.notification.NotificationListenerService - .NOTIFICATION_CHANNEL_OR_GROUP_DELETED; -import static android.service.notification.NotificationListenerService - .NOTIFICATION_CHANNEL_OR_GROUP_UPDATED; +import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS; +import static android.service.notification.NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_ADDED; +import static android.service.notification.NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_DELETED; +import static android.service.notification.NotificationListenerService.NOTIFICATION_CHANNEL_OR_GROUP_UPDATED; import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL; import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL; import static android.service.notification.NotificationListenerService.REASON_CANCEL; @@ -65,8 +60,7 @@ import static android.service.notification.NotificationListenerService.REASON_CA import static android.service.notification.NotificationListenerService.REASON_CHANNEL_BANNED; import static android.service.notification.NotificationListenerService.REASON_CLICK; import static android.service.notification.NotificationListenerService.REASON_ERROR; -import static android.service.notification.NotificationListenerService - .REASON_GROUP_SUMMARY_CANCELED; +import static android.service.notification.NotificationListenerService.REASON_GROUP_SUMMARY_CANCELED; import static android.service.notification.NotificationListenerService.REASON_LISTENER_CANCEL; import static android.service.notification.NotificationListenerService.REASON_LISTENER_CANCEL_ALL; import static android.service.notification.NotificationListenerService.REASON_PACKAGE_BANNED; @@ -6695,7 +6689,7 @@ public class NotificationManagerService extends SystemService { Bundle hidden = new Bundle(); Bundle systemGeneratedSmartActions = new Bundle(); Bundle smartReplies = new Bundle(); - Bundle audiblyAlerted = new Bundle(); + Bundle lastAudiblyAlerted = new Bundle(); Bundle noisy = new Bundle(); for (int i = 0; i < N; i++) { NotificationRecord record = mNotificationList.get(i); @@ -6727,7 +6721,7 @@ public class NotificationManagerService extends SystemService { systemGeneratedSmartActions.putParcelableArrayList(key, record.getSystemGeneratedSmartActions()); smartReplies.putCharSequenceArrayList(key, record.getSmartReplies()); - audiblyAlerted.putBoolean(key, record.getAudiblyAlerted()); + lastAudiblyAlerted.putLong(key, record.getLastAudiblyAlertedMs()); noisy.putBoolean(key, record.getSound() != null || record.getVibration() != null); } final int M = keys.size(); @@ -6740,7 +6734,7 @@ public class NotificationManagerService extends SystemService { return new NotificationRankingUpdate(keysAr, interceptedKeysAr, visibilityOverrides, suppressedVisualEffects, importanceAr, explanation, overrideGroupKeys, channels, overridePeople, snoozeCriteria, showBadge, userSentiment, hidden, - systemGeneratedSmartActions, smartReplies, audiblyAlerted, noisy); + systemGeneratedSmartActions, smartReplies, lastAudiblyAlerted, noisy); } boolean hasCompanionDevice(ManagedServiceInfo info) { diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index 50810ccc8cbc..39451d40a97e 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -132,6 +132,9 @@ public final class NotificationRecord { // user private long mInterruptionTimeMs; + // The most recent time the notification made noise or buzzed the device, or -1 if it did not. + private long mLastAudiblyAlertedMs; + // Is this record an update of an old record? public boolean isUpdate; private int mPackagePriority; @@ -172,7 +175,6 @@ public final class NotificationRecord { private final NotificationStats mStats; private int mUserSentiment; private boolean mIsInterruptive; - private boolean mAudiblyAlerted; private boolean mTextChanged; private boolean mRecordedInterruption; private int mNumberOfSmartRepliesAdded; @@ -1051,7 +1053,7 @@ public final class NotificationRecord { } public void setAudiblyAlerted(boolean audiblyAlerted) { - mAudiblyAlerted = audiblyAlerted; + mLastAudiblyAlertedMs = audiblyAlerted ? System.currentTimeMillis() : -1; } public void setTextChanged(boolean textChanged) { @@ -1070,9 +1072,9 @@ public final class NotificationRecord { return mIsInterruptive; } - /** Returns true if the notification audibly alerted the user. */ - public boolean getAudiblyAlerted() { - return mAudiblyAlerted; + /** Returns the time the notification audibly alerted the user. */ + public long getLastAudiblyAlertedMs() { + return mLastAudiblyAlertedMs; } protected void setPeopleOverride(ArrayList<String> people) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java index 41d5a1c2fac4..afbe6bc21d0d 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java @@ -27,6 +27,8 @@ import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyInt; @@ -417,7 +419,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyLights(); assertTrue(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -430,7 +432,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverVibrate(); verify(mAccessibilityService, times(1)).sendAccessibilityEvent(any(), anyInt()); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -441,7 +443,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyBeep(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -452,7 +454,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverBeep(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -490,7 +492,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverBeep(); verifyNeverVibrate(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -503,7 +505,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverBeep(); verifyNeverVibrate(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -520,7 +522,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyBeepLooped(); verify(mAccessibilityService, times(2)).sendAccessibilityEvent(any(), anyInt()); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -549,7 +551,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverStopAudio(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -563,9 +565,9 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverStopAudio(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } /** @@ -602,7 +604,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(s); // this no longer owns the stream verifyNeverStopAudio(); assertTrue(other.isInterruptive()); - assertTrue(other.getAudiblyAlerted()); + assertNotEquals(-1, other.getLastAudiblyAlertedMs()); } @Test @@ -628,14 +630,14 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { // set up internal state mService.buzzBeepBlinkLocked(r); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // quiet update should stop making noise mService.buzzBeepBlinkLocked(s); verifyStopAudio(); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -647,14 +649,14 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { // set up internal state mService.buzzBeepBlinkLocked(r); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); Mockito.reset(mRingtonePlayer); // stop making noise - this is a weird corner case, but quiet should override once mService.buzzBeepBlinkLocked(s); verifyStopAudio(); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -671,7 +673,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verify(mService, times(1)).playInCallNotification(); verifyNeverBeep(); // doesn't play normal beep assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -691,7 +693,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { eq(effect), anyString(), (AudioAttributes) anyObject()); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -709,7 +711,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverVibrate(); verifyBeepLooped(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -729,7 +731,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verify(mRingtonePlayer, never()).playAsync (anyObject(), anyObject(), anyBoolean(), anyObject()); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -746,7 +748,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyDelayedVibrateLooped(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -758,7 +760,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverBeep(); verifyVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -768,7 +770,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyVibrateLooped(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -784,7 +786,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -795,7 +797,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverBeep(); assertFalse(child.isInterruptive()); - assertFalse(child.getAudiblyAlerted()); + assertEquals(-1, child.getLastAudiblyAlertedMs()); } @Test @@ -808,7 +810,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyBeepLooped(); // summaries are never interruptive for notification counts assertFalse(summary.isInterruptive()); - assertTrue(summary.getAudiblyAlerted()); + assertNotEquals(-1, summary.getLastAudiblyAlertedMs()); } @Test @@ -819,7 +821,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyBeepLooped(); assertTrue(nonGroup.isInterruptive()); - assertTrue(nonGroup.getAudiblyAlerted()); + assertNotEquals(-1, nonGroup.getLastAudiblyAlertedMs()); } @Test @@ -831,7 +833,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverBeep(); assertFalse(summary.isInterruptive()); - assertFalse(summary.getAudiblyAlerted()); + assertEquals(-1, summary.getLastAudiblyAlertedMs()); } @Test @@ -842,7 +844,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyBeepLooped(); assertTrue(child.isInterruptive()); - assertTrue(child.getAudiblyAlerted()); + assertNotEquals(-1, child.getLastAudiblyAlertedMs()); } @Test @@ -853,7 +855,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyBeepLooped(); assertTrue(nonGroup.isInterruptive()); - assertTrue(nonGroup.getAudiblyAlerted()); + assertNotEquals(-1, nonGroup.getLastAudiblyAlertedMs()); } @Test @@ -864,7 +866,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyBeepLooped(); assertTrue(group.isInterruptive()); - assertTrue(group.getAudiblyAlerted()); + assertNotEquals(-1, group.getLastAudiblyAlertedMs()); } @Test @@ -877,13 +879,13 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); Mockito.reset(mVibrator); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); // update should not beep mService.buzzBeepBlinkLocked(s); verifyNeverVibrate(); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -896,7 +898,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverStopVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -910,9 +912,9 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverStopVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -931,11 +933,11 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(s); // this no longer owns the stream verifyNeverStopVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); assertTrue(other.isInterruptive()); - assertTrue(other.getAudiblyAlerted()); + assertNotEquals(-1, other.getLastAudiblyAlertedMs()); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -951,7 +953,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(other); verifyNeverStopVibrate(); assertFalse(other.isInterruptive()); - assertFalse(other.getAudiblyAlerted()); + assertEquals(-1, other.getLastAudiblyAlertedMs()); } @Test @@ -968,9 +970,9 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(s); verifyStopVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -987,9 +989,9 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(s); verifyStopVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -1007,9 +1009,9 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(s); verifyStopVibrate(); assertTrue(r.isInterruptive()); - assertTrue(r.getAudiblyAlerted()); + assertNotEquals(-1, r.getLastAudiblyAlertedMs()); assertFalse(s.isInterruptive()); - assertFalse(s.getAudiblyAlerted()); + assertEquals(-1, s.getLastAudiblyAlertedMs()); } @Test @@ -1027,7 +1029,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1039,7 +1041,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1082,7 +1084,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverBeep(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1116,7 +1118,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1126,7 +1128,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1135,7 +1137,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyLights(); assertTrue(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); r = getLightsOnceNotification(); r.isUpdate = true; @@ -1143,7 +1145,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { // checks that lights happened once, i.e. this new call didn't trigger them again verifyLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1153,7 +1155,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1162,7 +1164,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1172,7 +1174,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1182,7 +1184,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1192,7 +1194,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { mService.buzzBeepBlinkLocked(r); verifyNeverLights(); assertFalse(r.isInterruptive()); - assertFalse(r.getAudiblyAlerted()); + assertEquals(-1, r.getLastAudiblyAlertedMs()); } @Test @@ -1203,7 +1205,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverLights(); assertFalse(child.isInterruptive()); - assertFalse(child.getAudiblyAlerted()); + assertEquals(-1, child.getLastAudiblyAlertedMs()); } @Test @@ -1216,7 +1218,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyLights(); // summaries should never count for interruptiveness counts assertFalse(summary.isInterruptive()); - assertFalse(summary.getAudiblyAlerted()); + assertEquals(-1, summary.getLastAudiblyAlertedMs()); } @Test @@ -1227,7 +1229,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyLights(); assertTrue(nonGroup.isInterruptive()); - assertFalse(nonGroup.getAudiblyAlerted()); + assertEquals(-1, nonGroup.getLastAudiblyAlertedMs()); } @Test @@ -1239,7 +1241,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyNeverLights(); assertFalse(summary.isInterruptive()); - assertFalse(summary.getAudiblyAlerted()); + assertEquals(-1, summary.getLastAudiblyAlertedMs()); } @Test @@ -1250,7 +1252,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyLights(); assertTrue(child.isInterruptive()); - assertFalse(child.getAudiblyAlerted()); + assertEquals(-1, child.getLastAudiblyAlertedMs()); } @Test @@ -1261,7 +1263,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyLights(); assertTrue(nonGroup.isInterruptive()); - assertFalse(nonGroup.getAudiblyAlerted()); + assertEquals(-1, nonGroup.getLastAudiblyAlertedMs()); } @Test @@ -1272,7 +1274,7 @@ public class BuzzBeepBlinkTest extends UiServiceTestCase { verifyLights(); assertTrue(group.isInterruptive()); - assertFalse(group.getAudiblyAlerted()); + assertEquals(-1, group.getLastAudiblyAlertedMs()); } static class VibrateRepeatMatcher implements ArgumentMatcher<VibrationEffect> { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenerServiceTest.java index bcba15df8756..daca9cb28051 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationListenerServiceTest.java @@ -16,12 +16,9 @@ package com.android.server.notification; -import static android.service.notification.NotificationListenerService.Ranking - .USER_SENTIMENT_NEGATIVE; -import static android.service.notification.NotificationListenerService.Ranking - .USER_SENTIMENT_NEUTRAL; -import static android.service.notification.NotificationListenerService.Ranking - .USER_SENTIMENT_POSITIVE; +import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; +import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL; +import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_POSITIVE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -92,7 +89,7 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { assertEquals(getShowBadge(i), ranking.canShowBadge()); assertEquals(getUserSentiment(i), ranking.getUserSentiment()); assertEquals(getHidden(i), ranking.isSuspended()); - assertEquals(audiblyAlerted(i), ranking.audiblyAlerted()); + assertEquals(lastAudiblyAlerted(i), ranking.getLastAudiblyAlertedMillis()); assertActionsEqual(getSmartActions(key, i), ranking.getSmartActions()); assertEquals(getSmartReplies(key, i), ranking.getSmartReplies()); } @@ -113,7 +110,7 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { Bundle mHidden = new Bundle(); Bundle smartActions = new Bundle(); Bundle smartReplies = new Bundle(); - Bundle audiblyAlerted = new Bundle(); + Bundle lastAudiblyAlerted = new Bundle(); Bundle noisy = new Bundle(); for (int i = 0; i < mKeys.length; i++) { @@ -134,14 +131,14 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { mHidden.putBoolean(key, getHidden(i)); smartActions.putParcelableArrayList(key, getSmartActions(key, i)); smartReplies.putCharSequenceArrayList(key, getSmartReplies(key, i)); - audiblyAlerted.putBoolean(key, audiblyAlerted(i)); + lastAudiblyAlerted.putLong(key, lastAudiblyAlerted(i)); noisy.putBoolean(key, getNoisy(i)); } NotificationRankingUpdate update = new NotificationRankingUpdate(mKeys, interceptedKeys.toArray(new String[0]), visibilityOverrides, suppressedVisualEffects, importance, explanation, overrideGroupKeys, channels, overridePeople, snoozeCriteria, showBadge, userSentiment, mHidden, - smartActions, smartReplies, audiblyAlerted, noisy); + smartActions, smartReplies, lastAudiblyAlerted, noisy); return update; } @@ -193,8 +190,8 @@ public class NotificationListenerServiceTest extends UiServiceTestCase { return index % 2 == 0; } - private boolean audiblyAlerted(int index) { - return index < 2; + private long lastAudiblyAlerted(int index) { + return index * 2000; } private boolean getNoisy(int index) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java index 0eeeeed0b227..65e640f5f73c 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationRecordTest.java @@ -19,12 +19,9 @@ import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_LOW; -import static android.service.notification.NotificationListenerService.Ranking - .USER_SENTIMENT_NEGATIVE; -import static android.service.notification.NotificationListenerService.Ranking - .USER_SENTIMENT_NEUTRAL; -import static android.service.notification.NotificationListenerService.Ranking - .USER_SENTIMENT_POSITIVE; +import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE; +import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL; +import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_POSITIVE; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; @@ -806,6 +803,18 @@ public class NotificationRecordTest extends UiServiceTestCase { } @Test + public void testSetDidNotAudiblyAlert() { + StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, + true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, + false /* lights */, false /* defaultLights */, groupId /* group */); + NotificationRecord record = new NotificationRecord(mMockContext, sbn, channel); + + record.setAudiblyAlerted(false); + + assertEquals(-1, record.getLastAudiblyAlertedMs()); + } + + @Test public void testSetAudiblyAlerted() { StatusBarNotification sbn = getNotification(PKG_O, true /* noisy */, true /* defaultSound */, false /* buzzy */, false /* defaultBuzz */, @@ -814,6 +823,6 @@ public class NotificationRecordTest extends UiServiceTestCase { record.setAudiblyAlerted(true); - assertTrue(record.getAudiblyAlerted()); + assertNotEquals(-1, record.getLastAudiblyAlertedMs()); } } |