diff options
| author | 2022-10-14 14:25:14 -0700 | |
|---|---|---|
| committer | 2022-11-21 20:44:46 +0000 | |
| commit | 2db19d26c9372e83b04509e836a455185aaaaef8 (patch) | |
| tree | d41c57967581b2fc968fa23100d068a249629cc3 | |
| parent | 489bdd0de491bd0a13b1e1aac921fe06bbd8f43e (diff) | |
Improve display name to avoid callback when it did not change
Update the caller display name only if the name actually changed.
This avoids excessive computations on the receiver end as apps such
as dialer listen to these changes and rebuild UI models when they
change.
Defer-CP-To-TM: 240341306
Bug: 240341306
Test: Manual logs to verify callback triggers only when changed.
Test: atest CallDetailsTest
Change-Id: I1c81049240042232ca5c3efa9a75ce2ef2de1829
| -rw-r--r-- | telecomm/java/android/telecom/Connection.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java index 7c736e38897d..568c8abc40a2 100644 --- a/telecomm/java/android/telecom/Connection.java +++ b/telecomm/java/android/telecom/Connection.java @@ -66,6 +66,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -2531,11 +2532,21 @@ public abstract class Connection extends Conferenceable { */ public final void setCallerDisplayName(String callerDisplayName, int presentation) { checkImmutable(); - Log.d(this, "setCallerDisplayName %s", callerDisplayName); - mCallerDisplayName = callerDisplayName; - mCallerDisplayNamePresentation = presentation; - for (Listener l : mListeners) { - l.onCallerDisplayNameChanged(this, callerDisplayName, presentation); + boolean nameChanged = !Objects.equals(mCallerDisplayName, callerDisplayName); + boolean presentationChanged = mCallerDisplayNamePresentation != presentation; + if (nameChanged) { + // Ensure the new name is not clobbering the old one with a null value due to the caller + // wanting to only set the presentation and not knowing the display name. + mCallerDisplayName = callerDisplayName; + } + if (presentationChanged) { + mCallerDisplayNamePresentation = presentation; + } + if (nameChanged || presentationChanged) { + for (Listener l : mListeners) { + l.onCallerDisplayNameChanged(this, mCallerDisplayName, + mCallerDisplayNamePresentation); + } } } |