|
75 | 75 | import android.service.notification.NotificationRankingUpdate; |
76 | 76 | import android.service.notification.StatusBarNotification; |
77 | 77 | import android.service.notification.ZenModeConfig; |
| 78 | +import android.telephony.PhoneStateListener; |
78 | 79 | import android.telephony.TelephonyManager; |
79 | 80 | import android.text.TextUtils; |
80 | 81 | import android.util.ArrayMap; |
@@ -187,6 +188,7 @@ public class NotificationManagerService extends SystemService { |
187 | 188 | boolean mSystemReady; |
188 | 189 |
|
189 | 190 | private boolean mDisableNotificationEffects; |
| 191 | + private int mCallState; |
190 | 192 | NotificationRecord mSoundNotification; |
191 | 193 | NotificationRecord mVibrateNotification; |
192 | 194 |
|
@@ -490,7 +492,7 @@ public void onSetDisabled(int status) { |
490 | 492 | synchronized (mNotificationList) { |
491 | 493 | mDisableNotificationEffects = |
492 | 494 | (status & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0; |
493 | | - if (disableNotificationEffects()) { |
| 495 | + if (disableNotificationEffects(null) != null) { |
494 | 496 | // cancel whatever's going on |
495 | 497 | long identity = Binder.clearCallingIdentity(); |
496 | 498 | try { |
@@ -875,6 +877,7 @@ void onZenModeChanged() { |
875 | 877 | mZenModeHelper.updateZenMode(); |
876 | 878 |
|
877 | 879 | mUserProfiles.updateCache(getContext()); |
| 880 | + listenForCallState(); |
878 | 881 |
|
879 | 882 | // register for various Intents |
880 | 883 | IntentFilter filter = new IntentFilter(); |
@@ -1510,8 +1513,17 @@ private String[] getActiveNotificationKeys(INotificationListener token) { |
1510 | 1513 | return keys.toArray(new String[keys.size()]); |
1511 | 1514 | } |
1512 | 1515 |
|
1513 | | - private boolean disableNotificationEffects() { |
1514 | | - return mDisableNotificationEffects || (mListenerHints & HINT_HOST_DISABLE_EFFECTS) != 0; |
| 1516 | + private String disableNotificationEffects(NotificationRecord record) { |
| 1517 | + if (mDisableNotificationEffects) { |
| 1518 | + return "booleanState"; |
| 1519 | + } |
| 1520 | + if ((mListenerHints & HINT_HOST_DISABLE_EFFECTS) != 0) { |
| 1521 | + return "listenerHints"; |
| 1522 | + } |
| 1523 | + if (mCallState != TelephonyManager.CALL_STATE_IDLE && !mZenModeHelper.isCall(record)) { |
| 1524 | + return "callState"; |
| 1525 | + } |
| 1526 | + return null; |
1515 | 1527 | } |
1516 | 1528 |
|
1517 | 1529 | void dumpImpl(PrintWriter pw, DumpFilter filter) { |
@@ -1563,6 +1575,7 @@ void dumpImpl(PrintWriter pw, DumpFilter filter) { |
1563 | 1575 | pw.println(" mSoundNotification=" + mSoundNotification); |
1564 | 1576 | pw.println(" mVibrateNotification=" + mVibrateNotification); |
1565 | 1577 | pw.println(" mDisableNotificationEffects=" + mDisableNotificationEffects); |
| 1578 | + pw.println(" mCallState=" + callStateToString(mCallState)); |
1566 | 1579 | pw.println(" mSystemReady=" + mSystemReady); |
1567 | 1580 | } |
1568 | 1581 | pw.println(" mArchive=" + mArchive.toString()); |
@@ -1839,7 +1852,11 @@ private void buzzBeepBlinkLocked(NotificationRecord record) { |
1839 | 1852 | } |
1840 | 1853 |
|
1841 | 1854 | // If we're not supposed to beep, vibrate, etc. then don't. |
1842 | | - if (!disableNotificationEffects() |
| 1855 | + final String disableEffects = disableNotificationEffects(record); |
| 1856 | + if (disableEffects != null) { |
| 1857 | + ZenLog.traceDisableEffects(record, disableEffects); |
| 1858 | + } |
| 1859 | + if (disableEffects == null |
1843 | 1860 | && (!(record.isUpdate |
1844 | 1861 | && (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 )) |
1845 | 1862 | && (record.getUserId() == UserHandle.USER_ALL || |
@@ -2657,6 +2674,26 @@ private static void checkCallerIsSystemOrSameApp(String pkg) { |
2657 | 2674 | } |
2658 | 2675 | } |
2659 | 2676 |
|
| 2677 | + private static String callStateToString(int state) { |
| 2678 | + switch (state) { |
| 2679 | + case TelephonyManager.CALL_STATE_IDLE: return "CALL_STATE_IDLE"; |
| 2680 | + case TelephonyManager.CALL_STATE_RINGING: return "CALL_STATE_RINGING"; |
| 2681 | + case TelephonyManager.CALL_STATE_OFFHOOK: return "CALL_STATE_OFFHOOK"; |
| 2682 | + default: return "CALL_STATE_UNKNOWN_" + state; |
| 2683 | + } |
| 2684 | + } |
| 2685 | + |
| 2686 | + private void listenForCallState() { |
| 2687 | + TelephonyManager.from(getContext()).listen(new PhoneStateListener() { |
| 2688 | + @Override |
| 2689 | + public void onCallStateChanged(int state, String incomingNumber) { |
| 2690 | + if (mCallState == state) return; |
| 2691 | + if (DBG) Slog.d(TAG, "Call state changed: " + callStateToString(state)); |
| 2692 | + mCallState = state; |
| 2693 | + } |
| 2694 | + }, PhoneStateListener.LISTEN_CALL_STATE); |
| 2695 | + } |
| 2696 | + |
2660 | 2697 | /** |
2661 | 2698 | * Generates a NotificationRankingUpdate from 'sbns', considering only |
2662 | 2699 | * notifications visible to the given listener. |
|
0 commit comments