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

Commit babfe155 authored by Tyler Gunn's avatar Tyler Gunn Committed by Android (Google) Code Review
Browse files

Merge "Multi-endpoint changes." into nyc-mr1-dev

parents bc0f1d16 67f3535d
Loading
Loading
Loading
Loading
+49 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.telephony.imsphone;
import com.android.ims.ImsCallProfile;
import com.android.ims.ImsExternalCallState;
import com.android.ims.ImsExternalCallStateListener;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.Phone;
@@ -38,6 +39,29 @@ import java.util.Map;
 */
public class ImsExternalCallTracker {

    /**
     * Interface implemented by modules which are capable of notifying interested parties of new
     * unknown connections, and changes to call state.
     * This is used to break the dependency between {@link ImsExternalCallTracker} and
     * {@link ImsPhone}.
     *
     * @hide
     */

    public static interface ImsCallNotify {
        /**
         * Notifies that an unknown connection has been added.
         * @param c The new unknown connection.
         */
        void notifyUnknownConnection(Connection c);

        /**
         * Notifies of a change to call state.
         */
        void notifyPreciseCallStateChanged();
    }


    /**
     * Implements the {@link ImsExternalCallStateListener}, which is responsible for receiving
     * external call state updates from the IMS framework.
@@ -80,13 +104,35 @@ public class ImsExternalCallTracker {
    private Map<Integer, ImsExternalConnection> mExternalConnections =
            new ArrayMap<>();
    private final ImsPhone mPhone;
    private final ImsCallNotify mCallStateNotifier;
    private final ExternalCallStateListener mExternalCallStateListener;
    private final ExternalConnectionListener mExternalConnectionListener =
            new ExternalConnectionListener();
    private final ImsPullCall mCallPuller;

    @VisibleForTesting
    public ImsExternalCallTracker(ImsPhone phone, ImsPullCall callPuller,
            ImsCallNotify callNotifier) {

        mPhone = phone;
        mCallStateNotifier = callNotifier;
        mExternalCallStateListener = new ExternalCallStateListener();
        mCallPuller = callPuller;

    }
    public ImsExternalCallTracker(ImsPhone phone, ImsPullCall callPuller) {
        mPhone = phone;
        mCallStateNotifier = new ImsCallNotify() {
            @Override
            public void notifyUnknownConnection(Connection c) {
                mPhone.notifyUnknownConnection(c);
            }

            @Override
            public void notifyPreciseCallStateChanged() {
                mPhone.notifyPreciseCallStateChanged();
            }
        };
        mExternalCallStateListener = new ExternalCallStateListener();
        mCallPuller = callPuller;
    }
@@ -126,7 +172,7 @@ public class ImsExternalCallTracker {
        // If one or more calls were removed, trigger a notification that will cause the
        // TelephonyConnection instancse to refresh their state with Telecom.
        if (wasCallRemoved) {
            mPhone.notifyPreciseCallStateChanged();
            mCallStateNotifier.notifyPreciseCallStateChanged();
        }

        // Check for new calls, and updates to existing ones.
@@ -182,7 +228,7 @@ public class ImsExternalCallTracker {
        // PstnIncomingCallNotifier#addNewUnknownCall.  That method will ensure that an extra is set
        // containing the ImsExternalConnection#mCallId so that we have a means of reconciling which
        // unknown call was added.
        mPhone.notifyUnknownConnection(connection);
        mCallStateNotifier.notifyUnknownConnection(connection);
    }

    /**
@@ -205,7 +251,7 @@ public class ImsExternalCallTracker {
                connection.setTerminated();
                connection.removeListener(mExternalConnectionListener);
                mExternalConnections.remove(connection);
                mPhone.notifyPreciseCallStateChanged();
                mCallStateNotifier.notifyPreciseCallStateChanged();
            }
        }

+5 −0
Original line number Diff line number Diff line
@@ -511,6 +511,11 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                    );
                }

                if (intentExtras.containsKey(ImsCallProfile.EXTRA_IS_CALL_PULL)) {
                    profile.mCallExtras.putBoolean(ImsCallProfile.EXTRA_IS_CALL_PULL,
                            intentExtras.getBoolean(ImsCallProfile.EXTRA_IS_CALL_PULL));
                }

                // Pack the OEM-specific call extras.
                profile.mCallExtras.putBundle(ImsCallProfile.EXTRA_OEM_EXTRAS, intentExtras);

+106 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.internal.telephony.imsphone;

import com.android.ims.ImsCallProfile;
import com.android.ims.ImsExternalCallState;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.Connection;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import android.net.Uri;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

/**
 * Unit tests for the {@link ImsExternalCallTracker}.
 */
public class ImsExternalCallTrackerTest {
    private static final Uri TEST_ADDRESS = Uri.parse("tel:6505551212");
    private static final int CALL_ID = 1;

    ImsExternalCallTracker mTracker;
    @Mock
    ImsPhone mImsPhone;
    @Mock
    ImsPullCall mImsPullCall;
    @Mock
    ImsExternalCallTracker.ImsCallNotify mCallNotifier;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);

        mTracker = new ImsExternalCallTracker(mImsPhone, mImsPullCall, mCallNotifier);
    }

    @Test
    public void testAddExternalCall() {
        List<ImsExternalCallState> dep = new ArrayList<>();
        dep.add(
                new ImsExternalCallState(CALL_ID,
                        TEST_ADDRESS,
                        false /* isPullable */,
                        ImsExternalCallState.CALL_STATE_CONFIRMED,
                        ImsCallProfile.CALL_TYPE_VOICE,
                        false /* isHeld */));

        mTracker.refreshExternalCallState(dep);

        ArgumentCaptor<Connection> connectionArgumentCaptor = ArgumentCaptor.forClass(
                Connection.class);
        verify(mCallNotifier).notifyUnknownConnection(connectionArgumentCaptor.capture());


        Connection connection = connectionArgumentCaptor.getValue();
        assert(connection instanceof ImsExternalConnection);
    }

    @Test
    public void testRemoveExternalCall() {
        testAddExternalCall();

        ImsExternalConnection connection = (ImsExternalConnection)
                mTracker.getConnectionById(CALL_ID);

        List<ImsExternalCallState> dep = new ArrayList<>();
        mTracker.refreshExternalCallState(dep);
        verify(mCallNotifier).notifyPreciseCallStateChanged();
        assertEquals(connection.getState(), Call.State.DISCONNECTED);
        assertNull(mTracker.getConnectionById(CALL_ID));
    }
}