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

Commit b3425963 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DSDA: Pending account selection multi-call aware" into main

parents 94df0e5e 80914bce
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
@@ -859,6 +862,7 @@ public class CallsManager extends Call.ListenerBase
        mCallAnomalyWatchdog = callAnomalyWatchdog;
        mAsyncTaskExecutor = asyncTaskExecutor;
        mUserManager = mContext.getSystemService(UserManager.class);
        mPendingAccountSelection = new HashMap<>();
    }

    public void setIncomingCallNotifier(IncomingCallNotifier incomingCallNotifier) {
@@ -2428,11 +2432,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.
@@ -3594,10 +3599,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.
@@ -3992,9 +3999,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);
            }
        }
    }
@@ -7182,4 +7190,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);