Conference.java revision 6714030083b1d8ec5b2df6dfef08034d0d30c2fe
1823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon/*
2823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * Copyright (C) 2014 The Android Open Source Project
3823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon *
4823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * Licensed under the Apache License, Version 2.0 (the "License");
5823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * you may not use this file except in compliance with the License.
6823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * You may obtain a copy of the License at
7823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon *
8823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon *      http://www.apache.org/licenses/LICENSE-2.0
9823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon *
10823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * Unless required by applicable law or agreed to in writing, software
11823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * distributed under the License is distributed on an "AS IS" BASIS,
12823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * See the License for the specific language governing permissions and
14823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * limitations under the License.
15823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon */
16823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
17ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnpackage android.telecom;
18823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
196b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordonimport android.annotation.Nullable;
205d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordonimport android.annotation.SystemApi;
216b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordonimport android.os.Bundle;
2207366813cdf3768dcd69a1f744023747564d654aRekha Kumarimport android.telecom.Connection.VideoProvider;
230e094d926c306c3667bcdf6f23c52cc7181f25f3Evan Charlton
2450e3506533478fa273cbc92c2919470d1889f1edIhab Awadimport java.util.ArrayList;
25823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordonimport java.util.Collections;
26823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordonimport java.util.List;
2707366813cdf3768dcd69a1f744023747564d654aRekha Kumarimport java.util.Locale;
28823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordonimport java.util.Set;
29823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordonimport java.util.concurrent.CopyOnWriteArrayList;
30823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordonimport java.util.concurrent.CopyOnWriteArraySet;
31823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
32823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon/**
33823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon * Represents a conference call which can contain any number of {@link Connection} objects.
34823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon */
35abfcfdc0444c48dd161e425c8417dab87de1cb69Yorke Leepublic abstract class Conference extends Conferenceable {
36823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
37cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn    /**
38cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     * Used to indicate that the conference connection time is not specified.  If not specified,
39cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     * Telecom will set the connect time.
40cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     */
41164a0acf53a3496c974a97ed35834e6195c14e4bJay Shrauner    public static final long CONNECT_TIME_NOT_SPECIFIED = 0;
42cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn
43823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /** @hide */
44823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public abstract static class Listener {
45823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        public void onStateChanged(Conference conference, int oldState, int newState) {}
467f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee        public void onDisconnected(Conference conference, DisconnectCause disconnectCause) {}
47823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        public void onConnectionAdded(Conference conference, Connection connection) {}
48823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        public void onConnectionRemoved(Conference conference, Connection connection) {}
4950e3506533478fa273cbc92c2919470d1889f1edIhab Awad        public void onConferenceableConnectionsChanged(
5050e3506533478fa273cbc92c2919470d1889f1edIhab Awad                Conference conference, List<Connection> conferenceableConnections) {}
51823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        public void onDestroyed(Conference conference) {}
525c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        public void onConnectionCapabilitiesChanged(
535c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad                Conference conference, int connectionCapabilities) {}
5407366813cdf3768dcd69a1f744023747564d654aRekha Kumar        public void onVideoStateChanged(Conference c, int videoState) { }
5507366813cdf3768dcd69a1f744023747564d654aRekha Kumar        public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) {}
56edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee        public void onStatusHintsChanged(Conference conference, StatusHints statusHints) {}
576b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        public void onExtrasChanged(Conference conference, Bundle extras) {}
58823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
59823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
60823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
61823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
62b8e85c74e5910a461078704048d67f82b216508cIhab Awad    private final List<Connection> mUnmodifiableChildConnections =
63823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            Collections.unmodifiableList(mChildConnections);
6450e3506533478fa273cbc92c2919470d1889f1edIhab Awad    private final List<Connection> mConferenceableConnections = new ArrayList<>();
6550e3506533478fa273cbc92c2919470d1889f1edIhab Awad    private final List<Connection> mUnmodifiableConferenceableConnections =
6650e3506533478fa273cbc92c2919470d1889f1edIhab Awad            Collections.unmodifiableList(mConferenceableConnections);
67823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
686714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu    private String mTelecomCallId;
69164a0acf53a3496c974a97ed35834e6195c14e4bJay Shrauner    private PhoneAccountHandle mPhoneAccount;
704af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    private CallAudioState mCallAudioState;
71823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private int mState = Connection.STATE_NEW;
727f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee    private DisconnectCause mDisconnectCause;
735c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    private int mConnectionCapabilities;
74823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private String mDisconnectMessage;
75cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn    private long mConnectTimeMillis = CONNECT_TIME_NOT_SPECIFIED;
76edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee    private StatusHints mStatusHints;
776b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    private Bundle mExtras;
78823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
7950e3506533478fa273cbc92c2919470d1889f1edIhab Awad    private final Connection.Listener mConnectionDeathListener = new Connection.Listener() {
8050e3506533478fa273cbc92c2919470d1889f1edIhab Awad        @Override
8150e3506533478fa273cbc92c2919470d1889f1edIhab Awad        public void onDestroyed(Connection c) {
8250e3506533478fa273cbc92c2919470d1889f1edIhab Awad            if (mConferenceableConnections.remove(c)) {
8350e3506533478fa273cbc92c2919470d1889f1edIhab Awad                fireOnConferenceableConnectionsChanged();
8450e3506533478fa273cbc92c2919470d1889f1edIhab Awad            }
8550e3506533478fa273cbc92c2919470d1889f1edIhab Awad        }
8650e3506533478fa273cbc92c2919470d1889f1edIhab Awad    };
8750e3506533478fa273cbc92c2919470d1889f1edIhab Awad
8856fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen    /**
8956fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * Constructs a new Conference with a mandatory {@link PhoneAccountHandle}
9056fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     *
9156fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * @param phoneAccount The {@code PhoneAccountHandle} associated with the conference.
9256fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     */
93823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public Conference(PhoneAccountHandle phoneAccount) {
94823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        mPhoneAccount = phoneAccount;
95823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
96823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
9756fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen    /**
986714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     * Returns the telecom internal call ID associated with this conference.
996714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     *
1006714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     * @return The telecom call ID.
1016714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     * @hide
1026714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     */
1036714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu    public final String getTelecomCallId() {
1046714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu        return mTelecomCallId;
1056714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu    }
1066714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu
1076714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu    /**
1086714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     * Sets the telecom internal call ID associated with this conference.
1096714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     *
1106714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     * @param telecomCallId The telecom call ID.
1116714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     * @hide
1126714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu     */
1136714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu    public final void setTelecomCallId(String telecomCallId) {
1146714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu        mTelecomCallId = telecomCallId;
1156714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu    }
1166714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu
1176714030083b1d8ec5b2df6dfef08034d0d30c2feJack Yu    /**
11856fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * Returns the {@link PhoneAccountHandle} the conference call is being placed through.
11956fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     *
12056fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * @return A {@code PhoneAccountHandle} object representing the PhoneAccount of the conference.
12156fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     */
122ea38cca14964a5ee658899b0bafbc48017d556cdNancy Chen    public final PhoneAccountHandle getPhoneAccountHandle() {
123823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        return mPhoneAccount;
124823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
125823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
12656fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen    /**
12756fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * Returns the list of connections currently associated with the conference call.
12856fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     *
12956fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * @return A list of {@code Connection} objects which represent the children of the conference.
13056fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     */
131823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final List<Connection> getConnections() {
132b8e85c74e5910a461078704048d67f82b216508cIhab Awad        return mUnmodifiableChildConnections;
133823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
134823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
13556fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen    /**
13656fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * Gets the state of the conference call. See {@link Connection} for valid values.
13756fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     *
13856fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     * @return A constant representing the state the conference call is currently in.
13956fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     */
140823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final int getState() {
141823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        return mState;
142823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
143823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
1445c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1455d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * Returns the capabilities of the conference. See {@code CAPABILITY_*} constants in class
1465c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * {@link Connection} for valid values.
1475c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
1485c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return A bitmask of the capabilities of the conference call.
1495c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1505c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public final int getConnectionCapabilities() {
1515c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        return mConnectionCapabilities;
1525c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
1535c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1545c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1555c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Whether the given capabilities support the specified capability.
1565c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
1575c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capabilities A capability bit field.
1585c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to check capabilities for.
1595c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return Whether the specified capability is supported.
1605c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
1615c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1625c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static boolean can(int capabilities, int capability) {
1635c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        return (capabilities & capability) != 0;
1645c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
1655c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
16656fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen    /**
1675c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Whether the capabilities of this {@code Connection} supports the specified capability.
16856fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     *
1695c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to check capabilities for.
1705c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return Whether the specified capability is supported.
1715c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
17256fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     */
1735c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public boolean can(int capability) {
1745c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        return can(mConnectionCapabilities, capability);
1755c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
1765c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1775c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1785c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Removes the specified capability from the set of capabilities of this {@code Conference}.
1795c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
1805c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to remove from the set.
1815c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
1825c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1835c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public void removeCapability(int capability) {
1845c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        mConnectionCapabilities &= ~capability;
1855c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
1865c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1875c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1885c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Adds the specified capability to the set of capabilities of this {@code Conference}.
1895c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
1905c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to add to the set.
1915c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
1925c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1935c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public void addCapability(int capability) {
1945c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        mConnectionCapabilities |= capability;
195823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
196823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
197823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
198a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * @return The audio state of the conference, describing how its audio is currently
199a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     *         being routed by the system. This is {@code null} if this Conference
200a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     *         does not directly know about its audio state.
2014af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @deprecated Use {@link #getCallAudioState()} instead.
2024af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @hide
203a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     */
2044af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @Deprecated
2054af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @SystemApi
206a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    public final AudioState getAudioState() {
2074af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        return new AudioState(mCallAudioState);
2084af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    }
2094af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee
2104af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    /**
2114af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @return The audio state of the conference, describing how its audio is currently
2124af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     *         being routed by the system. This is {@code null} if this Conference
2134af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     *         does not directly know about its audio state.
2144af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     */
2154af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    public final CallAudioState getCallAudioState() {
2164af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        return mCallAudioState;
217a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    }
218a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee
219a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    /**
22007366813cdf3768dcd69a1f744023747564d654aRekha Kumar     * Returns VideoProvider of the primary call. This can be null.
22107366813cdf3768dcd69a1f744023747564d654aRekha Kumar     */
22207366813cdf3768dcd69a1f744023747564d654aRekha Kumar    public VideoProvider getVideoProvider() {
22307366813cdf3768dcd69a1f744023747564d654aRekha Kumar        return null;
22407366813cdf3768dcd69a1f744023747564d654aRekha Kumar    }
22507366813cdf3768dcd69a1f744023747564d654aRekha Kumar
22607366813cdf3768dcd69a1f744023747564d654aRekha Kumar    /**
22707366813cdf3768dcd69a1f744023747564d654aRekha Kumar     * Returns video state of the primary call.
22807366813cdf3768dcd69a1f744023747564d654aRekha Kumar     */
22907366813cdf3768dcd69a1f744023747564d654aRekha Kumar    public int getVideoState() {
23087b73f370e2b8a76b0540580f43edba6ec21c6cfTyler Gunn        return VideoProfile.STATE_AUDIO_ONLY;
23107366813cdf3768dcd69a1f744023747564d654aRekha Kumar    }
23207366813cdf3768dcd69a1f744023747564d654aRekha Kumar
23307366813cdf3768dcd69a1f744023747564d654aRekha Kumar    /**
234823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
235823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
236823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public void onDisconnect() {}
237823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
238823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
239823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Invoked when the specified {@link Connection} should be separated from the conference call.
240823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *
241823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @param connection The connection to separate.
242823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
243823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public void onSeparate(Connection connection) {}
244823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
245823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
24650e3506533478fa273cbc92c2919470d1889f1edIhab Awad     * Invoked when the specified {@link Connection} should merged with the conference call.
24750e3506533478fa273cbc92c2919470d1889f1edIhab Awad     *
24850e3506533478fa273cbc92c2919470d1889f1edIhab Awad     * @param connection The {@code Connection} to merge.
24950e3506533478fa273cbc92c2919470d1889f1edIhab Awad     */
25050e3506533478fa273cbc92c2919470d1889f1edIhab Awad    public void onMerge(Connection connection) {}
25150e3506533478fa273cbc92c2919470d1889f1edIhab Awad
25250e3506533478fa273cbc92c2919470d1889f1edIhab Awad    /**
253823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Invoked when the conference should be put on hold.
254823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
255823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public void onHold() {}
256823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
257823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
258823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Invoked when the conference should be moved from hold to active.
259823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
260823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public void onUnhold() {}
261823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
262823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
263a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon     * Invoked when the child calls should be merged. Only invoked if the conference contains the
2645c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * capability {@link Connection#CAPABILITY_MERGE_CONFERENCE}.
265a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon     */
266a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon    public void onMerge() {}
267a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon
268a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon    /**
269a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon     * Invoked when the child calls should be swapped. Only invoked if the conference contains the
2705c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * capability {@link Connection#CAPABILITY_SWAP_CONFERENCE}.
271a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon     */
272a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon    public void onSwap() {}
273a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon
274a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon    /**
275a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * Notifies this conference of a request to play a DTMF tone.
276a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     *
277a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * @param c A DTMF character.
278a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     */
279a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    public void onPlayDtmfTone(char c) {}
280a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee
281a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    /**
282a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * Notifies this conference of a request to stop any currently playing DTMF tones.
283a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     */
284a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    public void onStopDtmfTone() {}
285a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee
286a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    /**
287a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * Notifies this conference that the {@link #getAudioState()} property has a new value.
288a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     *
289a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * @param state The new call audio state.
2904af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
2914af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @hide
292a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     */
2934af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @SystemApi
2944af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @Deprecated
295a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    public void onAudioStateChanged(AudioState state) {}
296a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee
297a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    /**
2984af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * Notifies this conference that the {@link #getCallAudioState()} property has a new value.
2994af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     *
3004af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @param state The new call audio state.
3014af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     */
3024af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    public void onCallAudioStateChanged(CallAudioState state) {}
3034af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee
3044af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    /**
30546f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee     * Notifies this conference that a connection has been added to it.
30646f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee     *
30746f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee     * @param connection The newly added connection.
30846f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee     */
30946f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee    public void onConnectionAdded(Connection connection) {}
31046f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee
31146f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee    /**
312823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Sets state to be on hold.
313823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
314823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final void setOnHold() {
315823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        setState(Connection.STATE_HOLDING);
316823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
317823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
318823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
319d46595a673eba0df624d9d92b6f981e3483e0d20Tyler Gunn     * Sets state to be dialing.
320d46595a673eba0df624d9d92b6f981e3483e0d20Tyler Gunn     */
321d46595a673eba0df624d9d92b6f981e3483e0d20Tyler Gunn    public final void setDialing() {
322d46595a673eba0df624d9d92b6f981e3483e0d20Tyler Gunn        setState(Connection.STATE_DIALING);
323d46595a673eba0df624d9d92b6f981e3483e0d20Tyler Gunn    }
324d46595a673eba0df624d9d92b6f981e3483e0d20Tyler Gunn
325d46595a673eba0df624d9d92b6f981e3483e0d20Tyler Gunn    /**
326823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Sets state to be active.
327823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
328823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final void setActive() {
329823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        setState(Connection.STATE_ACTIVE);
330823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
331823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
332823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
333823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Sets state to disconnected.
334823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *
3357f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     * @param disconnectCause The reason for the disconnection, as described by
3367f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     *     {@link android.telecom.DisconnectCause}.
337823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
3387f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee    public final void setDisconnected(DisconnectCause disconnectCause) {
3397f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee        mDisconnectCause = disconnectCause;;
340823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        setState(Connection.STATE_DISCONNECTED);
341823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        for (Listener l : mListeners) {
3427f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee            l.onDisconnected(this, mDisconnectCause);
343823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
344823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
345823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
346823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
3471cf14ac5dc5708fc31e6c987a5c7db465ff95533mike dooley     * @return The {@link DisconnectCause} for this connection.
3481cf14ac5dc5708fc31e6c987a5c7db465ff95533mike dooley     */
3491cf14ac5dc5708fc31e6c987a5c7db465ff95533mike dooley    public final DisconnectCause getDisconnectCause() {
3501cf14ac5dc5708fc31e6c987a5c7db465ff95533mike dooley        return mDisconnectCause;
3511cf14ac5dc5708fc31e6c987a5c7db465ff95533mike dooley    }
3521cf14ac5dc5708fc31e6c987a5c7db465ff95533mike dooley
3531cf14ac5dc5708fc31e6c987a5c7db465ff95533mike dooley    /**
3545c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Sets the capabilities of a conference. See {@code CAPABILITY_*} constants of class
3555c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * {@link Connection} for valid values.
35656fc25deec15a32ea5f37d7c8c82f16d1bf9d275Nancy Chen     *
3575c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param connectionCapabilities A bitmask of the {@code PhoneCapabilities} of the conference call.
358823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
3595c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public final void setConnectionCapabilities(int connectionCapabilities) {
3605c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (connectionCapabilities != mConnectionCapabilities) {
3615c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            mConnectionCapabilities = connectionCapabilities;
362823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
363823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            for (Listener l : mListeners) {
3645c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad                l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
365823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            }
366823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
367823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
368823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
369823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
370823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Adds the specified connection as a child of this conference.
371823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *
372823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @param connection The connection to add.
373823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @return True if the connection was successfully added.
374823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
375a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon    public final boolean addConnection(Connection connection) {
37607366813cdf3768dcd69a1f744023747564d654aRekha Kumar        Log.d(this, "Connection=%s, connection=", connection);
377823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (connection != null && !mChildConnections.contains(connection)) {
378823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            if (connection.setConference(this)) {
379823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                mChildConnections.add(connection);
38046f7f5dce42d645353a0f3eb0dbdd25b3a6c72fbAndrew Lee                onConnectionAdded(connection);
381823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                for (Listener l : mListeners) {
382823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                    l.onConnectionAdded(this, connection);
383823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                }
384823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                return true;
385823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            }
386823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
387823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        return false;
388823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
389823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
390823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
391823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Removes the specified connection as a child of this conference.
392823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *
393823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @param connection The connection to remove.
394823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
395a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon    public final void removeConnection(Connection connection) {
3960159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon        Log.d(this, "removing %s from %s", connection, mChildConnections);
397823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (connection != null && mChildConnections.remove(connection)) {
398823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            connection.resetConference();
399823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            for (Listener l : mListeners) {
400823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                l.onConnectionRemoved(this, connection);
401823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            }
402823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
403823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
404823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
405823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
40650e3506533478fa273cbc92c2919470d1889f1edIhab Awad     * Sets the connections with which this connection can be conferenced.
40750e3506533478fa273cbc92c2919470d1889f1edIhab Awad     *
40850e3506533478fa273cbc92c2919470d1889f1edIhab Awad     * @param conferenceableConnections The set of connections this connection can conference with.
40950e3506533478fa273cbc92c2919470d1889f1edIhab Awad     */
41050e3506533478fa273cbc92c2919470d1889f1edIhab Awad    public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
41150e3506533478fa273cbc92c2919470d1889f1edIhab Awad        clearConferenceableList();
41250e3506533478fa273cbc92c2919470d1889f1edIhab Awad        for (Connection c : conferenceableConnections) {
41350e3506533478fa273cbc92c2919470d1889f1edIhab Awad            // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
41450e3506533478fa273cbc92c2919470d1889f1edIhab Awad            // small amount of items here.
41550e3506533478fa273cbc92c2919470d1889f1edIhab Awad            if (!mConferenceableConnections.contains(c)) {
41650e3506533478fa273cbc92c2919470d1889f1edIhab Awad                c.addConnectionListener(mConnectionDeathListener);
41750e3506533478fa273cbc92c2919470d1889f1edIhab Awad                mConferenceableConnections.add(c);
41850e3506533478fa273cbc92c2919470d1889f1edIhab Awad            }
41950e3506533478fa273cbc92c2919470d1889f1edIhab Awad        }
42050e3506533478fa273cbc92c2919470d1889f1edIhab Awad        fireOnConferenceableConnectionsChanged();
42150e3506533478fa273cbc92c2919470d1889f1edIhab Awad    }
42250e3506533478fa273cbc92c2919470d1889f1edIhab Awad
42307366813cdf3768dcd69a1f744023747564d654aRekha Kumar    /**
42407366813cdf3768dcd69a1f744023747564d654aRekha Kumar     * Set the video state for the conference.
42532f24731604fd81289a39619bbc925b65184b505Yorke Lee     * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
42632f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_BIDIRECTIONAL},
42732f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_TX_ENABLED},
42832f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_RX_ENABLED}.
42907366813cdf3768dcd69a1f744023747564d654aRekha Kumar     *
43007366813cdf3768dcd69a1f744023747564d654aRekha Kumar     * @param videoState The new video state.
43107366813cdf3768dcd69a1f744023747564d654aRekha Kumar     */
43207366813cdf3768dcd69a1f744023747564d654aRekha Kumar    public final void setVideoState(Connection c, int videoState) {
43307366813cdf3768dcd69a1f744023747564d654aRekha Kumar        Log.d(this, "setVideoState Conference: %s Connection: %s VideoState: %s",
43407366813cdf3768dcd69a1f744023747564d654aRekha Kumar                this, c, videoState);
43507366813cdf3768dcd69a1f744023747564d654aRekha Kumar        for (Listener l : mListeners) {
43607366813cdf3768dcd69a1f744023747564d654aRekha Kumar            l.onVideoStateChanged(this, videoState);
43707366813cdf3768dcd69a1f744023747564d654aRekha Kumar        }
43807366813cdf3768dcd69a1f744023747564d654aRekha Kumar    }
43907366813cdf3768dcd69a1f744023747564d654aRekha Kumar
44007366813cdf3768dcd69a1f744023747564d654aRekha Kumar    /**
44107366813cdf3768dcd69a1f744023747564d654aRekha Kumar     * Sets the video connection provider.
44207366813cdf3768dcd69a1f744023747564d654aRekha Kumar     *
44307366813cdf3768dcd69a1f744023747564d654aRekha Kumar     * @param videoProvider The video provider.
44407366813cdf3768dcd69a1f744023747564d654aRekha Kumar     */
44507366813cdf3768dcd69a1f744023747564d654aRekha Kumar    public final void setVideoProvider(Connection c, Connection.VideoProvider videoProvider) {
44607366813cdf3768dcd69a1f744023747564d654aRekha Kumar        Log.d(this, "setVideoProvider Conference: %s Connection: %s VideoState: %s",
44707366813cdf3768dcd69a1f744023747564d654aRekha Kumar                this, c, videoProvider);
44807366813cdf3768dcd69a1f744023747564d654aRekha Kumar        for (Listener l : mListeners) {
44907366813cdf3768dcd69a1f744023747564d654aRekha Kumar            l.onVideoProviderChanged(this, videoProvider);
45007366813cdf3768dcd69a1f744023747564d654aRekha Kumar        }
45107366813cdf3768dcd69a1f744023747564d654aRekha Kumar    }
45207366813cdf3768dcd69a1f744023747564d654aRekha Kumar
45350e3506533478fa273cbc92c2919470d1889f1edIhab Awad    private final void fireOnConferenceableConnectionsChanged() {
45450e3506533478fa273cbc92c2919470d1889f1edIhab Awad        for (Listener l : mListeners) {
45550e3506533478fa273cbc92c2919470d1889f1edIhab Awad            l.onConferenceableConnectionsChanged(this, getConferenceableConnections());
45650e3506533478fa273cbc92c2919470d1889f1edIhab Awad        }
45750e3506533478fa273cbc92c2919470d1889f1edIhab Awad    }
45850e3506533478fa273cbc92c2919470d1889f1edIhab Awad
45950e3506533478fa273cbc92c2919470d1889f1edIhab Awad    /**
46050e3506533478fa273cbc92c2919470d1889f1edIhab Awad     * Returns the connections with which this connection can be conferenced.
46150e3506533478fa273cbc92c2919470d1889f1edIhab Awad     */
46250e3506533478fa273cbc92c2919470d1889f1edIhab Awad    public final List<Connection> getConferenceableConnections() {
46350e3506533478fa273cbc92c2919470d1889f1edIhab Awad        return mUnmodifiableConferenceableConnections;
46450e3506533478fa273cbc92c2919470d1889f1edIhab Awad    }
46550e3506533478fa273cbc92c2919470d1889f1edIhab Awad
46650e3506533478fa273cbc92c2919470d1889f1edIhab Awad    /**
467ea38cca14964a5ee658899b0bafbc48017d556cdNancy Chen     * Tears down the conference object and any of its current connections.
468823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
469a48680427e022ab6eb73277faac6c57831ee6ff9Santos Cordon    public final void destroy() {
470823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        Log.d(this, "destroying conference : %s", this);
471823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        // Tear down the children.
4720159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon        for (Connection connection : mChildConnections) {
473823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            Log.d(this, "removing connection %s", connection);
474823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            removeConnection(connection);
475823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
476823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
477823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        // If not yet disconnected, set the conference call as disconnected first.
478823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (mState != Connection.STATE_DISCONNECTED) {
479823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            Log.d(this, "setting to disconnected");
4807f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee            setDisconnected(new DisconnectCause(DisconnectCause.LOCAL));
481823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
482823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
483823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        // ...and notify.
484823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        for (Listener l : mListeners) {
485823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            l.onDestroyed(this);
486823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
487823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
488823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
489823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
490823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Add a listener to be notified of a state change.
491823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *
492823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @param listener The new listener.
493823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @return This conference.
494823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @hide
495823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
496823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final Conference addListener(Listener listener) {
497823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        mListeners.add(listener);
498823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        return this;
499823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
500823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
501823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
502823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Removes the specified listener.
503823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *
504823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @param listener The listener to remove.
505823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @return This conference.
506823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @hide
507823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
508823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final Conference removeListener(Listener listener) {
509823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        mListeners.remove(listener);
510823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        return this;
511823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
512823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
513a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    /**
5144a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     * Retrieves the primary connection associated with the conference.  The primary connection is
5154a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     * the connection from which the conference will retrieve its current state.
5164a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     *
5174a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     * @return The primary connection.
5185d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * @hide
5194a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     */
5205d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    @SystemApi
5214055d648993c35be19487f7ab82e337197e25297Santos Cordon    public Connection getPrimaryConnection() {
5224a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn        if (mUnmodifiableChildConnections == null || mUnmodifiableChildConnections.isEmpty()) {
5234a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn            return null;
5244a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn        }
5254a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn        return mUnmodifiableChildConnections.get(0);
5264a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn    }
5274a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn
5284a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn    /**
5295d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * @hide
5305d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * @deprecated Use {@link #setConnectionTime}.
5315d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     */
5325d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    @Deprecated
5335d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    @SystemApi
5345d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    public final void setConnectTimeMillis(long connectTimeMillis) {
5355d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon        setConnectionTime(connectTimeMillis);
5365d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    }
5375d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon
5385d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    /**
5395d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * Sets the connection start time of the {@code Conference}.
540cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     *
5415d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * @param connectionTimeMillis The connection time, in milliseconds.
542cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     */
5435d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    public final void setConnectionTime(long connectionTimeMillis) {
5445d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon        mConnectTimeMillis = connectionTimeMillis;
545cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn    }
546cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn
547cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn    /**
5485d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * @hide
5495d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * @deprecated Use {@link #getConnectionTime}.
5505d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     */
5515d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    @Deprecated
5525d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    @SystemApi
5535d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    public final long getConnectTimeMillis() {
5545d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon        return getConnectionTime();
5555d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    }
5565d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon
5575d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    /**
5585d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * Retrieves the connection start time of the {@code Conference}, if specified.  A value of
559cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     * {@link #CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the start time
560cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     * of the conference.
561cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     *
5625d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon     * @return The time at which the {@code Conference} was connected.
563cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn     */
5645d2e4f20fee033a22fbadffb291c4e47f35b7633Santos Cordon    public final long getConnectionTime() {
565cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn        return mConnectTimeMillis;
566cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn    }
567cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn
568cd5d33c89f25b3bfe8989d55f05702d0970c13b4Tyler Gunn    /**
569a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * Inform this Conference that the state of its audio output has been changed externally.
570a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     *
571a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * @param state The new audio state.
572a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     * @hide
573a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee     */
5744af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    final void setCallAudioState(CallAudioState state) {
5754af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        Log.d(this, "setCallAudioState %s", state);
5764af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        mCallAudioState = state;
5774af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        onAudioStateChanged(getAudioState());
5784af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        onCallAudioStateChanged(state);
579a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee    }
580a0d3ca9746143d669fe9384babb9e1b9fca33dcfYorke Lee
581823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private void setState(int newState) {
582823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (newState != Connection.STATE_ACTIVE &&
583823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                newState != Connection.STATE_HOLDING &&
584823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                newState != Connection.STATE_DISCONNECTED) {
585823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            Log.w(this, "Unsupported state transition for Conference call.",
586823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                    Connection.stateToString(newState));
587823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            return;
588823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
589823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
590823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (mState != newState) {
591823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            int oldState = mState;
592823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            mState = newState;
593823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            for (Listener l : mListeners) {
594823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                l.onStateChanged(this, oldState, newState);
595823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            }
596823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
597823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
59850e3506533478fa273cbc92c2919470d1889f1edIhab Awad
59950e3506533478fa273cbc92c2919470d1889f1edIhab Awad    private final void clearConferenceableList() {
60050e3506533478fa273cbc92c2919470d1889f1edIhab Awad        for (Connection c : mConferenceableConnections) {
60150e3506533478fa273cbc92c2919470d1889f1edIhab Awad            c.removeConnectionListener(mConnectionDeathListener);
60250e3506533478fa273cbc92c2919470d1889f1edIhab Awad        }
60350e3506533478fa273cbc92c2919470d1889f1edIhab Awad        mConferenceableConnections.clear();
60450e3506533478fa273cbc92c2919470d1889f1edIhab Awad    }
60507366813cdf3768dcd69a1f744023747564d654aRekha Kumar
60607366813cdf3768dcd69a1f744023747564d654aRekha Kumar    @Override
60707366813cdf3768dcd69a1f744023747564d654aRekha Kumar    public String toString() {
60807366813cdf3768dcd69a1f744023747564d654aRekha Kumar        return String.format(Locale.US,
60907366813cdf3768dcd69a1f744023747564d654aRekha Kumar                "[State: %s,Capabilites: %s, VideoState: %s, VideoProvider: %s, ThisObject %s]",
61007366813cdf3768dcd69a1f744023747564d654aRekha Kumar                Connection.stateToString(mState),
61107366813cdf3768dcd69a1f744023747564d654aRekha Kumar                Call.Details.capabilitiesToString(mConnectionCapabilities),
61207366813cdf3768dcd69a1f744023747564d654aRekha Kumar                getVideoState(),
61307366813cdf3768dcd69a1f744023747564d654aRekha Kumar                getVideoProvider(),
61407366813cdf3768dcd69a1f744023747564d654aRekha Kumar                super.toString());
61507366813cdf3768dcd69a1f744023747564d654aRekha Kumar    }
6160f51da328d11f8709d99890a61d6b4021a2207a5Andrew Lee
617edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee    /**
618edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee     * Sets the label and icon status to display in the InCall UI.
619edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee     *
620edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee     * @param statusHints The status label and icon to set.
621edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee     */
622edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee    public final void setStatusHints(StatusHints statusHints) {
623edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee        mStatusHints = statusHints;
624edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee        for (Listener l : mListeners) {
625edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee            l.onStatusHintsChanged(this, statusHints);
626edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee        }
627edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee    }
628edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee
629edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee    /**
630edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee     * @return The status hints for this conference.
631edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee     */
632edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee    public final StatusHints getStatusHints() {
633edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee        return mStatusHints;
634edc625f52e5db5d0cb3d60387218f8f8365167f7Andrew Lee    }
6356b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon
6366b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    /**
6376b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * Set some extras that can be associated with this {@code Conference}. No assumptions should
6386b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * be made as to how an In-Call UI or service will handle these extras.
6396b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
6406b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     *
6416b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * @param extras The extras associated with this {@code Connection}.
6426b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     */
6436b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    public final void setExtras(@Nullable Bundle extras) {
6446b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        mExtras = extras;
6456b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        for (Listener l : mListeners) {
6466b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon            l.onExtrasChanged(this, extras);
6476b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        }
6486b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    }
6496b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon
6506b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    /**
6516b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * @return The extras associated with this conference.
6526b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     */
6536b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    public final Bundle getExtras() {
6546b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        return mExtras;
6556b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    }
656823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon}
657