Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 80914bce authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

DSDA: Pending account selection multi-call aware

Ensure that the pending account selection is multi-call aware. Normally,
we clear the pending account selection future when we disconnect a call.
However, when we have a new call that is pending account selection and
we disconnect the active call, we will end up clearing the pending
account future for the new call and inadvertently cause that new call to
disconnect.

Bug: 396664319
Test: atest
CallsManagerTest#testPendingAccountSelectionNotClearedWithNewCall
Flag: EXEMPT bug fix

Change-Id: I1dafd06061ce072093d0f0b3b621d3ffc4a3d8f9
parent a762d437
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -432,7 +432,10 @@ public class CallsManager extends Call.ListenerBase
            new ConcurrentHashMap<>();

    private CompletableFuture<Call> mPendingCallConfirm;
    private CompletableFuture<Pair<Call, PhoneAccountHandle>> mPendingAccountSelection;
    // Map the call's id to the corresponding pending account selection future associated with the
    // call.
    private final Map<String, CompletableFuture<Pair<Call, PhoneAccountHandle>>>
            mPendingAccountSelection;

    // Instance variables for testing -- we keep the latest copy of the outgoing call futures
    // here so that we can wait on them in tests
@@ -858,6 +861,7 @@ public class CallsManager extends Call.ListenerBase
        mCallAnomalyWatchdog = callAnomalyWatchdog;
        mAsyncTaskExecutor = asyncTaskExecutor;
        mUserManager = mContext.getSystemService(UserManager.class);
        mPendingAccountSelection = new HashMap<>();
    }

    public void setIncomingCallNotifier(IncomingCallNotifier incomingCallNotifier) {
@@ -2420,11 +2424,12 @@ public class CallsManager extends Call.ListenerBase
                                    android.telecom.Call.EXTRA_SUGGESTED_PHONE_ACCOUNTS,
                                    accountSuggestions);
                            // Set a future in place so that we can proceed once the dialer replies.
                            mPendingAccountSelection = new CompletableFuture<>();
                            mPendingAccountSelection.put(callToPlace.getId(),
                                    new CompletableFuture<>());
                            callToPlace.setIntentExtras(newExtras);

                            addCall(callToPlace);
                            return mPendingAccountSelection;
                            return mPendingAccountSelection.get(callToPlace.getId());
                        }, new LoggedHandlerExecutor(outgoingCallHandler, "CM.dSPA", mLock));

        // Potentially perform call identification for dialed TEL scheme numbers.
@@ -3586,10 +3591,12 @@ public class CallsManager extends Call.ListenerBase
            mPendingCallConfirm.complete(null);
            mPendingCallConfirm = null;
        }
        if (mPendingAccountSelection != null && !mPendingAccountSelection.isDone()) {
            mPendingAccountSelection.complete(null);
            mPendingAccountSelection = null;
        String callId = call.getId();
        if (mPendingAccountSelection.containsKey(callId)
                && !mPendingAccountSelection.get(callId).isDone()) {
            mPendingAccountSelection.get(callId).complete(null);
        }
        mPendingAccountSelection.remove(callId);
    }
    /**
     * Disconnects calls for any other {@link PhoneAccountHandle} but the one specified.
@@ -3984,9 +3991,10 @@ public class CallsManager extends Call.ListenerBase
                        .setUserSelectedOutgoingPhoneAccount(account, call.getAssociatedUser());
            }

            if (mPendingAccountSelection != null) {
                mPendingAccountSelection.complete(Pair.create(call, account));
                mPendingAccountSelection = null;
            String callId = call.getId();
            if (mPendingAccountSelection.containsKey(callId)) {
                mPendingAccountSelection.get(callId).complete(Pair.create(call, account));
                mPendingAccountSelection.remove(callId);
            }
        }
    }
@@ -7174,4 +7182,10 @@ public class CallsManager extends Call.ListenerBase
            }
        }
    }

    @VisibleForTesting
    public Map<String, CompletableFuture<Pair<Call, PhoneAccountHandle>>>
    getPendingAccountSelection() {
        return mPendingAccountSelection;
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -3777,6 +3777,19 @@ public class CallsManagerTest extends TelecomTestCase {
        inOrder.verify(call).setState(eq(CallState.RINGING), anyString());
    }

    @SmallTest
    @Test
    public void testPendingAccountSelectionNotClearedWithNewCall() {
        Call ongoingCall = createSpyCall(SIM_1_HANDLE, CallState.ACTIVE);
        mCallsManager.getPendingAccountSelection().put(ongoingCall.getId(),
                CompletableFuture.completedFuture(new Pair<>(ongoingCall, SIM_1_HANDLE)));
        Call pendingCall = createSpyCall(SIM_1_HANDLE, CallState.SELECT_PHONE_ACCOUNT);
        mCallsManager.getPendingAccountSelection().put(pendingCall.getId(),
                CompletableFuture.completedFuture(new Pair<>(pendingCall, SIM_1_HANDLE)));
        mCallsManager.processDisconnectCallAndCleanup(ongoingCall, CallState.DISCONNECTED);
        assertFalse(mCallsManager.getPendingAccountSelection().containsKey(ongoingCall.getId()));
        assertTrue(mCallsManager.getPendingAccountSelection().containsKey(pendingCall.getId()));
    }

    private Call addSpyCall() {
        return addSpyCall(SIM_2_HANDLE, CallState.ACTIVE);