Skip to content

Commit a23867c

Browse files
John SpurlockAndroid (Google) Code Review
authored andcommitted
Merge "Disable notification effects during phone calls." into lmp-dev
2 parents c5146e8 + 32fe4c6 commit a23867c

3 files changed

Lines changed: 50 additions & 7 deletions

File tree

services/core/java/com/android/server/notification/NotificationManagerService.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import android.service.notification.NotificationRankingUpdate;
7676
import android.service.notification.StatusBarNotification;
7777
import android.service.notification.ZenModeConfig;
78+
import android.telephony.PhoneStateListener;
7879
import android.telephony.TelephonyManager;
7980
import android.text.TextUtils;
8081
import android.util.ArrayMap;
@@ -187,6 +188,7 @@ public class NotificationManagerService extends SystemService {
187188
boolean mSystemReady;
188189

189190
private boolean mDisableNotificationEffects;
191+
private int mCallState;
190192
NotificationRecord mSoundNotification;
191193
NotificationRecord mVibrateNotification;
192194

@@ -490,7 +492,7 @@ public void onSetDisabled(int status) {
490492
synchronized (mNotificationList) {
491493
mDisableNotificationEffects =
492494
(status & StatusBarManager.DISABLE_NOTIFICATION_ALERTS) != 0;
493-
if (disableNotificationEffects()) {
495+
if (disableNotificationEffects(null) != null) {
494496
// cancel whatever's going on
495497
long identity = Binder.clearCallingIdentity();
496498
try {
@@ -875,6 +877,7 @@ void onZenModeChanged() {
875877
mZenModeHelper.updateZenMode();
876878

877879
mUserProfiles.updateCache(getContext());
880+
listenForCallState();
878881

879882
// register for various Intents
880883
IntentFilter filter = new IntentFilter();
@@ -1510,8 +1513,17 @@ private String[] getActiveNotificationKeys(INotificationListener token) {
15101513
return keys.toArray(new String[keys.size()]);
15111514
}
15121515

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;
15151527
}
15161528

15171529
void dumpImpl(PrintWriter pw, DumpFilter filter) {
@@ -1563,6 +1575,7 @@ void dumpImpl(PrintWriter pw, DumpFilter filter) {
15631575
pw.println(" mSoundNotification=" + mSoundNotification);
15641576
pw.println(" mVibrateNotification=" + mVibrateNotification);
15651577
pw.println(" mDisableNotificationEffects=" + mDisableNotificationEffects);
1578+
pw.println(" mCallState=" + callStateToString(mCallState));
15661579
pw.println(" mSystemReady=" + mSystemReady);
15671580
}
15681581
pw.println(" mArchive=" + mArchive.toString());
@@ -1839,7 +1852,11 @@ private void buzzBeepBlinkLocked(NotificationRecord record) {
18391852
}
18401853

18411854
// 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
18431860
&& (!(record.isUpdate
18441861
&& (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) != 0 ))
18451862
&& (record.getUserId() == UserHandle.USER_ALL ||
@@ -2657,6 +2674,26 @@ private static void checkCallerIsSystemOrSameApp(String pkg) {
26572674
}
26582675
}
26592676

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+
26602697
/**
26612698
* Generates a NotificationRankingUpdate from 'sbns', considering only
26622699
* notifications visible to the given listener.

services/core/java/com/android/server/notification/ZenLog.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class ZenLog {
5555
private static final int TYPE_CONFIG = 10;
5656
private static final int TYPE_FOLLOW_RINGER_MODE = 11;
5757
private static final int TYPE_NOT_INTERCEPTED = 12;
58+
private static final int TYPE_DISABLE_EFFECTS = 13;
5859

5960
private static int sNext;
6061
private static int sSize;
@@ -106,6 +107,10 @@ public static void traceFollowRingerMode(int ringerMode, int oldZen, int newZen)
106107
+ zenModeToString(oldZen) + " -> " + zenModeToString(newZen));
107108
}
108109

110+
public static void traceDisableEffects(NotificationRecord record, String reason) {
111+
append(TYPE_DISABLE_EFFECTS, record.getKey() + "," + reason);
112+
}
113+
109114
private static String subscribeResult(IConditionProvider provider, RemoteException e) {
110115
return provider == null ? "no provider" : e != null ? e.getMessage() : "ok";
111116
}
@@ -124,6 +129,7 @@ private static String typeToString(int type) {
124129
case TYPE_CONFIG: return "config";
125130
case TYPE_FOLLOW_RINGER_MODE: return "follow_ringer_mode";
126131
case TYPE_NOT_INTERCEPTED: return "not_intercepted";
132+
case TYPE_DISABLE_EFFECTS: return "disable_effects";
127133
default: return "unknown";
128134
}
129135
}

services/core/java/com/android/server/notification/ZenModeHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,9 @@ private static boolean isEvent(NotificationRecord record) {
350350
return record.isCategory(Notification.CATEGORY_EVENT);
351351
}
352352

353-
private boolean isCall(NotificationRecord record) {
354-
return isDefaultPhoneApp(record.sbn.getPackageName())
355-
|| record.isCategory(Notification.CATEGORY_CALL);
353+
public boolean isCall(NotificationRecord record) {
354+
return record != null && (isDefaultPhoneApp(record.sbn.getPackageName())
355+
|| record.isCategory(Notification.CATEGORY_CALL));
356356
}
357357

358358
private boolean isDefaultPhoneApp(String pkg) {

0 commit comments

Comments
 (0)