From fc2be9c0d2beddfbff420d64c0af3d287327a2ee Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Fri, 8 Nov 2019 18:26:47 -0800 Subject: [PATCH] Fix double-add of calls In the api compatibility logic for the new call states, we might end up adding a call by accident in internalUpdateCall if a call was updated in the NEW state, and it'd then get added again when internalAddCall gets called. To fix this, restrict the call states that would result in an add from internalUpdateCall, and also don't add the call again in internalAddCall if it's already present. Fixes: 143049799 Test: CTS Change-Id: I2a6b646a5200fedf9e02029a7120595210a24c76 --- telecomm/java/android/telecom/Phone.java | 27 +++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/telecomm/java/android/telecom/Phone.java b/telecomm/java/android/telecom/Phone.java index 2ecdb30356850..61a639a1a2352 100644 --- a/telecomm/java/android/telecom/Phone.java +++ b/telecomm/java/android/telecom/Phone.java @@ -152,13 +152,20 @@ public final class Phone { return; } - Call call = new Call(this, parcelableCall.getId(), mInCallAdapter, - parcelableCall.getState(), mCallingPackage, mTargetSdkVersion); - mCallByTelecomCallId.put(parcelableCall.getId(), call); - mCalls.add(call); - checkCallTree(parcelableCall); - call.internalUpdate(parcelableCall, mCallByTelecomCallId); - fireCallAdded(call); + Call call = mCallByTelecomCallId.get(parcelableCall.getId()); + if (call == null) { + call = new Call(this, parcelableCall.getId(), mInCallAdapter, + parcelableCall.getState(), mCallingPackage, mTargetSdkVersion); + mCallByTelecomCallId.put(parcelableCall.getId(), call); + mCalls.add(call); + checkCallTree(parcelableCall); + call.internalUpdate(parcelableCall, mCallByTelecomCallId); + fireCallAdded(call); + } else { + Log.w(this, "Call %s added, but it was already present", call.internalGetCallId()); + checkCallTree(parcelableCall); + call.internalUpdate(parcelableCall, mCallByTelecomCallId); + } } final void internalRemoveCall(Call call) { @@ -190,7 +197,11 @@ public final class Phone { } else { // This call may have come out of audio processing. Try adding it if our target sdk // version is low enough. - if (mTargetSdkVersion < SDK_VERSION_R) { + // The only two allowable states coming out of audio processing are ACTIVE and + // SIMULATED_RINGING. + if (mTargetSdkVersion < SDK_VERSION_R && (parcelableCall.getState() == Call.STATE_ACTIVE + || parcelableCall.getState() == Call.STATE_SIMULATED_RINGING)) { + Log.i(this, "adding call during update for sdk compatibility"); internalAddCall(parcelableCall); } }