|
76 | 76 | import android.os.Message; |
77 | 77 | import android.os.Process; |
78 | 78 | import android.os.RemoteException; |
| 79 | +import android.os.SystemClock; |
79 | 80 | import android.os.SystemProperties; |
80 | 81 | import android.os.UserHandle; |
81 | 82 | import android.os.UserManager; |
|
100 | 101 | import android.util.LruCache; |
101 | 102 | import android.util.Slog; |
102 | 103 | import android.util.SparseIntArray; |
| 104 | +import android.util.TimeUtils; |
103 | 105 | import android.util.Xml; |
104 | 106 | import android.view.accessibility.AccessibilityEvent; |
105 | 107 | import android.view.accessibility.AccessibilityManager; |
@@ -302,6 +304,7 @@ public class NotificationManagerService extends SystemService { |
302 | 304 | new ArrayMap<String, NotificationRecord>(); |
303 | 305 | final ArrayList<ToastRecord> mToastQueue = new ArrayList<ToastRecord>(); |
304 | 306 | final ArrayMap<String, NotificationRecord> mSummaryByGroupKey = new ArrayMap<>(); |
| 307 | + final ArrayMap<String, Long> mLastSoundTimestamps = new ArrayMap<>(); |
305 | 308 | final PolicyAccess mPolicyAccess = new PolicyAccess(); |
306 | 309 |
|
307 | 310 | // The last key in this list owns the hardware. |
@@ -1595,6 +1598,19 @@ public int getShowNotificationForPackageOnKeyguard(String pkg, int uid) { |
1595 | 1598 | return mRankingHelper.getShowNotificationForPackageOnKeyguard(pkg, uid); |
1596 | 1599 | } |
1597 | 1600 |
|
| 1601 | + @Override |
| 1602 | + public void setPackageNotificationSoundTimeout(String pkg, int uid, long timeout) { |
| 1603 | + checkCallerIsSystem(); |
| 1604 | + mRankingHelper.setPackageNotificationSoundTimeout(pkg, uid, timeout); |
| 1605 | + savePolicyFile(); |
| 1606 | + } |
| 1607 | + |
| 1608 | + @Override |
| 1609 | + public long getPackageNotificationSoundTimeout(String pkg, int uid) { |
| 1610 | + checkCallerIsSystem(); |
| 1611 | + return mRankingHelper.getPackageNotificationSoundTimeout(pkg, uid); |
| 1612 | + } |
| 1613 | + |
1598 | 1614 | /** |
1599 | 1615 | * System-only API for getting a list of current (i.e. not cleared) notifications. |
1600 | 1616 | * |
@@ -2317,6 +2333,14 @@ void dumpImpl(PrintWriter pw, DumpFilter filter) { |
2317 | 2333 | } catch (NameNotFoundException e) { |
2318 | 2334 | // pass |
2319 | 2335 | } |
| 2336 | + |
| 2337 | + long now = SystemClock.elapsedRealtime(); |
| 2338 | + pw.println("\n Last notification sound timestamps:"); |
| 2339 | + for (Map.Entry<String, Long> entry: mLastSoundTimestamps.entrySet()) { |
| 2340 | + pw.print(" " + entry.getKey() + " -> "); |
| 2341 | + TimeUtils.formatDuration(entry.getValue(), now, pw); |
| 2342 | + pw.println(" ago"); |
| 2343 | + } |
2320 | 2344 | } |
2321 | 2345 | } |
2322 | 2346 |
|
@@ -2705,6 +2729,7 @@ private void buzzBeepBlinkLocked(NotificationRecord record) { |
2705 | 2729 | && (record.getUserId() == UserHandle.USER_ALL || |
2706 | 2730 | record.getUserId() == currentUser || |
2707 | 2731 | mUserProfiles.isCurrentProfile(record.getUserId())) |
| 2732 | + && !isInSoundTimeoutPeriod(record) |
2708 | 2733 | && mSystemReady |
2709 | 2734 | && mAudioManager != null; |
2710 | 2735 |
|
@@ -2835,13 +2860,35 @@ private void buzzBeepBlinkLocked(NotificationRecord record) { |
2835 | 2860 | } else if (wasShowLights) { |
2836 | 2861 | updateLightsLocked(); |
2837 | 2862 | } |
| 2863 | + if (buzz || beep) { |
| 2864 | + mLastSoundTimestamps.put(generateLastSoundTimeoutKey(record), |
| 2865 | + SystemClock.elapsedRealtime()); |
| 2866 | + } |
2838 | 2867 | if (buzz || beep || blink) { |
2839 | 2868 | EventLogTags.writeNotificationAlert(record.getKey(), |
2840 | 2869 | buzz ? 1 : 0, beep ? 1 : 0, blink ? 1 : 0); |
2841 | 2870 | mHandler.post(mBuzzBeepBlinked); |
2842 | 2871 | } |
2843 | 2872 | } |
2844 | 2873 |
|
| 2874 | + private boolean isInSoundTimeoutPeriod(NotificationRecord record) { |
| 2875 | + long timeoutMillis = mRankingHelper.getPackageNotificationSoundTimeout( |
| 2876 | + record.sbn.getPackageName(), record.sbn.getUid()); |
| 2877 | + if (timeoutMillis == 0) { |
| 2878 | + return false; |
| 2879 | + } |
| 2880 | + |
| 2881 | + Long value = mLastSoundTimestamps.get(generateLastSoundTimeoutKey(record)); |
| 2882 | + if (value == null) { |
| 2883 | + return false; |
| 2884 | + } |
| 2885 | + return SystemClock.elapsedRealtime() - value < timeoutMillis; |
| 2886 | + } |
| 2887 | + |
| 2888 | + private String generateLastSoundTimeoutKey(NotificationRecord record) { |
| 2889 | + return record.sbn.getPackageName() + "|" + record.sbn.getUid(); |
| 2890 | + } |
| 2891 | + |
2845 | 2892 | private static AudioAttributes audioAttributesForNotification(Notification n) { |
2846 | 2893 | if (n.audioAttributes != null |
2847 | 2894 | && !Notification.AUDIO_ATTRIBUTES_DEFAULT.equals(n.audioAttributes)) { |
|
0 commit comments