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

Commit 7db91bdb authored by Grant Menke's avatar Grant Menke Committed by Android (Google) Code Review
Browse files

Merge "Notify listeners when call is aborted with no phone accounts." into udc-dev

parents 57211dab 94c42c74
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -285,6 +285,10 @@ public class CallsManager extends Call.ListenerBase
    public static final String EMERGENCY_CALL_DISCONNECTED_BEFORE_BEING_ADDED_ERROR_MSG =
            "An emergency call was disconnected after the connection was created but before the "
                    + "call was successfully added to CallsManager.";
    public static final UUID EMERGENCY_CALL_ABORTED_NO_PHONE_ACCOUNTS_ERROR_UUID =
            UUID.fromString("2e994acb-1997-4345-8bf3-bad04303de26");
    public static final String EMERGENCY_CALL_ABORTED_NO_PHONE_ACCOUNTS_ERROR_MSG =
            "An emergency call was aborted since there were no available phone accounts.";

    private static final int[] OUTGOING_CALL_STATES =
            {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING,
@@ -1950,6 +1954,12 @@ public class CallsManager extends Call.ListenerBase
                                Log.i(CallsManager.this, "Aborting call since there are no"
                                        + " available accounts.");
                                showErrorMessage(R.string.cant_call_due_to_no_supported_service);
                                mListeners.forEach(l -> l.onCallCreatedButNeverAdded(callToPlace));
                                if (callToPlace.isEmergencyCall()){
                                    mAnomalyReporter.reportAnomaly(
                                            EMERGENCY_CALL_ABORTED_NO_PHONE_ACCOUNTS_ERROR_UUID,
                                            EMERGENCY_CALL_ABORTED_NO_PHONE_ACCOUNTS_ERROR_MSG);
                                }
                                return CompletableFuture.completedFuture(null);
                            }
                            boolean needsAccountSelection = accountSuggestions.size() > 1
+31 −0
Original line number Diff line number Diff line
@@ -2041,6 +2041,37 @@ public class CallsManagerTest extends TelecomTestCase {
        verify(listener, never()).onCallCreatedButNeverAdded(incomingCall);
    }

    /**
     * Emulate the case where a new outgoing call is created but is aborted before being added to
     * CallsManager since there are no available phone accounts. In this case, the listeners
     * should be notified properly.
     */
    @Test
    public void testAbortOutgoingCallNoPhoneAccountsNotifyListeners() throws Exception {
        // Setup a new outgoing call and add a listener
        Call newCall = addSpyCall(CallState.NEW);
        CallsManager.CallsManagerListener listener = mock(CallsManager.CallsManagerListener.class);
        mCallsManager.addListener(listener);

        // Ensure contact info lookup succeeds but do not set the phone account info
        doAnswer(invocation -> {
            Uri handle = invocation.getArgument(0);
            CallerInfo info = new CallerInfo();
            CompletableFuture<Pair<Uri, CallerInfo>> callerInfoFuture = new CompletableFuture<>();
            callerInfoFuture.complete(new Pair<>(handle, info));
            return callerInfoFuture;
        }).when(mCallerInfoLookupHelper).startLookup(any(Uri.class));

        // Start the outgoing call
        CompletableFuture<Call> callFuture = mCallsManager.startOutgoingCall(
                newCall.getHandle(), newCall.getTargetPhoneAccount(), new Bundle(),
                UserHandle.CURRENT, new Intent(), "com.test.stuff");
        Call result = callFuture.get(TEST_TIMEOUT, TimeUnit.MILLISECONDS);

        //Ensure the listener is notified properly:
        verify(listener).onCallCreatedButNeverAdded(any());
        assertNull(result);
    }

    @Test
    public void testIsInSelfManagedCallOnlySelfManaged() {