1542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad/*
2542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * Copyright (C) 2014 The Android Open Source Project
3542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad *
4542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * Licensed under the Apache License, Version 2.0 (the "License");
5542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * you may not use this file except in compliance with the License.
6542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * You may obtain a copy of the License at
7542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad *
8542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad *      http://www.apache.org/licenses/LICENSE-2.0
9542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad *
10542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * Unless required by applicable law or agreed to in writing, software
11542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * distributed under the License is distributed on an "AS IS" BASIS,
12542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * See the License for the specific language governing permissions and
14542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad * limitations under the License.
15542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad */
16542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
17ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnpackage android.telecom;
18542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
194538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunnimport com.android.internal.os.SomeArgs;
20ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnimport com.android.internal.telecom.IVideoCallback;
21ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnimport com.android.internal.telecom.IVideoProvider;
22b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
23dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunnimport android.annotation.NonNull;
246b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordonimport android.annotation.Nullable;
254af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Leeimport android.annotation.SystemApi;
26b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunnimport android.hardware.camera2.CameraManager;
27542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awadimport android.net.Uri;
286b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordonimport android.os.Bundle;
29b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awadimport android.os.Handler;
30b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awadimport android.os.IBinder;
314e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunnimport android.os.Looper;
32b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awadimport android.os.Message;
33b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awadimport android.os.RemoteException;
34dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunnimport android.util.ArraySet;
35b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awadimport android.view.Surface;
36542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
37b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordonimport java.util.ArrayList;
38b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awadimport java.util.Collections;
39b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordonimport java.util.List;
40542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awadimport java.util.Set;
41229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shraunerimport java.util.concurrent.ConcurrentHashMap;
42542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
43542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad/**
44895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon * Represents a phone call or connection to a remote endpoint that carries voice and/or video
45895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon * traffic.
466107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * <p>
476107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * Implementations create a custom subclass of {@code Connection} and return it to the framework
486107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * as the return value of
496107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * {@link ConnectionService#onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)}
506107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * or
516107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * {@link ConnectionService#onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}.
526107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * Implementations are then responsible for updating the state of the {@code Connection}, and
536107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
546107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad * longer used and associated resources may be recovered.
55542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad */
56abfcfdc0444c48dd161e425c8417dab87de1cb69Yorke Leepublic abstract class Connection extends Conferenceable {
57542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
58895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
59895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * The connection is initializing. This is generally the first state for a {@code Connection}
60895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * returned by a {@link ConnectionService}.
61895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
62b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static final int STATE_INITIALIZING = 0;
63b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
64895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
65895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * The connection is new and not connected.
66895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
67b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static final int STATE_NEW = 1;
68b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
69895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
70895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * An incoming connection is in the ringing state. During this state, the user's ringer or
71895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * vibration feature will be activated.
72895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
73b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static final int STATE_RINGING = 2;
74b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
75895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
76895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * An outgoing connection is in the dialing state. In this state the other party has not yet
77895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * answered the call and the user traditionally hears a ringback tone.
78895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
79b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static final int STATE_DIALING = 3;
80b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
81895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
82895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * A connection is active. Both parties are connected to the call and can actively communicate.
83895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
84b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static final int STATE_ACTIVE = 4;
85b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
86895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
87895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * A connection is on hold.
88895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
89b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static final int STATE_HOLDING = 5;
90b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
91895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
92895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * A connection has been disconnected. This is the final state once the user has been
93895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * disconnected from a call either locally, remotely or by an error in the service.
94895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
95b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static final int STATE_DISCONNECTED = 6;
96b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
97895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon    /**
98876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * The state of an external connection which is in the process of being pulled from a remote
99876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * device to the local device.
100876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
101720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * A connection can only be in this state if the {@link #PROPERTY_IS_EXTERNAL_CALL} property and
102876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * {@link #CAPABILITY_CAN_PULL_CALL} capability bits are set on the connection.
1031bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
104876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     */
105876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    public static final int STATE_PULLING_CALL = 7;
106876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn
107876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    /**
108895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * Connection can currently be put on hold or unheld. This is distinct from
109895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * {@link #CAPABILITY_SUPPORT_HOLD} in that although a connection may support 'hold' most times,
110895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * it does not at the moment support the function. This can be true while the call is in the
111895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * state {@link #STATE_DIALING}, for example. During this condition, an in-call UI may
112895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     * display a disabled 'hold' button.
113895d4b8f63389b79974dfd3e36f1ab10b5ceb4dcSantos Cordon     */
1145c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_HOLD = 0x00000001;
1155c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1165c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /** Connection supports the hold feature. */
1175c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_SUPPORT_HOLD = 0x00000002;
1185c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1195c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1205c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Connections within a conference can be merged. A {@link ConnectionService} has the option to
1215c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * add a {@link Conference} before the child {@link Connection}s are merged. This is how
1225c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, this
1235c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * capability allows a merge button to be shown while the conference is in the foreground
1245c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * of the in-call UI.
1255c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * <p>
1265c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * This is only intended for use by a {@link Conference}.
1275c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1285c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_MERGE_CONFERENCE = 0x00000004;
1295c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1305c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1315c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Connections within a conference can be swapped between foreground and background.
1325c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.
1335c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * <p>
1345c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * This is only intended for use by a {@link Conference}.
1355c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1365c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_SWAP_CONFERENCE = 0x00000008;
1375c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1385c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1395c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
1405c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1415c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_UNUSED = 0x00000010;
1425c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1435c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /** Connection supports responding via text option. */
1445c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_RESPOND_VIA_TEXT = 0x00000020;
1455c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1465c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /** Connection can be muted. */
1475c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_MUTE = 0x00000040;
1485c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1495c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1505c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Connection supports conference management. This capability only applies to
1515c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * {@link Conference}s which can have {@link Connection}s as children.
1525c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1535c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_MANAGE_CONFERENCE = 0x00000080;
1545c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1555c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1565e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * Local device supports receiving video.
1575c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1585e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX = 0x00000100;
1595c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1605c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1615e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * Local device supports transmitting video.
1625c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1635e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX = 0x00000200;
1645c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1655c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1665e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * Local device supports bidirectional video calling.
1675c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1689a8f9ce7adeb5fd93c11afffcc580d2af5c1225dAndrew Lee    public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL =
1695e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee            CAPABILITY_SUPPORTS_VT_LOCAL_RX | CAPABILITY_SUPPORTS_VT_LOCAL_TX;
1705c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1715c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1725e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * Remote device supports receiving video.
1735c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1745e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX = 0x00000400;
1755e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee
1765e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    /**
1775e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * Remote device supports transmitting video.
1785e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     */
1795e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX = 0x00000800;
1805e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee
1815e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    /**
1825e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * Remote device supports bidirectional video calling.
1835e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     */
1849a8f9ce7adeb5fd93c11afffcc580d2af5c1225dAndrew Lee    public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL =
1855e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee            CAPABILITY_SUPPORTS_VT_REMOTE_RX | CAPABILITY_SUPPORTS_VT_REMOTE_TX;
1865c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1875c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1885c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Connection is able to be separated from its parent {@code Conference}, if any.
1895c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1905c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE = 0x00001000;
1915c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1925c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
1935c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Connection is able to be individually disconnected when in a {@code Conference}.
1945c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
1955c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE = 0x00002000;
1965c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
1975c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
198720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Un-used.
1995c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
2005c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
201720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int CAPABILITY_UNUSED_2 = 0x00004000;
2025c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
2035e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    /**
204720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Un-used.
2055e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * @hide
2065e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     */
207720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int CAPABILITY_UNUSED_3 = 0x00008000;
2085e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee
2095e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee    /**
210720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Un-used.
2115e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     * @hide
2125e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee     */
213720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int CAPABILITY_UNUSED_4 = 0x00010000;
2145e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee
215068085b35d4c7ef368fde6f01b42f87766d4a2b4Tyler Gunn    /**
216720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Un-used.
217068085b35d4c7ef368fde6f01b42f87766d4a2b4Tyler Gunn     * @hide
218068085b35d4c7ef368fde6f01b42f87766d4a2b4Tyler Gunn     */
219720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int CAPABILITY_UNUSED_5 = 0x00020000;
220068085b35d4c7ef368fde6f01b42f87766d4a2b4Tyler Gunn
22196d6c40c7159a6e93c21a3b540e24a6ff916cb4bTyler Gunn    /**
22289f41eb39e910e220957ac861651ead17eff9085Dong Zhou     * Speed up audio setup for MT call.
22389f41eb39e910e220957ac861651ead17eff9085Dong Zhou     * @hide
22496d6c40c7159a6e93c21a3b540e24a6ff916cb4bTyler Gunn     */
22596d6c40c7159a6e93c21a3b540e24a6ff916cb4bTyler Gunn    public static final int CAPABILITY_SPEED_UP_MT_AUDIO = 0x00040000;
226068085b35d4c7ef368fde6f01b42f87766d4a2b4Tyler Gunn
22707366813cdf3768dcd69a1f744023747564d654aRekha Kumar    /**
228b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn     * Call can be upgraded to a video call.
22907366813cdf3768dcd69a1f744023747564d654aRekha Kumar     */
23007366813cdf3768dcd69a1f744023747564d654aRekha Kumar    public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO = 0x00080000;
23107366813cdf3768dcd69a1f744023747564d654aRekha Kumar
232b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn    /**
233b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn     * For video calls, indicates whether the outgoing video for the call can be paused using
23432f24731604fd81289a39619bbc925b65184b505Yorke Lee     * the {@link android.telecom.VideoProfile#STATE_PAUSED} VideoState.
235b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn     */
236b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn    public static final int CAPABILITY_CAN_PAUSE_VIDEO = 0x00100000;
237b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn
238d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn    /**
239d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * For a conference, indicates the conference will not have child connections.
240d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * <p>
241d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * An example of a conference with child connections is a GSM conference call, where the radio
242d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * retains connections to the individual participants of the conference.  Another example is an
243d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * IMS conference call where conference event package functionality is supported; in this case
244d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * the conference server ensures the radio is aware of the participants in the conference, which
245d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * are represented by child connections.
246d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * <p>
247d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * An example of a conference with no child connections is an IMS conference call with no
248d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * conference event package support.  Such a conference is represented by the radio as a single
249d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * connection to the IMS conference server.
250d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * <p>
251d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * Indicating whether a conference has children or not is important to help user interfaces
252d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * visually represent a conference.  A conference with no children, for example, will have the
253d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * conference connection shown in the list of calls on a Bluetooth device, where if the
254d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * conference has children, only the children will be shown in the list of calls on a Bluetooth
255d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * device.
256d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     * @hide
257d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn     */
258d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn    public static final int CAPABILITY_CONFERENCE_HAS_NO_CHILDREN = 0x00200000;
259d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn
2608190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee    /**
2618190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee     * Indicates that the connection itself wants to handle any sort of reply response, rather than
2628190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee     * relying on SMS.
2638190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee     */
2648190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee    public static final int CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION = 0x00400000;
2658190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee
266f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn    /**
267f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * When set, prevents a video call from being downgraded to an audio-only call.
268f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * <p>
269f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * Should be set when the VideoState has the {@link VideoProfile#STATE_TX_ENABLED} or
270f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * {@link VideoProfile#STATE_RX_ENABLED} bits set to indicate that the connection cannot be
271f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * downgraded from a video call back to a VideoState of
272f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * {@link VideoProfile#STATE_AUDIO_ONLY}.
273f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * <p>
274f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * Intuitively, a call which can be downgraded to audio should also have local and remote
275f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * video
276f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * capabilities (see {@link #CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL} and
277f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     * {@link #CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL}).
278f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn     */
279f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn    public static final int CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO = 0x00800000;
280f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn
281876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    /**
282720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * When set for an external connection, indicates that this {@code Connection} can be pulled
283720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * from a remote device to the current device.
284720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * <p>
285720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Should only be set on a {@code Connection} where {@link #PROPERTY_IS_EXTERNAL_CALL}
286720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * is set.
2871bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
288720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     */
289720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int CAPABILITY_CAN_PULL_CALL = 0x01000000;
290720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
291720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    //**********************************************************************************************
292720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    // Next CAPABILITY value: 0x02000000
293720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    //**********************************************************************************************
294720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
295720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    /**
296720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Indicates that the current device callback number should be shown.
297720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     *
298720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * @hide
299720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     */
300720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int PROPERTY_SHOW_CALLBACK_NUMBER = 1<<0;
301720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
302720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    /**
303720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Whether the call is a generic conference, where we do not know the precise state of
304720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * participants in the conference (eg. on CDMA).
305720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     *
306720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * @hide
307720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     */
308720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int PROPERTY_GENERIC_CONFERENCE = 1<<1;
309720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
310720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    /**
311720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Connection is using high definition audio.
312720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * @hide
313720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     */
314720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int PROPERTY_HIGH_DEF_AUDIO = 1<<2;
315720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
316720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    /**
317720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Connection is using WIFI.
318720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * @hide
319720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     */
320720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int PROPERTY_WIFI = 1<<3;
321720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
322720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    /**
323876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * When set, indicates that the {@code Connection} does not actually exist locally for the
324876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * {@link ConnectionService}.
325876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
326876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Consider, for example, a scenario where a user has two devices with the same phone number.
327876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * When a user places a call on one devices, the telephony stack can represent that call on the
328876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * other device by adding is to the {@link ConnectionService} with the
329720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * {@link #PROPERTY_IS_EXTERNAL_CALL} capability set.
330876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
331876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * An {@link ConnectionService} should not assume that all {@link InCallService}s will handle
332876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * external connections.  Only those {@link InCallService}s which have the
333876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * {@link TelecomManager#METADATA_INCLUDE_EXTERNAL_CALLS} metadata set to {@code true} in its
334876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * manifest will see external connections.
3351bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
336876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     */
337720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static final int PROPERTY_IS_EXTERNAL_CALL = 1<<4;
338876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn
339876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn
34096d6c40c7159a6e93c21a3b540e24a6ff916cb4bTyler Gunn    //**********************************************************************************************
341720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    // Next PROPERTY value: 1<<5
34296d6c40c7159a6e93c21a3b540e24a6ff916cb4bTyler Gunn    //**********************************************************************************************
343068085b35d4c7ef368fde6f01b42f87766d4a2b4Tyler Gunn
344335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn    /**
345335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * Connection extra key used to store the last forwarded number associated with the current
346335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * connection.  Used to communicate to the user interface that the connection was forwarded via
347335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * the specified number.
348335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     */
349335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn    public static final String EXTRA_LAST_FORWARDED_NUMBER =
350335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn            "android.telecom.extra.LAST_FORWARDED_NUMBER";
351335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn
352335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn    /**
353335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * Connection extra key used to store a child number associated with the current connection.
354335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * Used to communicate to the user interface that the connection was received via
355335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * a child address (i.e. phone number) associated with the {@link PhoneAccount}'s primary
356335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * address.
357335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     */
358335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn    public static final String EXTRA_CHILD_ADDRESS = "android.telecom.extra.CHILD_ADDRESS";
359335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn
360335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn    /**
361335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * Connection extra key used to store the subject for an incoming call.  The user interface can
362335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * query this extra and display its contents for incoming calls.  Will only be used if the
363335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     * {@link PhoneAccount} supports the capability {@link PhoneAccount#CAPABILITY_CALL_SUBJECT}.
364335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn     */
365335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn    public static final String EXTRA_CALL_SUBJECT = "android.telecom.extra.CALL_SUBJECT";
366335ff2ec7aaa1e56b996e5025a1fa72ddf10535cTyler Gunn
367bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn    /**
368bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * Connection event used to inform Telecom that it should play the on hold tone.  This is used
369bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * to play a tone when the peer puts the current call on hold.  Sent to Telecom via
370bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * {@link #sendConnectionEvent(String)}.
371bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * @hide
372bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     */
373bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn    public static final String EVENT_ON_HOLD_TONE_START =
374bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn            "android.telecom.event.ON_HOLD_TONE_START";
375bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn
376bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn    /**
377bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * Connection event used to inform Telecom that it should stop the on hold tone.  This is used
378bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * to stop a tone when the peer puts the current call on hold.  Sent to Telecom via
379bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * {@link #sendConnectionEvent(String)}.
380bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * @hide
381bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     */
382bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn    public static final String EVENT_ON_HOLD_TONE_END =
383bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn            "android.telecom.event.ON_HOLD_TONE_END";
384bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn
385876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    /**
386876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Connection event used to inform {@link InCallService}s when pulling of an external call has
387876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * failed.  The user interface should inform the user of the error.
388876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
389876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Expected to be used by the {@link ConnectionService} when the {@link Call#pullExternalCall()}
390876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * API is called on a {@link Call} with the properties
391876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * {@link Call.Details#PROPERTY_IS_EXTERNAL_CALL} and
392876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * {@link Call.Details#CAPABILITY_CAN_PULL_CALL}, but the {@link ConnectionService} could not
393876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * pull the external call due to an error condition.
3941bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
395876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     */
396876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    public static final String EVENT_CALL_PULL_FAILED = "android.telecom.event.CALL_PULL_FAILED";
397876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn
398b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    // Flag controlling whether PII is emitted into the logs
399b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG);
400b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
4015c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
4025c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Whether the given capabilities support the specified capability.
4035c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
4045c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capabilities A capability bit field.
4055c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to check capabilities for.
4065c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return Whether the specified capability is supported.
4075c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
4085c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
4095c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static boolean can(int capabilities, int capability) {
410014c711b0db81ce709b0ccad3e50b3d10227edd8Tyler Gunn        return (capabilities & capability) == capability;
4115c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
4125c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
4135c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
4145c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Whether the capabilities of this {@code Connection} supports the specified capability.
4155c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
4165c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to check capabilities for.
4175c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return Whether the specified capability is supported.
4185c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
4195c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
4205c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public boolean can(int capability) {
4215c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        return can(mConnectionCapabilities, capability);
4225c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
4235c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
4245c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
4255c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Removes the specified capability from the set of capabilities of this {@code Connection}.
4265c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
4275c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to remove from the set.
4285c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
4295c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
4305c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public void removeCapability(int capability) {
4315c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        mConnectionCapabilities &= ~capability;
4325c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
4335c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
4345c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
4355c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Adds the specified capability to the set of capabilities of this {@code Connection}.
4365c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
4375c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param capability The capability to add to the set.
4385c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
4395c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
4405c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public void addCapability(int capability) {
4415c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        mConnectionCapabilities |= capability;
4425c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
4435c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
4445c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
4455c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public static String capabilitiesToString(int capabilities) {
4465c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        StringBuilder builder = new StringBuilder();
4475c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        builder.append("[Capabilities:");
4485c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (can(capabilities, CAPABILITY_HOLD)) {
4495c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            builder.append(" CAPABILITY_HOLD");
4505c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4515c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
4525c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            builder.append(" CAPABILITY_SUPPORT_HOLD");
4535c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4545c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
4555c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            builder.append(" CAPABILITY_MERGE_CONFERENCE");
4565c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4575c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
4585c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            builder.append(" CAPABILITY_SWAP_CONFERENCE");
4595c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4605c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
4615c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
4625c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4635c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (can(capabilities, CAPABILITY_MUTE)) {
4645c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            builder.append(" CAPABILITY_MUTE");
4655c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4665c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
4675c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            builder.append(" CAPABILITY_MANAGE_CONFERENCE");
4685c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4695e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_RX)) {
4705e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee            builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_RX");
4715e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        }
4725e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_TX)) {
4735e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee            builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_TX");
4745e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        }
4759a8f9ce7adeb5fd93c11afffcc580d2af5c1225dAndrew Lee        if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL)) {
4769a8f9ce7adeb5fd93c11afffcc580d2af5c1225dAndrew Lee            builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL");
4775c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
4785e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_RX)) {
4795e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee            builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_RX");
4805e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        }
4815e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_TX)) {
4825e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee            builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_TX");
4835e9e8bb30e4d26eba46684c03ca950b602dfb830Andrew Lee        }
4849a8f9ce7adeb5fd93c11afffcc580d2af5c1225dAndrew Lee        if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL)) {
4859a8f9ce7adeb5fd93c11afffcc580d2af5c1225dAndrew Lee            builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL");
4865c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
487f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn        if (can(capabilities, CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO)) {
488f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn            builder.append(" CAPABILITY_CANNOT_DOWNGRADE_VIDEO_TO_AUDIO");
489f97a009f7645690a92bdef3a3ef39298deaff4b7Tyler Gunn        }
49089f41eb39e910e220957ac861651ead17eff9085Dong Zhou        if (can(capabilities, CAPABILITY_SPEED_UP_MT_AUDIO)) {
491d11a31561e88fbbb4f614caff8a05e7ff9ecd357Tyler Gunn            builder.append(" CAPABILITY_SPEED_UP_MT_AUDIO");
49289f41eb39e910e220957ac861651ead17eff9085Dong Zhou        }
49307366813cdf3768dcd69a1f744023747564d654aRekha Kumar        if (can(capabilities, CAPABILITY_CAN_UPGRADE_TO_VIDEO)) {
49407366813cdf3768dcd69a1f744023747564d654aRekha Kumar            builder.append(" CAPABILITY_CAN_UPGRADE_TO_VIDEO");
49507366813cdf3768dcd69a1f744023747564d654aRekha Kumar        }
496b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn        if (can(capabilities, CAPABILITY_CAN_PAUSE_VIDEO)) {
497b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn            builder.append(" CAPABILITY_CAN_PAUSE_VIDEO");
498b5e0cfb24efded1e200989b5b48d49ac144c7704Tyler Gunn        }
499d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn        if (can(capabilities, CAPABILITY_CONFERENCE_HAS_NO_CHILDREN)) {
500d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn            builder.append(" CAPABILITY_SINGLE_PARTY_CONFERENCE");
501d409173570e504f36db80ecfaa3284eb35f5a3c7Tyler Gunn        }
5028190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee        if (can(capabilities, CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
5038190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee            builder.append(" CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION");
5048190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee        }
505876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn        if (can(capabilities, CAPABILITY_CAN_PULL_CALL)) {
506876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn            builder.append(" CAPABILITY_CAN_PULL_CALL");
507876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn        }
5088190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee
5095c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        builder.append("]");
5105c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        return builder.toString();
5115c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    }
5125c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
5131bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn    /**
5141bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * Builds a string representation of a properties bit-mask.
5151bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     *
5161bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @param properties The properties bit-mask.
5171bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @return String representation.
5181bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
5191bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     */
520720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public static String propertiesToString(int properties) {
521720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        StringBuilder builder = new StringBuilder();
522720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        builder.append("[Properties:");
523720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
524720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        if (can(properties, PROPERTY_SHOW_CALLBACK_NUMBER)) {
525720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            builder.append(" PROPERTY_SHOW_CALLBACK_NUMBER");
526720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        }
527720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
528720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        if (can(properties, PROPERTY_HIGH_DEF_AUDIO)) {
529720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            builder.append(" PROPERTY_HIGH_DEF_AUDIO");
530720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        }
531720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
532720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        if (can(properties, PROPERTY_WIFI)) {
533720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            builder.append(" PROPERTY_WIFI");
534720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        }
535720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
536720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        if (can(properties, PROPERTY_GENERIC_CONFERENCE)) {
537720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            builder.append(" PROPERTY_GENERIC_CONFERENCE");
538720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        }
539720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
540720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        if (can(properties, PROPERTY_IS_EXTERNAL_CALL)) {
541720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            builder.append(" PROPERTY_IS_EXTERNAL_CALL");
542720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        }
543720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
544720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        builder.append("]");
545720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        return builder.toString();
546720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    }
547720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
548091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal    /** @hide */
549612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    public abstract static class Listener {
550542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad        public void onStateChanged(Connection c, int state) {}
551100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        public void onAddressChanged(Connection c, Uri newAddress, int presentation) {}
552612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        public void onCallerDisplayNameChanged(
553612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal                Connection c, String callerDisplayName, int presentation) {}
554aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn        public void onVideoStateChanged(Connection c, int videoState) {}
5557f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee        public void onDisconnected(Connection c, DisconnectCause disconnectCause) {}
556091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal        public void onPostDialWait(Connection c, String remaining) {}
55727d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen        public void onPostDialChar(Connection c, char nextChar) {}
558100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        public void onRingbackRequested(Connection c, boolean ringback) {}
559612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        public void onDestroyed(Connection c) {}
5605c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        public void onConnectionCapabilitiesChanged(Connection c, int capabilities) {}
561720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        public void onConnectionPropertiesChanged(Connection c, int properties) {}
562b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public void onVideoProviderChanged(
563b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                Connection c, VideoProvider videoProvider) {}
564001bbbb239d4ef1005a87039c7c53e26d8f13ad6Sailesh Nepal        public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
565001bbbb239d4ef1005a87039c7c53e26d8f13ad6Sailesh Nepal        public void onStatusHintsChanged(Connection c, StatusHints statusHints) {}
5666d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        public void onConferenceablesChanged(
567df2cbc8989e624cd6a1d732549ea4a4f00852508Tyler Gunn                Connection c, List<Conferenceable> conferenceables) {}
568823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        public void onConferenceChanged(Connection c, Conference conference) {}
5693bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn        /** @hide */
570ab4650c4563cd46e65ac37f924fee8febfd759c6Tyler Gunn        public void onConferenceParticipantsChanged(Connection c,
571ab4650c4563cd46e65ac37f924fee8febfd759c6Tyler Gunn                List<ConferenceParticipant> participants) {}
5728a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn        public void onConferenceStarted() {}
57317455a3d39350a39eb995897929977d793358365Anthony Lee        public void onConferenceMergeFailed(Connection c) {}
5746b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        public void onExtrasChanged(Connection c, Bundle extras) {}
575dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        public void onExtrasRemoved(Connection c, List<String> keys) {}
576876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn        public void onConnectionEvent(Connection c, String event, Bundle extras) {}
577542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
578542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
579b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn    /**
580b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * Provides a means of controlling the video session associated with a {@link Connection}.
581b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * <p>
582b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * Implementations create a custom subclass of {@link VideoProvider} and the
583b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * {@link ConnectionService} creates an instance sets it on the {@link Connection} using
584b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * {@link Connection#setVideoProvider(VideoProvider)}.  Any connection which supports video
585b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * should set the {@link VideoProvider}.
586b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * <p>
587b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * The {@link VideoProvider} serves two primary purposes: it provides a means for Telecom and
588b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * {@link InCallService} implementations to issue requests related to the video session;
589b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * it provides a means for the {@link ConnectionService} to report events and information
590b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * related to the video session to Telecom and the {@link InCallService} implementations.
591b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * <p>
592b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * {@link InCallService} implementations interact with the {@link VideoProvider} via
593b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     * {@link android.telecom.InCallService.VideoCall}.
594b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn     */
595b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static abstract class VideoProvider {
596b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
597b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
598b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Video is not being received (no protocol pause was issued).
599b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #handleCallSessionEvent(int)
600b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
601b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_EVENT_RX_PAUSE = 1;
602b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
603b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
604b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Video reception has resumed after a {@link #SESSION_EVENT_RX_PAUSE}.
605b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #handleCallSessionEvent(int)
606b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
607b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_EVENT_RX_RESUME = 2;
608b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
609b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
610b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Video transmission has begun. This occurs after a negotiated start of video transmission
611b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * when the underlying protocol has actually begun transmitting video to the remote party.
612b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #handleCallSessionEvent(int)
613b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
614b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_EVENT_TX_START = 3;
615b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
616b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
617b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Video transmission has stopped. This occurs after a negotiated stop of video transmission
618b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * when the underlying protocol has actually stopped transmitting video to the remote party.
619b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #handleCallSessionEvent(int)
620b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
621b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_EVENT_TX_STOP = 4;
622b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
623b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
624b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * A camera failure has occurred for the selected camera.  The {@link InCallService} can use
625b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * this as a cue to inform the user the camera is not available.
626b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #handleCallSessionEvent(int)
627b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
628b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_EVENT_CAMERA_FAILURE = 5;
629b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
630b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
631b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Issued after {@link #SESSION_EVENT_CAMERA_FAILURE} when the camera is once again ready
632b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * for operation.  The {@link InCallService} can use this as a cue to inform the user that
633b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * the camera has become available again.
634b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #handleCallSessionEvent(int)
635b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
636b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_EVENT_CAMERA_READY = 6;
637b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
638b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
639b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Session modify request was successful.
640b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
641b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
642b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_MODIFY_REQUEST_SUCCESS = 1;
643b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
644b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
645b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Session modify request failed.
646b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
647b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
648b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_MODIFY_REQUEST_FAIL = 2;
649b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
650b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
651b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Session modify request ignored due to invalid parameters.
652b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
653b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
654b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public static final int SESSION_MODIFY_REQUEST_INVALID = 3;
655b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
65607366813cdf3768dcd69a1f744023747564d654aRekha Kumar        /**
65707366813cdf3768dcd69a1f744023747564d654aRekha Kumar         * Session modify request timed out.
658b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
65907366813cdf3768dcd69a1f744023747564d654aRekha Kumar         */
66007366813cdf3768dcd69a1f744023747564d654aRekha Kumar        public static final int SESSION_MODIFY_REQUEST_TIMED_OUT = 4;
66107366813cdf3768dcd69a1f744023747564d654aRekha Kumar
66207366813cdf3768dcd69a1f744023747564d654aRekha Kumar        /**
663b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Session modify request rejected by remote user.
664b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)
66507366813cdf3768dcd69a1f744023747564d654aRekha Kumar         */
66607366813cdf3768dcd69a1f744023747564d654aRekha Kumar        public static final int SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE = 5;
66707366813cdf3768dcd69a1f744023747564d654aRekha Kumar
66875958420f2d294ceda517c2782b294002dc2969fTyler Gunn        private static final int MSG_ADD_VIDEO_CALLBACK = 1;
669b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SET_CAMERA = 2;
670b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SET_PREVIEW_SURFACE = 3;
671b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SET_DISPLAY_SURFACE = 4;
672b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SET_DEVICE_ORIENTATION = 5;
673b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SET_ZOOM = 6;
674b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SEND_SESSION_MODIFY_REQUEST = 7;
675b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SEND_SESSION_MODIFY_RESPONSE = 8;
676b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_REQUEST_CAMERA_CAPABILITIES = 9;
6775c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        private static final int MSG_REQUEST_CONNECTION_DATA_USAGE = 10;
678b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private static final int MSG_SET_PAUSE_IMAGE = 11;
67975958420f2d294ceda517c2782b294002dc2969fTyler Gunn        private static final int MSG_REMOVE_VIDEO_CALLBACK = 12;
680b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
6814e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn        private VideoProvider.VideoProviderHandler mMessageHandler;
682b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private final VideoProvider.VideoProviderBinder mBinder;
68375958420f2d294ceda517c2782b294002dc2969fTyler Gunn
68475958420f2d294ceda517c2782b294002dc2969fTyler Gunn        /**
68575958420f2d294ceda517c2782b294002dc2969fTyler Gunn         * Stores a list of the video callbacks, keyed by IBinder.
68684f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn         *
68784f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn         * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
68884f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn         * load factor before resizing, 1 means we only expect a single thread to
68984f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn         * access the map so make only a single shard
69075958420f2d294ceda517c2782b294002dc2969fTyler Gunn         */
69184f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn        private ConcurrentHashMap<IBinder, IVideoCallback> mVideoCallbacks =
69284f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                new ConcurrentHashMap<IBinder, IVideoCallback>(8, 0.9f, 1);
693b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
694b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
695b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Default handler used to consolidate binder method calls onto a single thread.
696b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
697b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private final class VideoProviderHandler extends Handler {
6984e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn            public VideoProviderHandler() {
6994e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn                super();
7004e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn            }
7014e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn
7024e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn            public VideoProviderHandler(Looper looper) {
7034e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn                super(looper);
7044e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn            }
7054e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn
706b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            @Override
707b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void handleMessage(Message msg) {
708b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                switch (msg.what) {
70975958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    case MSG_ADD_VIDEO_CALLBACK: {
71075958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        IBinder binder = (IBinder) msg.obj;
71175958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        IVideoCallback callback = IVideoCallback.Stub
71275958420f2d294ceda517c2782b294002dc2969fTyler Gunn                                .asInterface((IBinder) msg.obj);
71384f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        if (callback == null) {
71484f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                            Log.w(this, "addVideoProvider - skipped; callback is null.");
71584f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                            break;
71684f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        }
71784f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn
71875958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        if (mVideoCallbacks.containsKey(binder)) {
71975958420f2d294ceda517c2782b294002dc2969fTyler Gunn                            Log.i(this, "addVideoProvider - skipped; already present.");
72075958420f2d294ceda517c2782b294002dc2969fTyler Gunn                            break;
72175958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        }
72275958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        mVideoCallbacks.put(binder, callback);
72375958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        break;
72475958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
72575958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    case MSG_REMOVE_VIDEO_CALLBACK: {
72675958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        IBinder binder = (IBinder) msg.obj;
72775958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        IVideoCallback callback = IVideoCallback.Stub
72875958420f2d294ceda517c2782b294002dc2969fTyler Gunn                                .asInterface((IBinder) msg.obj);
72975958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        if (!mVideoCallbacks.containsKey(binder)) {
73075958420f2d294ceda517c2782b294002dc2969fTyler Gunn                            Log.i(this, "removeVideoProvider - skipped; not present.");
73175958420f2d294ceda517c2782b294002dc2969fTyler Gunn                            break;
73275958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        }
73375958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        mVideoCallbacks.remove(binder);
734b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
73575958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
736b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_SET_CAMERA:
737b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        onSetCamera((String) msg.obj);
738b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
739b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_SET_PREVIEW_SURFACE:
740b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        onSetPreviewSurface((Surface) msg.obj);
741b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
742b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_SET_DISPLAY_SURFACE:
743b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        onSetDisplaySurface((Surface) msg.obj);
744b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
745b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_SET_DEVICE_ORIENTATION:
746b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        onSetDeviceOrientation(msg.arg1);
747b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
748b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_SET_ZOOM:
749b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        onSetZoom((Float) msg.obj);
750b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
7514538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                    case MSG_SEND_SESSION_MODIFY_REQUEST: {
7524538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                        SomeArgs args = (SomeArgs) msg.obj;
7534538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                        try {
7544538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                            onSendSessionModifyRequest((VideoProfile) args.arg1,
7554538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                                    (VideoProfile) args.arg2);
7564538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                        } finally {
7574538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                            args.recycle();
7584538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                        }
759b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
7604538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                    }
761b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_SEND_SESSION_MODIFY_RESPONSE:
762b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        onSendSessionModifyResponse((VideoProfile) msg.obj);
763b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
764b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_REQUEST_CAMERA_CAPABILITIES:
765b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        onRequestCameraCapabilities();
766b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
7675c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad                    case MSG_REQUEST_CONNECTION_DATA_USAGE:
7685c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad                        onRequestConnectionDataUsage();
769b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
770b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    case MSG_SET_PAUSE_IMAGE:
77132f24731604fd81289a39619bbc925b65184b505Yorke Lee                        onSetPauseImage((Uri) msg.obj);
772b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
773b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                    default:
774b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        break;
775b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                }
776b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
777b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
778b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
779b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
780b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * IVideoProvider stub implementation.
781b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
782b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        private final class VideoProviderBinder extends IVideoProvider.Stub {
78375958420f2d294ceda517c2782b294002dc2969fTyler Gunn            public void addVideoCallback(IBinder videoCallbackBinder) {
78475958420f2d294ceda517c2782b294002dc2969fTyler Gunn                mMessageHandler.obtainMessage(
78575958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        MSG_ADD_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
78675958420f2d294ceda517c2782b294002dc2969fTyler Gunn            }
78775958420f2d294ceda517c2782b294002dc2969fTyler Gunn
78875958420f2d294ceda517c2782b294002dc2969fTyler Gunn            public void removeVideoCallback(IBinder videoCallbackBinder) {
789b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(
79075958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        MSG_REMOVE_VIDEO_CALLBACK, videoCallbackBinder).sendToTarget();
791b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
792b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
793b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void setCamera(String cameraId) {
794b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(MSG_SET_CAMERA, cameraId).sendToTarget();
795b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
796b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
797b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void setPreviewSurface(Surface surface) {
798b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(MSG_SET_PREVIEW_SURFACE, surface).sendToTarget();
799b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
800b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
801b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void setDisplaySurface(Surface surface) {
802b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(MSG_SET_DISPLAY_SURFACE, surface).sendToTarget();
803b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
804b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
805b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void setDeviceOrientation(int rotation) {
80607366813cdf3768dcd69a1f744023747564d654aRekha Kumar                mMessageHandler.obtainMessage(
80707366813cdf3768dcd69a1f744023747564d654aRekha Kumar                        MSG_SET_DEVICE_ORIENTATION, rotation, 0).sendToTarget();
808b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
809b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
810b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void setZoom(float value) {
811b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(MSG_SET_ZOOM, value).sendToTarget();
812b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
813b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
8144538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn            public void sendSessionModifyRequest(VideoProfile fromProfile, VideoProfile toProfile) {
8154538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                SomeArgs args = SomeArgs.obtain();
8164538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                args.arg1 = fromProfile;
8174538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                args.arg2 = toProfile;
8184538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                mMessageHandler.obtainMessage(MSG_SEND_SESSION_MODIFY_REQUEST, args).sendToTarget();
819b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
820b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
821b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void sendSessionModifyResponse(VideoProfile responseProfile) {
822b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(
823b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        MSG_SEND_SESSION_MODIFY_RESPONSE, responseProfile).sendToTarget();
824b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
825b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
826b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void requestCameraCapabilities() {
827b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(MSG_REQUEST_CAMERA_CAPABILITIES).sendToTarget();
828b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
829b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
830b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            public void requestCallDataUsage() {
8315c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad                mMessageHandler.obtainMessage(MSG_REQUEST_CONNECTION_DATA_USAGE).sendToTarget();
832b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
833b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
83432f24731604fd81289a39619bbc925b65184b505Yorke Lee            public void setPauseImage(Uri uri) {
835b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                mMessageHandler.obtainMessage(MSG_SET_PAUSE_IMAGE, uri).sendToTarget();
836b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
837b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
838b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
839b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public VideoProvider() {
840b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            mBinder = new VideoProvider.VideoProviderBinder();
84184f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn            mMessageHandler = new VideoProvider.VideoProviderHandler(Looper.getMainLooper());
8424e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn        }
8434e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn
8444e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn        /**
8454e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn         * Creates an instance of the {@link VideoProvider}, specifying the looper to use.
8464e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn         *
8474e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn         * @param looper The looper.
8484e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn         * @hide
8494e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn         */
8504e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn        public VideoProvider(Looper looper) {
8514e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn            mBinder = new VideoProvider.VideoProviderBinder();
8524e9bbaf043e4d64b737099af05a035780b7da8d6Tyler Gunn            mMessageHandler = new VideoProvider.VideoProviderHandler(looper);
853b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
854b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
855b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
856b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Returns binder object which can be used across IPC methods.
857b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * @hide
858b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
859b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public final IVideoProvider getInterface() {
860b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            return mBinder;
861b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
862b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
863b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
864b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sets the camera to be used for the outgoing video.
865b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
866b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
867b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * camera via
868b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
869b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
870b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
871b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#setCamera(String)}.
872b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
873b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param cameraId The id of the camera (use ids as reported by
874b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link CameraManager#getCameraIdList()}).
875b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
876b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public abstract void onSetCamera(String cameraId);
877b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
878b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
879b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Sets the surface to be used for displaying a preview of what the user's camera is
880b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * currently capturing.  When video transmission is enabled, this is the video signal which
881b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * is sent to the remote device.
882b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
883b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
884b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#setPreviewSurface(Surface)}.
885b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
886b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param surface The {@link Surface}.
887b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
888b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public abstract void onSetPreviewSurface(Surface surface);
889b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
890b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
891b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Sets the surface to be used for displaying the video received from the remote device.
892b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
893b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
894b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#setDisplaySurface(Surface)}.
895b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
896b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param surface The {@link Surface}.
897b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
898b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public abstract void onSetDisplaySurface(Surface surface);
899b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
900b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
901b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Sets the device orientation, in degrees.  Assumes that a standard portrait orientation of
902b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * the device is 0 degrees.
903b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
904b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
905b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#setDeviceOrientation(int)}.
906b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
907b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * @param rotation The device orientation, in degrees.
908b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
909b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public abstract void onSetDeviceOrientation(int rotation);
910b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
911b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
912b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * Sets camera zoom ratio.
913b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
914b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via {@link InCallService.VideoCall#setZoom(float)}.
915b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
916b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * @param value The camera zoom ratio.
917b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
918b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public abstract void onSetZoom(float value);
919b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
920b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
921b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Issues a request to modify the properties of the current video session.
922b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
923b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Example scenarios include: requesting an audio-only call to be upgraded to a
924b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * bi-directional video call, turning on or off the user's camera, sending a pause signal
925b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * when the {@link InCallService} is no longer the foreground application.
926b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
927b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * If the {@link VideoProvider} determines a request to be invalid, it should call
928b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)} to report the
929b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * invalid request back to the {@link InCallService}.
930b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
931b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Where a request requires confirmation from the user of the peer device, the
932b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProvider} must communicate the request to the peer device and handle the
933b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * user's response.  {@link #receiveSessionModifyResponse(int, VideoProfile, VideoProfile)}
934b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * is used to inform the {@link InCallService} of the result of the request.
935b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
936b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
937b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#sendSessionModifyRequest(VideoProfile)}.
938b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
939b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param fromProfile The video profile prior to the request.
940b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param toProfile The video profile with the requested changes made.
941b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
9424538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn        public abstract void onSendSessionModifyRequest(VideoProfile fromProfile,
9434538216a31d15b01e18c7b504e51031da0ce6e40Tyler Gunn                VideoProfile toProfile);
944b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
945b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn        /**
946b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Provides a response to a request to change the current video session properties.
947b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
948b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * For example, if the peer requests and upgrade from an audio-only call to a bi-directional
949b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * video call, could decline the request and keep the call as audio-only.
950b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * In such a scenario, the {@code responseProfile} would have a video state of
951b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProfile#STATE_AUDIO_ONLY}.  If the user had decided to accept the request,
952b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * the video state would be {@link VideoProfile#STATE_BIDIRECTIONAL}.
953b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
954b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
955b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#sendSessionModifyResponse(VideoProfile)} in response to
956b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * a {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)}
957b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * callback.
958b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
959b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param responseProfile The response video profile.
960b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
961b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public abstract void onSendSessionModifyResponse(VideoProfile responseProfile);
962b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
963b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
964b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Issues a request to the {@link VideoProvider} to retrieve the camera capabilities.
965b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
966b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * The {@link VideoProvider} should respond by communicating the capabilities of the chosen
967b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * camera via
968b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProvider#changeCameraCapabilities(VideoProfile.CameraCapabilities)}.
969b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
970b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
971b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#requestCameraCapabilities()}.
972b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
973b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public abstract void onRequestCameraCapabilities();
974b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
975b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
976b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Issues a request to the {@link VideoProvider} to retrieve the current data usage for the
977b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * video component of the current {@link Connection}.
978b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
979b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * The {@link VideoProvider} should respond by communicating current data usage, in bytes,
980b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * via {@link VideoProvider#setCallDataUsage(long)}.
981b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
982b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
983b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#requestCallDataUsage()}.
984b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
9855c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        public abstract void onRequestConnectionDataUsage();
986b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
987b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
988b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Provides the {@link VideoProvider} with the {@link Uri} of an image to be displayed to
989b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * the peer device when the video signal is paused.
990b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
991b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Sent from the {@link InCallService} via
992b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall#setPauseImage(Uri)}.
993b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
994b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * @param uri URI of image to display.
995b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
99632f24731604fd81289a39619bbc925b65184b505Yorke Lee        public abstract void onSetPauseImage(Uri uri);
997b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
998b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
999b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Used to inform listening {@link InCallService} implementations when the
1000b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProvider} receives a session modification request.
1001b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1002b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Received by the {@link InCallService} via
1003b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall.Callback#onSessionModifyRequestReceived(VideoProfile)},
1004b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
1005b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param videoProfile The requested video profile.
1006b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
1007b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
1008b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public void receiveSessionModifyRequest(VideoProfile videoProfile) {
100975958420f2d294ceda517c2782b294002dc2969fTyler Gunn            if (mVideoCallbacks != null) {
101084f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                for (IVideoCallback callback : mVideoCallbacks.values()) {
101184f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    try {
101275958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        callback.receiveSessionModifyRequest(videoProfile);
101384f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    } catch (RemoteException ignored) {
101484f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        Log.w(this, "receiveSessionModifyRequest callback failed", ignored);
101575958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
1016b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                }
1017b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
1018b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
1019b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
1020b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
1021b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Used to inform listening {@link InCallService} implementations when the
1022b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProvider} receives a response to a session modification request.
1023b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1024b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Received by the {@link InCallService} via
1025b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall.Callback#onSessionModifyResponseReceived(int,
1026b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * VideoProfile, VideoProfile)}.
1027b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
1028b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * @param status Status of the session modify request.  Valid values are
1029b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *               {@link VideoProvider#SESSION_MODIFY_REQUEST_SUCCESS},
1030b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *               {@link VideoProvider#SESSION_MODIFY_REQUEST_FAIL},
1031b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *               {@link VideoProvider#SESSION_MODIFY_REQUEST_INVALID},
1032b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *               {@link VideoProvider#SESSION_MODIFY_REQUEST_TIMED_OUT},
1033b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *               {@link VideoProvider#SESSION_MODIFY_REQUEST_REJECTED_BY_REMOTE}
1034b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param requestedProfile The original request which was sent to the peer device.
1035b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param responseProfile The actual profile changes agreed to by the peer device.
1036b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #onSendSessionModifyRequest(VideoProfile, VideoProfile)
1037b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
1038b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public void receiveSessionModifyResponse(int status,
1039b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                VideoProfile requestedProfile, VideoProfile responseProfile) {
104075958420f2d294ceda517c2782b294002dc2969fTyler Gunn            if (mVideoCallbacks != null) {
104184f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                for (IVideoCallback callback : mVideoCallbacks.values()) {
104284f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    try {
104375958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        callback.receiveSessionModifyResponse(status, requestedProfile,
104475958420f2d294ceda517c2782b294002dc2969fTyler Gunn                                responseProfile);
104584f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    } catch (RemoteException ignored) {
104684f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        Log.w(this, "receiveSessionModifyResponse callback failed", ignored);
104775958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
1048b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                }
1049b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
1050b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
1051542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1052b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
1053b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Used to inform listening {@link InCallService} implementations when the
1054b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProvider} reports a call session event.
1055b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1056b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Received by the {@link InCallService} via
1057b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall.Callback#onCallSessionEvent(int)}.
1058b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
1059b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param event The event.  Valid values are: {@link VideoProvider#SESSION_EVENT_RX_PAUSE},
1060b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProvider#SESSION_EVENT_RX_RESUME},
1061b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProvider#SESSION_EVENT_TX_START},
1062b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProvider#SESSION_EVENT_TX_STOP},
1063b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProvider#SESSION_EVENT_CAMERA_FAILURE},
1064b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProvider#SESSION_EVENT_CAMERA_READY}.
1065b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
1066b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public void handleCallSessionEvent(int event) {
106775958420f2d294ceda517c2782b294002dc2969fTyler Gunn            if (mVideoCallbacks != null) {
106884f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                for (IVideoCallback callback : mVideoCallbacks.values()) {
106984f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    try {
107075958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        callback.handleCallSessionEvent(event);
107184f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    } catch (RemoteException ignored) {
107284f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        Log.w(this, "handleCallSessionEvent callback failed", ignored);
107375958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
1074b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                }
1075b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
1076b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
1077b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
1078b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
1079b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Used to inform listening {@link InCallService} implementations when the dimensions of the
1080b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * peer's video have changed.
1081b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1082b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * This could occur if, for example, the peer rotates their device, changing the aspect
1083b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * ratio of the video, or if the user switches between the back and front cameras.
1084b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1085b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Received by the {@link InCallService} via
1086b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall.Callback#onPeerDimensionsChanged(int, int)}.
1087b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
1088b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * @param width  The updated peer video width.
1089b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         * @param height The updated peer video height.
1090b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
1091b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        public void changePeerDimensions(int width, int height) {
109275958420f2d294ceda517c2782b294002dc2969fTyler Gunn            if (mVideoCallbacks != null) {
109384f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                for (IVideoCallback callback : mVideoCallbacks.values()) {
109484f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    try {
109575958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        callback.changePeerDimensions(width, height);
109684f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    } catch (RemoteException ignored) {
109784f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        Log.w(this, "changePeerDimensions callback failed", ignored);
109875958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
1099b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                }
1100b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
1101b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
1102bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton
1103b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
1104b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Used to inform listening {@link InCallService} implementations when the data usage of the
1105b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * video associated with the current {@link Connection} has changed.
1106b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1107b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * This could be in response to a preview request via
1108b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link #onRequestConnectionDataUsage()}, or as a periodic update by the
1109295f5d7777ba63836bf75cb4de15bdaae06dfc1fTyler Gunn         * {@link VideoProvider}.  Where periodic updates of data usage are provided, they should be
1110295f5d7777ba63836bf75cb4de15bdaae06dfc1fTyler Gunn         * provided at most for every 1 MB of data transferred and no more than once every 10 sec.
1111b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1112b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Received by the {@link InCallService} via
1113b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall.Callback#onCallDataUsageChanged(long)}.
1114b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
1115b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param dataUsage The updated data usage (in bytes).  Reported as the cumulative bytes
1116b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *                  used since the start of the call.
1117b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
111832f24731604fd81289a39619bbc925b65184b505Yorke Lee        public void setCallDataUsage(long dataUsage) {
111975958420f2d294ceda517c2782b294002dc2969fTyler Gunn            if (mVideoCallbacks != null) {
112084f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                for (IVideoCallback callback : mVideoCallbacks.values()) {
112184f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    try {
112275958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        callback.changeCallDataUsage(dataUsage);
112384f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    } catch (RemoteException ignored) {
112484f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        Log.w(this, "setCallDataUsage callback failed", ignored);
112575958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
1126b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                }
1127b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
1128b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
1129b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
1130b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        /**
1131b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @see #setCallDataUsage(long)
1132b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         *
1133b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param dataUsage The updated data usage (in byes).
113432f24731604fd81289a39619bbc925b65184b505Yorke Lee         * @deprecated - Use {@link #setCallDataUsage(long)} instead.
113532f24731604fd81289a39619bbc925b65184b505Yorke Lee         * @hide
113632f24731604fd81289a39619bbc925b65184b505Yorke Lee         */
113732f24731604fd81289a39619bbc925b65184b505Yorke Lee        public void changeCallDataUsage(long dataUsage) {
113832f24731604fd81289a39619bbc925b65184b505Yorke Lee            setCallDataUsage(dataUsage);
113932f24731604fd81289a39619bbc925b65184b505Yorke Lee        }
114032f24731604fd81289a39619bbc925b65184b505Yorke Lee
114132f24731604fd81289a39619bbc925b65184b505Yorke Lee        /**
1142b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Used to inform listening {@link InCallService} implementations when the capabilities of
1143b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * the current camera have changed.
1144b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1145b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * The {@link VideoProvider} should call this in response to
1146b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link VideoProvider#onRequestCameraCapabilities()}, or when the current camera is
1147b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * changed via {@link VideoProvider#onSetCamera(String)}.
1148b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1149b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Received by the {@link InCallService} via
1150b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall.Callback#onCameraCapabilitiesChanged(
1151b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * VideoProfile.CameraCapabilities)}.
115232f24731604fd81289a39619bbc925b65184b505Yorke Lee         *
1153b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param cameraCapabilities The new camera capabilities.
1154b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad         */
1155400470fab932fe3374149ab89386e460ea161002Yorke Lee        public void changeCameraCapabilities(VideoProfile.CameraCapabilities cameraCapabilities) {
115675958420f2d294ceda517c2782b294002dc2969fTyler Gunn            if (mVideoCallbacks != null) {
115784f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                for (IVideoCallback callback : mVideoCallbacks.values()) {
115884f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    try {
115975958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        callback.changeCameraCapabilities(cameraCapabilities);
116084f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    } catch (RemoteException ignored) {
116184f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        Log.w(this, "changeCameraCapabilities callback failed", ignored);
116275958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
1163b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                }
1164b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
1165b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
116607366813cdf3768dcd69a1f744023747564d654aRekha Kumar
116707366813cdf3768dcd69a1f744023747564d654aRekha Kumar        /**
1168b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Used to inform listening {@link InCallService} implementations when the video quality
1169b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * of the call has changed.
1170b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * <p>
1171b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * Received by the {@link InCallService} via
1172b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * {@link InCallService.VideoCall.Callback#onVideoQualityChanged(int)}.
117332f24731604fd81289a39619bbc925b65184b505Yorke Lee         *
1174b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         * @param videoQuality The updated video quality.  Valid values:
1175b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProfile#QUALITY_HIGH},
1176b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProfile#QUALITY_MEDIUM},
1177b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProfile#QUALITY_LOW},
1178b702ef8a91c9adec68b11e36c50b89fd5bcbb607Tyler Gunn         *      {@link VideoProfile#QUALITY_DEFAULT}.
117907366813cdf3768dcd69a1f744023747564d654aRekha Kumar         */
118007366813cdf3768dcd69a1f744023747564d654aRekha Kumar        public void changeVideoQuality(int videoQuality) {
118175958420f2d294ceda517c2782b294002dc2969fTyler Gunn            if (mVideoCallbacks != null) {
118284f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                for (IVideoCallback callback : mVideoCallbacks.values()) {
118384f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    try {
118475958420f2d294ceda517c2782b294002dc2969fTyler Gunn                        callback.changeVideoQuality(videoQuality);
118584f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                    } catch (RemoteException ignored) {
118684f381b4eb9880b929ac40286b17b3f16271666bTyler Gunn                        Log.w(this, "changeVideoQuality callback failed", ignored);
118775958420f2d294ceda517c2782b294002dc2969fTyler Gunn                    }
118807366813cdf3768dcd69a1f744023747564d654aRekha Kumar                }
118907366813cdf3768dcd69a1f744023747564d654aRekha Kumar            }
119007366813cdf3768dcd69a1f744023747564d654aRekha Kumar        }
1191542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1192542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
11937c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    private final Listener mConnectionDeathListener = new Listener() {
11947c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        @Override
11957c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        public void onDestroyed(Connection c) {
11966d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            if (mConferenceables.remove(c)) {
11976d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                fireOnConferenceableConnectionsChanged();
11986d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            }
11996d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        }
12006d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn    };
12016d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn
12026d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn    private final Conference.Listener mConferenceDeathListener = new Conference.Listener() {
12036d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        @Override
12046d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        public void onDestroyed(Conference c) {
12056d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            if (mConferenceables.remove(c)) {
12067c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon                fireOnConferenceableConnectionsChanged();
12077c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon            }
12087c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        }
12097c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    };
12107c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon
1211229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner    /**
1212229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
1213229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     * load factor before resizing, 1 means we only expect a single thread to
1214229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     * access the map so make only a single shard
1215229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     */
1216229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner    private final Set<Listener> mListeners = Collections.newSetFromMap(
1217229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner            new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
1218df2cbc8989e624cd6a1d732549ea4a4f00852508Tyler Gunn    private final List<Conferenceable> mConferenceables = new ArrayList<>();
1219df2cbc8989e624cd6a1d732549ea4a4f00852508Tyler Gunn    private final List<Conferenceable> mUnmodifiableConferenceables =
12206d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            Collections.unmodifiableList(mConferenceables);
1221b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon
1222f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    // The internal telecom call ID associated with this connection.
1223f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    private String mTelecomCallId;
1224b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    private int mState = STATE_NEW;
12254af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    private CallAudioState mCallAudioState;
1226100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    private Uri mAddress;
1227100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    private int mAddressPresentation;
1228612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    private String mCallerDisplayName;
1229612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    private int mCallerDisplayNamePresentation;
1230100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    private boolean mRingbackRequested = false;
12315c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    private int mConnectionCapabilities;
1232720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    private int mConnectionProperties;
1233b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    private VideoProvider mVideoProvider;
123433aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    private boolean mAudioModeIsVoip;
1235e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius    private long mConnectTimeMillis = Conference.CONNECT_TIME_NOT_SPECIFIED;
1236e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    private StatusHints mStatusHints;
1237aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    private int mVideoState;
12387f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee    private DisconnectCause mDisconnectCause;
1239823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private Conference mConference;
1240823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private ConnectionService mConnectionService;
12416b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    private Bundle mExtras;
12424fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger    private final Object mExtrasLock = new Object();
1243542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1244542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1245dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Tracks the key set for the extras bundle provided on the last invocation of
1246dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * {@link #setExtras(Bundle)}.  Used so that on subsequent invocations we can remove any extras
1247dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * keys which were set previously but are no longer present in the replacement Bundle.
1248dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
1249dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    private Set<String> mPreviousExtraKeys;
1250dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1251dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
1252542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Create a new Connection.
1253542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1254f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public Connection() {}
1255542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1256542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1257f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * Returns the Telecom internal call ID associated with this connection.  Should only be used
1258f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * for debugging and tracing purposes.
1259f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     *
1260f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * @return The Telecom call ID.
1261f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * @hide
1262f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     */
1263f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    public final String getTelecomCallId() {
1264f0500bd63571c667df7865d7484c89f671382711Tyler Gunn        return mTelecomCallId;
1265f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    }
1266f0500bd63571c667df7865d7484c89f671382711Tyler Gunn
1267f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    /**
1268100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee     * @return The address (e.g., phone number) to which this Connection is currently communicating.
1269542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1270100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    public final Uri getAddress() {
1271100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        return mAddress;
1272542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1273542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1274542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1275100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee     * @return The presentation requirements for the address.
1276ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunn     *         See {@link TelecomManager} for valid values.
1277542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1278100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    public final int getAddressPresentation() {
1279100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        return mAddressPresentation;
1280612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    }
1281612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal
1282612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    /**
1283612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal     * @return The caller display name (CNAP).
1284612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal     */
1285612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    public final String getCallerDisplayName() {
1286612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        return mCallerDisplayName;
1287612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    }
1288612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal
1289612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    /**
12909d568c01db1f90fbe9cbff1d9385e7e7b809e066Nancy Chen     * @return The presentation requirements for the handle.
1291ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunn     *         See {@link TelecomManager} for valid values.
1292612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal     */
1293612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    public final int getCallerDisplayNamePresentation() {
1294612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        return mCallerDisplayNamePresentation;
1295542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1296542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1297542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1298612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal     * @return The state of this Connection.
12998d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn     */
1300612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    public final int getState() {
1301612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        return mState;
13022a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    }
13038d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn
13048d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn    /**
13055c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Returns the video state of the connection.
130632f24731604fd81289a39619bbc925b65184b505Yorke Lee     * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
130732f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_BIDIRECTIONAL},
130832f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_TX_ENABLED},
130932f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_RX_ENABLED}.
1310aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     *
13115c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return The video state of the connection.
131227d1e257f3cba2d5954e5562db69035df9ecf290Tyler Gunn     * @hide
1313aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     */
1314aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    public final int getVideoState() {
1315aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn        return mVideoState;
1316aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    }
1317aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn
1318aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    /**
13195c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return The audio state of the connection, describing how its audio is currently
1320542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *         being routed by the system. This is {@code null} if this Connection
1321542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *         does not directly know about its audio state.
13224af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @deprecated Use {@link #getCallAudioState()} instead.
13234af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @hide
1324542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
13254af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @SystemApi
13264af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @Deprecated
1327b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public final AudioState getAudioState() {
1328000d38ab3ce46ad9ba4d99694c4d1bf46dff9cbfSailesh Nepal        if (mCallAudioState == null) {
1329000d38ab3ce46ad9ba4d99694c4d1bf46dff9cbfSailesh Nepal          return null;
1330000d38ab3ce46ad9ba4d99694c4d1bf46dff9cbfSailesh Nepal        }
13314af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        return new AudioState(mCallAudioState);
13324af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    }
13334af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee
13344af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    /**
13354af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @return The audio state of the connection, describing how its audio is currently
13364af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     *         being routed by the system. This is {@code null} if this Connection
13374af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     *         does not directly know about its audio state.
13384af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     */
13394af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    public final CallAudioState getCallAudioState() {
13404af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        return mCallAudioState;
1341542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1342542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1343542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1344823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @return The conference that this connection is a part of.  Null if it is not part of any
1345823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *         conference.
13462a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal     */
1347823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final Conference getConference() {
1348823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        return mConference;
13492a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    }
13502a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal
13512a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    /**
1352823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Returns whether this connection is requesting that the system play a ringback tone
1353823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * on its behalf.
13542a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal     */
1355100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    public final boolean isRingbackRequested() {
1356100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        return mRingbackRequested;
13572a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    }
13582a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal
13592a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    /**
136033aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     * @return True if the connection's audio mode is VOIP.
136133aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     */
136233aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    public final boolean getAudioModeIsVoip() {
136333aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal        return mAudioModeIsVoip;
136433aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    }
136533aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal
136633aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    /**
1367e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * Retrieves the connection start time of the {@code Connnection}, if specified.  A value of
1368e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * {@link Conference#CONNECT_TIME_NOT_SPECIFIED} indicates that Telecom should determine the
1369e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * start time of the conference.
1370e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     *
1371e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * @return The time at which the {@code Connnection} was connected.
1372e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     *
1373e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * @hide
1374e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     */
1375e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius    public final long getConnectTimeMillis() {
1376e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius        return mConnectTimeMillis;
1377e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius    }
1378e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius
1379e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius    /**
1380e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal     * @return The status hints for this connection.
1381e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal     */
1382e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    public final StatusHints getStatusHints() {
1383e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal        return mStatusHints;
1384e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    }
1385e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal
1386e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    /**
1387dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Returns the extras associated with this connection.
1388dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
13896b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * @return The extras associated with this connection.
13906b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     */
13916b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    public final Bundle getExtras() {
13924fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        Bundle extras = null;
13934fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        synchronized (mExtrasLock) {
13944fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            if (mExtras != null) {
13954fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger                extras = new Bundle(mExtras);
13964fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            }
13974fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        }
13984fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        return extras;
13996b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    }
14006b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon
14016b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    /**
1402542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Assign a listener to be notified of state changes.
1403542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
1404542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @param l A listener.
1405542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @return This Connection.
1406542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
1407542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @hide
1408542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1409542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    public final Connection addConnectionListener(Listener l) {
1410d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        mListeners.add(l);
1411542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad        return this;
1412542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1413542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1414542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1415542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Remove a previously assigned listener that was being notified of state changes.
1416542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
1417542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @param l A Listener.
1418542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @return This Connection.
1419542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
1420542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @hide
1421542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1422542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    public final Connection removeConnectionListener(Listener l) {
1423229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner        if (l != null) {
1424229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner            mListeners.remove(l);
1425229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner        }
1426542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad        return this;
1427542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1428542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1429542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1430cf7020b7e84c1f5190db7167d70cb0675cd3332fSailesh Nepal     * @return The {@link DisconnectCause} for this connection.
1431bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     */
14327f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee    public final DisconnectCause getDisconnectCause() {
1433cf7020b7e84c1f5190db7167d70cb0675cd3332fSailesh Nepal        return mDisconnectCause;
1434bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    }
1435bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton
1436bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    /**
1437f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * Sets the telecom call ID associated with this Connection.  The Telecom Call ID should be used
1438f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * ONLY for debugging purposes.
1439f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     *
1440f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * @param callId The telecom call ID.
1441f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     * @hide
1442f0500bd63571c667df7865d7484c89f671382711Tyler Gunn     */
1443f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    public void setTelecomCallId(String callId) {
1444f0500bd63571c667df7865d7484c89f671382711Tyler Gunn        mTelecomCallId = callId;
1445f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    }
1446f0500bd63571c667df7865d7484c89f671382711Tyler Gunn
1447f0500bd63571c667df7865d7484c89f671382711Tyler Gunn    /**
1448542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Inform this Connection that the state of its audio output has been changed externally.
1449542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
1450542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @param state The new audio state.
1451400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal     * @hide
1452542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
14534af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    final void setCallAudioState(CallAudioState state) {
14545c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
145560ac30bb8a30fa7283d592c12ddf2da9447adf14Ihab Awad        Log.d(this, "setAudioState %s", state);
14564af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        mCallAudioState = state;
14574af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        onAudioStateChanged(getAudioState());
14584af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee        onCallAudioStateChanged(state);
1459542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1460542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1461542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1462b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * @param state An integer value of a {@code STATE_*} constant.
1463542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @return A string representation of the value.
1464542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1465542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    public static String stateToString(int state) {
1466542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad        switch (state) {
1467b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            case STATE_INITIALIZING:
1468e911c8d19662b7eaee07ffa4bfe8822d51c9ee21Yorke Lee                return "INITIALIZING";
1469b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            case STATE_NEW:
1470e911c8d19662b7eaee07ffa4bfe8822d51c9ee21Yorke Lee                return "NEW";
1471b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            case STATE_RINGING:
1472e911c8d19662b7eaee07ffa4bfe8822d51c9ee21Yorke Lee                return "RINGING";
1473b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            case STATE_DIALING:
1474e911c8d19662b7eaee07ffa4bfe8822d51c9ee21Yorke Lee                return "DIALING";
1475b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            case STATE_ACTIVE:
1476e911c8d19662b7eaee07ffa4bfe8822d51c9ee21Yorke Lee                return "ACTIVE";
1477b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            case STATE_HOLDING:
1478e911c8d19662b7eaee07ffa4bfe8822d51c9ee21Yorke Lee                return "HOLDING";
1479b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            case STATE_DISCONNECTED:
1480542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad                return "DISCONNECTED";
1481542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad            default:
148260ac30bb8a30fa7283d592c12ddf2da9447adf14Ihab Awad                Log.wtf(Connection.class, "Unknown state %d", state);
1483542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad                return "UNKNOWN";
1484542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad        }
1485542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1486542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1487542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
14885c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.
148952a28f619fca8c2118e1f421cb56f6542805e954Ihab Awad     */
14905c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public final int getConnectionCapabilities() {
14915c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        return mConnectionCapabilities;
149252a28f619fca8c2118e1f421cb56f6542805e954Ihab Awad    }
149352a28f619fca8c2118e1f421cb56f6542805e954Ihab Awad
149452a28f619fca8c2118e1f421cb56f6542805e954Ihab Awad    /**
1495720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Returns the connection's properties, as a bit mask of the {@code PROPERTY_*} constants.
14961bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
1497720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     */
1498720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public final int getConnectionProperties() {
1499720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        return mConnectionProperties;
1500720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    }
1501720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
1502720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    /**
1503100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee     * Sets the value of the {@link #getAddress()} property.
1504542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
1505100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee     * @param address The new address.
1506100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee     * @param presentation The presentation requirements for the address.
1507ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunn     *        See {@link TelecomManager} for valid values.
1508542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1509100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    public final void setAddress(Uri address, int presentation) {
15105c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1511100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        Log.d(this, "setAddress %s", address);
1512100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        mAddress = address;
1513100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        mAddressPresentation = presentation;
1514d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
1515100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee            l.onAddressChanged(this, address, presentation);
1516d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1517542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1518542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1519542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1520612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal     * Sets the caller display name (CNAP).
15212a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal     *
1522612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal     * @param callerDisplayName The new display name.
15239d568c01db1f90fbe9cbff1d9385e7e7b809e066Nancy Chen     * @param presentation The presentation requirements for the handle.
1524ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunn     *        See {@link TelecomManager} for valid values.
1525612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal     */
1526612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    public final void setCallerDisplayName(String callerDisplayName, int presentation) {
15275c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1528612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        Log.d(this, "setCallerDisplayName %s", callerDisplayName);
1529d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        mCallerDisplayName = callerDisplayName;
1530d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        mCallerDisplayNamePresentation = presentation;
1531d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
1532d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
1533d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
15342a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    }
15352a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal
15362a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    /**
1537aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     * Set the video state for the connection.
153832f24731604fd81289a39619bbc925b65184b505Yorke Lee     * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY},
153932f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_BIDIRECTIONAL},
154032f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_TX_ENABLED},
154132f24731604fd81289a39619bbc925b65184b505Yorke Lee     * {@link VideoProfile#STATE_RX_ENABLED}.
1542aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     *
1543aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     * @param videoState The new video state.
1544aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     */
1545aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    public final void setVideoState(int videoState) {
15465c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1547aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn        Log.d(this, "setVideoState %d", videoState);
1548d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        mVideoState = videoState;
1549d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
1550d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            l.onVideoStateChanged(this, mVideoState);
1551d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1552aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    }
1553aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn
1554aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    /**
15555c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Sets state to active (e.g., an ongoing connection where two or more parties can actively
1556542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * communicate).
1557542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1558400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal    public final void setActive() {
15595c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1560100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        setRingbackRequested(false);
1561b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        setState(STATE_ACTIVE);
1562542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1563542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1564542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
15655c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Sets state to ringing (e.g., an inbound ringing connection).
1566542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1567400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal    public final void setRinging() {
15685c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1569b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        setState(STATE_RINGING);
1570542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1571542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1572542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1573bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     * Sets state to initializing (this Connection is not yet ready to be used).
1574bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     */
1575bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    public final void setInitializing() {
15765c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1577b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        setState(STATE_INITIALIZING);
1578bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    }
1579bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton
1580bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    /**
1581bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     * Sets state to initialized (the Connection has been set up and is now ready to be used).
1582bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     */
1583bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    public final void setInitialized() {
15845c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1585b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        setState(STATE_NEW);
1586bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    }
1587bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton
1588bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    /**
15895c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Sets state to dialing (e.g., dialing an outbound connection).
1590542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1591400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal    public final void setDialing() {
15925c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1593b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        setState(STATE_DIALING);
1594542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1595542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1596542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
1597542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Sets state to be on hold.
1598542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
1599400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal    public final void setOnHold() {
16005c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1601b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        setState(STATE_HOLDING);
1602542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1603542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1604542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
16055c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Sets the video connection provider.
1606b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * @param videoProvider The video provider.
16075ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee     */
1608b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public final void setVideoProvider(VideoProvider videoProvider) {
16095c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1610b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        mVideoProvider = videoProvider;
1611d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
1612b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            l.onVideoProviderChanged(this, videoProvider);
1613d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
16145ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee    }
16155ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee
1616b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public final VideoProvider getVideoProvider() {
1617b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        return mVideoProvider;
1618a27a1938ab27aeb17144867b231f830622fa6ad4Andrew Lee    }
1619a27a1938ab27aeb17144867b231f830622fa6ad4Andrew Lee
16205ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee    /**
1621091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal     * Sets state to disconnected.
1622542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
16237f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     * @param disconnectCause The reason for the disconnection, as specified by
1624b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     *         {@link DisconnectCause}.
1625542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
16267f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee    public final void setDisconnected(DisconnectCause disconnectCause) {
16275c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
16287f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee        mDisconnectCause = disconnectCause;
1629b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        setState(STATE_DISCONNECTED);
1630f34519b4dd12d065c510b06922a196e8a3fd9885mike dooley        Log.d(this, "Disconnected with cause %s", disconnectCause);
1631d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
16327f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee            l.onDisconnected(this, disconnectCause);
1633d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1634542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
1635542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
1636542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
16375c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Informs listeners that this {@code Connection} is in a post-dial wait state. This is done
16385c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait"
16395c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user
16405c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * to send an {@link #onPostDialContinue(boolean)} signal.
16415c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
16425c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param remaining The DTMF character sequence remaining to be emitted once the
16435c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *         {@link #onPostDialContinue(boolean)} is received, including any "wait" characters
16445c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *         that remaining sequence may contain.
1645091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal     */
1646091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal    public final void setPostDialWait(String remaining) {
16475c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1648d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
1649d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            l.onPostDialWait(this, remaining);
1650d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1651091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal    }
1652091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal
1653091768c3021d740b7d66846d36405c4d4c76cc56Sailesh Nepal    /**
165427d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen     * Informs listeners that this {@code Connection} has processed a character in the post-dial
165527d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen     * started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence;
16561ed8561ac65b9d8eb3d9f32b0830a60442aa1c49Sailesh Nepal     * and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.
165727d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen     *
165827d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen     * @param nextChar The DTMF character that was just processed by the {@code Connection}.
165927d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen     */
16601ed8561ac65b9d8eb3d9f32b0830a60442aa1c49Sailesh Nepal    public final void setNextPostDialChar(char nextChar) {
166127d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen        checkImmutable();
166227d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen        for (Listener l : mListeners) {
166327d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen            l.onPostDialChar(this, nextChar);
166427d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen        }
166527d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen    }
166627d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen
166727d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen    /**
1668f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     * Requests that the framework play a ringback tone. This is to be invoked by implementations
16695c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * that do not play a ringback tone themselves in the connection's audio stream.
1670f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     *
1671f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     * @param ringback Whether the ringback tone is to be played.
1672f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     */
1673100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    public final void setRingbackRequested(boolean ringback) {
16745c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1675100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee        if (mRingbackRequested != ringback) {
1676100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee            mRingbackRequested = ringback;
1677d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            for (Listener l : mListeners) {
1678100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee                l.onRingbackRequested(this, ringback);
1679d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            }
1680d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1681f835897f9f799490de27653ae39141ba6bc14223Ihab Awad    }
1682f835897f9f799490de27653ae39141ba6bc14223Ihab Awad
1683f835897f9f799490de27653ae39141ba6bc14223Ihab Awad    /**
16845c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.
16851a7061ba950538c93d92c0448752a212039cc06aSailesh Nepal     *
16865c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param connectionCapabilities The new connection capabilities.
1687b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     */
16885c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public final void setConnectionCapabilities(int connectionCapabilities) {
16895c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
16905c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        if (mConnectionCapabilities != connectionCapabilities) {
16915c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad            mConnectionCapabilities = connectionCapabilities;
1692d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            for (Listener l : mListeners) {
16935c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad                l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
1694d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            }
1695d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1696b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon    }
1697b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon
1698b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon    /**
1699720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * Sets the connection's properties as a bit mask of the {@code PROPERTY_*} constants.
1700720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     *
1701720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * @param connectionProperties The new connection properties.
17021bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
1703720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     */
1704720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    public final void setConnectionProperties(int connectionProperties) {
1705720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        checkImmutable();
1706720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        if (mConnectionProperties != connectionProperties) {
1707720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            mConnectionProperties = connectionProperties;
1708720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            for (Listener l : mListeners) {
1709720c664401081ca00e56c7eef12641ae792da530Tyler Gunn                l.onConnectionPropertiesChanged(this, mConnectionProperties);
1710720c664401081ca00e56c7eef12641ae792da530Tyler Gunn            }
1711720c664401081ca00e56c7eef12641ae792da530Tyler Gunn        }
1712720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    }
1713720c664401081ca00e56c7eef12641ae792da530Tyler Gunn
1714720c664401081ca00e56c7eef12641ae792da530Tyler Gunn    /**
17157c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon     * Tears down the Connection object.
1716b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     */
171736a713431ceda2e5462c5dc5d1300f32acf9e63aEvan Charlton    public final void destroy() {
1718229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner        for (Listener l : mListeners) {
1719229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner            l.onDestroyed(this);
1720d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1721b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon    }
1722b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon
1723b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon    /**
172433aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     * Requests that the framework use VOIP audio mode for this connection.
172533aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     *
172633aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     * @param isVoip True if the audio mode is VOIP.
172733aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     */
172833aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    public final void setAudioModeIsVoip(boolean isVoip) {
17295c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1730d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        mAudioModeIsVoip = isVoip;
1731d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
1732d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            l.onAudioModeIsVoipChanged(this, isVoip);
1733d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
173433aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    }
173533aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal
173633aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    /**
1737e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * Sets the time at which a call became active on this Connection. This is set only
1738e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * when a conference call becomes active on this connection.
1739e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     *
1740e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * @param connectionTimeMillis The connection time, in milliseconds.
1741e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     *
1742e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     * @hide
1743e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius     */
1744e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius    public final void setConnectTimeMillis(long connectTimeMillis) {
1745e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius        mConnectTimeMillis = connectTimeMillis;
1746e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius    }
1747e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius
1748e927ec02f5bbad925d5f28cbe370a04aa118f370Roshan Pius    /**
1749e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal     * Sets the label and icon status to display in the in-call UI.
1750e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal     *
1751e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal     * @param statusHints The status label and icon to set.
1752e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal     */
1753e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    public final void setStatusHints(StatusHints statusHints) {
17545c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1755d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        mStatusHints = statusHints;
1756d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        for (Listener l : mListeners) {
1757d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon            l.onStatusHintsChanged(this, statusHints);
1758d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon        }
1759e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    }
1760e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal
1761e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    /**
17627c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon     * Sets the connections with which this connection can be conferenced.
17637c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon     *
17647c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon     * @param conferenceableConnections The set of connections this connection can conference with.
17657c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon     */
17667c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    public final void setConferenceableConnections(List<Connection> conferenceableConnections) {
17675c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
17687c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        clearConferenceableList();
17697c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        for (Connection c : conferenceableConnections) {
17707c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon            // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
17717c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon            // small amount of items here.
17726d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            if (!mConferenceables.contains(c)) {
17737c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon                c.addConnectionListener(mConnectionDeathListener);
17746d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                mConferenceables.add(c);
17757c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon            }
17767c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        }
17777c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        fireOnConferenceableConnectionsChanged();
17787c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    }
17797c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon
17807c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    /**
17816d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn     * Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections
17826d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn     * or conferences with which this connection can be conferenced.
17836d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn     *
17846d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn     * @param conferenceables The conferenceables.
1785b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     */
1786df2cbc8989e624cd6a1d732549ea4a4f00852508Tyler Gunn    public final void setConferenceables(List<Conferenceable> conferenceables) {
17876d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        clearConferenceableList();
1788df2cbc8989e624cd6a1d732549ea4a4f00852508Tyler Gunn        for (Conferenceable c : conferenceables) {
17896d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
17906d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            // small amount of items here.
17916d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            if (!mConferenceables.contains(c)) {
17926d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                if (c instanceof Connection) {
17936d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                    Connection connection = (Connection) c;
17946d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                    connection.addConnectionListener(mConnectionDeathListener);
17956d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                } else if (c instanceof Conference) {
17966d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                    Conference conference = (Conference) c;
17976d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                    conference.addListener(mConferenceDeathListener);
17986d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                }
17996d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                mConferenceables.add(c);
18006d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            }
18016d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        }
18026d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        fireOnConferenceableConnectionsChanged();
18036d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn    }
18046d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn
18056d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn    /**
18066d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn     * Returns the connections or conferences with which this connection can be conferenced.
18076d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn     */
1808df2cbc8989e624cd6a1d732549ea4a4f00852508Tyler Gunn    public final List<Conferenceable> getConferenceables() {
18096d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        return mUnmodifiableConferenceables;
1810b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    }
1811b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
18125346396ba2077a8bd03da1adde46db6b39669ac9Yorke Lee    /**
1813823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @hide
1814823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
1815823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final void setConnectionService(ConnectionService connectionService) {
18165c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1817823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (mConnectionService != null) {
1818823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
1819823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                    "which is already associated with another ConnectionService.");
1820823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        } else {
1821823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            mConnectionService = connectionService;
1822823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
1823823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
1824823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
1825823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
1826823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @hide
1827823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
1828823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final void unsetConnectionService(ConnectionService connectionService) {
1829823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (mConnectionService != connectionService) {
1830823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
1831823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                    "that does not belong to the ConnectionService.");
1832823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        } else {
1833823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            mConnectionService = null;
1834823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
1835823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
1836823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
1837823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
1838af1b296a41f0b6e3af34e9c2c73bc1029bfa8b2aSantos Cordon     * @hide
1839af1b296a41f0b6e3af34e9c2c73bc1029bfa8b2aSantos Cordon     */
1840af1b296a41f0b6e3af34e9c2c73bc1029bfa8b2aSantos Cordon    public final ConnectionService getConnectionService() {
1841af1b296a41f0b6e3af34e9c2c73bc1029bfa8b2aSantos Cordon        return mConnectionService;
1842af1b296a41f0b6e3af34e9c2c73bc1029bfa8b2aSantos Cordon    }
1843af1b296a41f0b6e3af34e9c2c73bc1029bfa8b2aSantos Cordon
1844af1b296a41f0b6e3af34e9c2c73bc1029bfa8b2aSantos Cordon    /**
1845823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Sets the conference that this connection is a part of. This will fail if the connection is
18465c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * already part of a conference. {@link #resetConference} to un-set the conference first.
1847823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     *
1848823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @param conference The conference.
1849823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @return {@code true} if the conference was successfully set.
1850823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @hide
1851823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
1852823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final boolean setConference(Conference conference) {
18535c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
1854823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        // We check to see if it is already part of another conference.
18550159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon        if (mConference == null) {
1856823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            mConference = conference;
18570159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon            if (mConnectionService != null && mConnectionService.containsConference(conference)) {
18580159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon                fireConferenceChanged();
18590159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon            }
1860823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            return true;
1861823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
1862823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        return false;
1863823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
1864823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
1865823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    /**
1866823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * Resets the conference that this connection is a part of.
1867823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     * @hide
1868823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon     */
1869823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    public final void resetConference() {
1870823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        if (mConference != null) {
18710159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon            Log.d(this, "Conference reset");
1872823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            mConference = null;
1873823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            fireConferenceChanged();
1874823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
1875823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
1876823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
1877b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    /**
1878dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Set some extras that can be associated with this {@code Connection}.
1879dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * <p>
1880dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * New or existing keys are replaced in the {@code Connection} extras.  Keys which are no longer
1881dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * in the new extras, but were present the last time {@code setExtras} was called are removed.
1882dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * <p>
1883dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * No assumptions should be made as to how an In-Call UI or service will handle these extras.
18846b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
18856b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     *
18866b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     * @param extras The extras associated with this {@code Connection}.
18876b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon     */
18886b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    public final void setExtras(@Nullable Bundle extras) {
18896b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        checkImmutable();
1890dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1891dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        // Add/replace any new or changed extras values.
1892dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        putExtras(extras);
1893dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1894dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        // If we have used "setExtras" in the past, compare the key set from the last invocation to
1895dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        // the current one and remove any keys that went away.
1896dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        if (mPreviousExtraKeys != null) {
1897dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            List<String> toRemove = new ArrayList<String>();
1898dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            for (String oldKey : mPreviousExtraKeys) {
1899a8fb8aba7ce464a9d42f4e4ac42f76aa90d050e9Tyler Gunn                if (extras == null || !extras.containsKey(oldKey)) {
1900dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn                    toRemove.add(oldKey);
1901dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn                }
1902dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            }
1903dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            if (!toRemove.isEmpty()) {
1904dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn                removeExtras(toRemove);
1905dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            }
1906dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        }
1907dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1908dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        // Track the keys the last time set called setExtras.  This way, the next time setExtras is
1909dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        // called we can see if the caller has removed any extras values.
1910dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        if (mPreviousExtraKeys == null) {
1911dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            mPreviousExtraKeys = new ArraySet<String>();
1912dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        }
1913dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        mPreviousExtraKeys.clear();
1914a8fb8aba7ce464a9d42f4e4ac42f76aa90d050e9Tyler Gunn        if (extras != null) {
1915a8fb8aba7ce464a9d42f4e4ac42f76aa90d050e9Tyler Gunn            mPreviousExtraKeys.addAll(extras.keySet());
1916a8fb8aba7ce464a9d42f4e4ac42f76aa90d050e9Tyler Gunn        }
1917dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    }
1918dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1919dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
1920dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Adds some extras to this {@code Connection}.  Existing keys are replaced and new ones are
1921dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * added.
1922dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * <p>
1923dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * No assumptions should be made as to how an In-Call UI or service will handle these extras.
1924dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.
1925dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
1926dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param extras The extras to add.
19271bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
1928dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
1929dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    public final void putExtras(@NonNull Bundle extras) {
1930dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        checkImmutable();
1931dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        if (extras == null) {
1932dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            return;
1933dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        }
19344fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        // Creating a duplicate bundle so we don't have to synchronize on mExtrasLock while calling
19354fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        // the listeners.
19364fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        Bundle listenerExtras;
19374fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        synchronized (mExtrasLock) {
19384fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            if (mExtras == null) {
19394fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger                mExtras = new Bundle();
19404fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            }
19414fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            mExtras.putAll(extras);
19424fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            listenerExtras = new Bundle(mExtras);
1943dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        }
19446b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        for (Listener l : mListeners) {
19454fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            // Create a new clone of the extras for each listener so that they don't clobber
19464fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            // each other
19474fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            l.onExtrasChanged(this, new Bundle(listenerExtras));
19486b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon        }
19496b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    }
19506b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon
19516b7f955c2d9b231660b8c54f8ef8e8e6ad802625Santos Cordon    /**
1952dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Adds a boolean extra to this {@code Connection}.
1953dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
1954dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param key The extra key.
1955dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param value The value.
1956dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @hide
1957dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
1958dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    public final void putExtra(String key, boolean value) {
1959dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        Bundle newExtras = new Bundle();
1960dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        newExtras.putBoolean(key, value);
1961dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        putExtras(newExtras);
1962dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    }
1963dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1964dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
1965dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Adds an integer extra to this {@code Connection}.
1966dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
1967dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param key The extra key.
1968dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param value The value.
1969dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @hide
1970dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
1971dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    public final void putExtra(String key, int value) {
1972dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        Bundle newExtras = new Bundle();
1973dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        newExtras.putInt(key, value);
1974dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        putExtras(newExtras);
1975dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    }
1976dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1977dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
1978dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Adds a string extra to this {@code Connection}.
1979dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
1980dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param key The extra key.
1981dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param value The value.
1982dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @hide
1983dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
1984dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    public final void putExtra(String key, String value) {
1985dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        Bundle newExtras = new Bundle();
1986dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        newExtras.putString(key, value);
1987dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        putExtras(newExtras);
1988dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    }
1989dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
1990dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
1991dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Removes an extra from this {@code Connection}.
1992dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
1993dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param keys The key of the extra key to remove.
19941bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
1995dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
1996dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    public final void removeExtras(List<String> keys) {
19974fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        synchronized (mExtrasLock) {
19984fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            if (mExtras != null) {
19994fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger                for (String key : keys) {
20004fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger                    mExtras.remove(key);
20014fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger                }
2002dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn            }
2003dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        }
20044fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        List<String> unmodifiableKeys = Collections.unmodifiableList(keys);
2005dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        for (Listener l : mListeners) {
20064fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            l.onExtrasRemoved(this, unmodifiableKeys);
2007dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn        }
2008dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    }
2009dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
2010dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
2011b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * Notifies this Connection that the {@link #getAudioState()} property has a new value.
2012400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal     *
20135c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param state The new connection audio state.
20144af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @deprecated Use {@link #onCallAudioStateChanged(CallAudioState)} instead.
20154af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @hide
2016400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal     */
20174af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @SystemApi
20184af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    @Deprecated
2019354b2bd0fe8647bd5c7e28f3598b9b7414846124Nancy Chen    public void onAudioStateChanged(AudioState state) {}
2020400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal
2021400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal    /**
20224af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * Notifies this Connection that the {@link #getCallAudioState()} property has a new value.
20234af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     *
20244af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     * @param state The new connection audio state.
20254af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee     */
20264af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    public void onCallAudioStateChanged(CallAudioState state) {}
20274af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee
20284af5935c71f1e31ef1aec27661c4ef60545a0924Yorke Lee    /**
2029bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     * Notifies this Connection of an internal state change. This method is called after the
2030bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     * state is changed.
2031f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     *
2032b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * @param state The new state, one of the {@code STATE_*} constants.
2033f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     */
2034354b2bd0fe8647bd5c7e28f3598b9b7414846124Nancy Chen    public void onStateChanged(int state) {}
2035f835897f9f799490de27653ae39141ba6bc14223Ihab Awad
2036f835897f9f799490de27653ae39141ba6bc14223Ihab Awad    /**
2037542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Notifies this Connection of a request to play a DTMF tone.
2038542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     *
2039542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * @param c A DTMF character.
2040542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2041f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onPlayDtmfTone(char c) {}
2042542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
2043542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
2044542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Notifies this Connection of a request to stop any currently playing DTMF tones.
2045542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2046f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onStopDtmfTone() {}
2047542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
2048542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
2049542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Notifies this Connection of a request to disconnect.
2050542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2051f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onDisconnect() {}
2052542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
2053542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
20543b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn     * Notifies this Connection of a request to disconnect a participant of the conference managed
20553b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn     * by the connection.
20563b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn     *
20573b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn     * @param endpoint the {@link Uri} of the participant to disconnect.
20583b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn     * @hide
20593b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn     */
20603b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn    public void onDisconnectConferenceParticipant(Uri endpoint) {}
20613b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn
20623b4b1dcb607b8932374a4bc8c9ab349b9bb68660Tyler Gunn    /**
20637c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon     * Notifies this Connection of a request to separate from its parent conference.
2064b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     */
2065f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onSeparate() {}
2066b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon
2067b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon    /**
2068542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Notifies this Connection of a request to abort.
2069542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2070f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onAbort() {}
2071542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
2072542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
2073542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Notifies this Connection of a request to hold.
2074542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2075f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onHold() {}
2076542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
2077542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
2078542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     * Notifies this Connection of a request to exit a hold state.
2079542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2080f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onUnhold() {}
2081542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
2082542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
2083b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2084d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon     * a request to accept.
20858da4c3c11faf066b2b04ba853f03be6f1c4af5d8Andrew Lee     *
20865c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @param videoState The video state in which to answer the connection.
2087542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2088f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onAnswer(int videoState) {}
2089542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
2090542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    /**
2091b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2092be74de0978a7eaa577f6b61902b550a3161aff8bTyler Gunn     * a request to accept.
2093be74de0978a7eaa577f6b61902b550a3161aff8bTyler Gunn     */
2094be74de0978a7eaa577f6b61902b550a3161aff8bTyler Gunn    public void onAnswer() {
209587b73f370e2b8a76b0540580f43edba6ec21c6cfTyler Gunn        onAnswer(VideoProfile.STATE_AUDIO_ONLY);
2096be74de0978a7eaa577f6b61902b550a3161aff8bTyler Gunn    }
2097be74de0978a7eaa577f6b61902b550a3161aff8bTyler Gunn
2098be74de0978a7eaa577f6b61902b550a3161aff8bTyler Gunn    /**
2099be74de0978a7eaa577f6b61902b550a3161aff8bTyler Gunn     * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2100d34e5713c9571859d12e9c2e83ce3946cacdd68eSantos Cordon     * a request to reject.
2101542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad     */
2102f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onReject() {}
2103542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad
21046dea4aceba8f69ee4be346ec356d277a3c153f3dEvan Charlton    /**
2105712acbe13c76b2274b34d7ca40c4bbcc436b0cdaHall Liu     * Notifies this Connection, which is in {@link #STATE_RINGING}, of
2106712acbe13c76b2274b34d7ca40c4bbcc436b0cdaHall Liu     * a request to reject with a message.
21078190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee     */
21088190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee    public void onReject(String replyMessage) {}
21098190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee
21108190168077aa3ef02a1f5a3a636130d83c4eec1dBryce Lee    /**
2111cac50775b2e13c293d224b8d09feb15f9ee40c3fBryce Lee     * Notifies the Connection of a request to silence the ringer.
2112cac50775b2e13c293d224b8d09feb15f9ee40c3fBryce Lee     *
2113cac50775b2e13c293d224b8d09feb15f9ee40c3fBryce Lee     * @hide
2114cac50775b2e13c293d224b8d09feb15f9ee40c3fBryce Lee     */
2115cac50775b2e13c293d224b8d09feb15f9ee40c3fBryce Lee    public void onSilence() {}
2116cac50775b2e13c293d224b8d09feb15f9ee40c3fBryce Lee
2117cac50775b2e13c293d224b8d09feb15f9ee40c3fBryce Lee    /**
21186dea4aceba8f69ee4be346ec356d277a3c153f3dEvan Charlton     * Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
21196dea4aceba8f69ee4be346ec356d277a3c153f3dEvan Charlton     */
2120f29511043e1c3bf750e28427410192c793363bf7Santos Cordon    public void onPostDialContinue(boolean proceed) {}
21216dea4aceba8f69ee4be346ec356d277a3c153f3dEvan Charlton
2122876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    /**
2123876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Notifies this Connection of a request to pull an external call to the local device.
2124876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
2125876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * The {@link InCallService} issues a request to pull an external call to the local device via
2126876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * {@link Call#pullExternalCall()}.
2127876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
2128720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * For a Connection to be pulled, both the {@link Connection#CAPABILITY_CAN_PULL_CALL}
2129720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * capability and {@link Connection#PROPERTY_IS_EXTERNAL_CALL} property bits must be set.
2130876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
2131720c664401081ca00e56c7eef12641ae792da530Tyler Gunn     * For more information on external calls, see {@link Connection#PROPERTY_IS_EXTERNAL_CALL}.
21321bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
2133876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     */
2134876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    public void onPullExternalCall() {}
2135876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn
2136876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    /**
2137876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Notifies this Connection of a {@link Call} event initiated from an {@link InCallService}.
2138876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
2139876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * The {@link InCallService} issues a Call event via {@link Call#sendCallEvent(String, Bundle)}.
2140876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * <p>
2141876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * See also {@link Call#sendCallEvent(String, Bundle)}.
2142876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     *
2143876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * @param event The call event.
2144876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * @param extras Extras associated with the call event.
21451bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
2146876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     */
2147876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    public void onCallEvent(String event, Bundle extras) {}
2148876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn
2149dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
2150dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Notifies this {@link Connection} of a change to the extras made outside the
2151dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * {@link ConnectionService}.
2152dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * <p>
2153dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * These extras changes can originate from Telecom itself, or from an {@link InCallService} via
2154dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * the {@link android.telecom.Call#putExtras(Bundle)} and
2155dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * {@link Call#removeExtras(List)}.
2156dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
2157dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param extras The new extras bundle.
21581bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
2159dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
2160dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    public void onExtrasChanged(Bundle extras) {}
2161dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
2162b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    static String toLogSafePhoneNumber(String number) {
2163b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        // For unknown number, log empty string.
2164b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        if (number == null) {
2165b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            return "";
2166b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
2167b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
2168b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        if (PII_DEBUG) {
2169b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            // When PII_DEBUG is true we emit PII.
2170b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            return number;
2171b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
2172b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
2173b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
2174b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        // sanitized phone numbers.
2175b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        StringBuilder builder = new StringBuilder();
2176b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        for (int i = 0; i < number.length(); i++) {
2177b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            char c = number.charAt(i);
2178b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            if (c == '-' || c == '@' || c == '.') {
2179b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                builder.append(c);
2180b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            } else {
2181b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                builder.append('x');
2182b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            }
2183b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        }
2184b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad        return builder.toString();
2185b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    }
2186b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad
2187542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    private void setState(int state) {
21885c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        checkImmutable();
21896107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad        if (mState == STATE_DISCONNECTED && mState != state) {
21906107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad            Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
2191bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton            return;
2192400cc48512dc69e940ad4d233a3b47ee9574601dSailesh Nepal        }
2193bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton        if (mState != state) {
2194bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton            Log.d(this, "setState: %s", stateToString(state));
2195bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton            mState = state;
2196354b2bd0fe8647bd5c7e28f3598b9b7414846124Nancy Chen            onStateChanged(state);
2197bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton            for (Listener l : mListeners) {
2198bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton                l.onStateChanged(this, state);
2199bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton            }
2200bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton        }
2201bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    }
2202bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton
2203cf7020b7e84c1f5190db7167d70cb0675cd3332fSailesh Nepal    private static class FailureSignalingConnection extends Connection {
220490e34e324cbe22f18680809cbc33caf63b320cb4Ihab Awad        private boolean mImmutable = false;
22057f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee        public FailureSignalingConnection(DisconnectCause disconnectCause) {
22067f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee            setDisconnected(disconnectCause);
220790e34e324cbe22f18680809cbc33caf63b320cb4Ihab Awad            mImmutable = true;
22086107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad        }
22095c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
22105c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        public void checkImmutable() {
221190e34e324cbe22f18680809cbc33caf63b320cb4Ihab Awad            if (mImmutable) {
221290e34e324cbe22f18680809cbc33caf63b320cb4Ihab Awad                throw new UnsupportedOperationException("Connection is immutable");
221390e34e324cbe22f18680809cbc33caf63b320cb4Ihab Awad            }
22145c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad        }
22156107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad    }
22166107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad
2217bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    /**
22186107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * Return a {@code Connection} which represents a failed connection attempt. The returned
22197f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     * {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified,
22207f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     * and a {@link #getState()} of {@link #STATE_DISCONNECTED}.
22216107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * <p>
22226107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * The returned {@code Connection} can be assumed to {@link #destroy()} itself when appropriate,
22236107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * so users of this method need not maintain a reference to its return value to destroy it.
2224bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     *
22257f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     * @param disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
22266107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * @return A {@code Connection} which indicates failure.
2227bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     */
22287f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee    public static Connection createFailedConnection(DisconnectCause disconnectCause) {
22297f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee        return new FailureSignalingConnection(disconnectCause);
2230bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    }
2231bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton
2232bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton    /**
22335c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is
22345c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * not intended to be mutated, e.g., if it is a marker for failure. Only for framework use;
22355c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * this should never be un-@hide-den.
22365c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     *
22375c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @hide
22385c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     */
22395c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    public void checkImmutable() {}
22405c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad
22415c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    /**
22426107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * Return a {@code Connection} which represents a canceled connection attempt. The returned
22436107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of
22446107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * that state. This connection should not be used for anything, and no other
22456107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * {@code Connection}s should be attempted.
22466107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * <p>
22476107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad     * so users of this method need not maintain a reference to its return value to destroy it.
2248bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     *
22495c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * @return A {@code Connection} which indicates that the underlying connection should
22505c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad     * be canceled.
2251bf11f98deb09ef54ff4161fba75d22b1a0a458eeEvan Charlton     */
2252b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    public static Connection createCanceledConnection() {
22537f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee        return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
2254542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad    }
22557c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon
22565c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    private final void fireOnConferenceableConnectionsChanged() {
22577c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        for (Listener l : mListeners) {
22586d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            l.onConferenceablesChanged(this, getConferenceables());
22597c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        }
22607c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    }
22617c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon
2262823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    private final void fireConferenceChanged() {
2263823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        for (Listener l : mListeners) {
2264823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon            l.onConferenceChanged(this, mConference);
2265823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon        }
2266823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    }
2267823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon
22687c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    private final void clearConferenceableList() {
2269df2cbc8989e624cd6a1d732549ea4a4f00852508Tyler Gunn        for (Conferenceable c : mConferenceables) {
22706d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            if (c instanceof Connection) {
22716d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                Connection connection = (Connection) c;
22726d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                connection.removeConnectionListener(mConnectionDeathListener);
22736d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            } else if (c instanceof Conference) {
22746d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                Conference conference = (Conference) c;
22756d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn                conference.removeListener(mConferenceDeathListener);
22766d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn            }
22777c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        }
22786d76ca0438c2cb7a7d5d91992db819c063c0a57bTyler Gunn        mConferenceables.clear();
22797c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    }
22803bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn
22813bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn    /**
2282dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * Handles a change to extras received from Telecom.
2283dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     *
2284dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @param extras The new extras.
2285dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     * @hide
2286dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn     */
2287dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    final void handleExtrasChanged(Bundle extras) {
22884fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        Bundle b = null;
22894fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        synchronized (mExtrasLock) {
22904fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            mExtras = extras;
22914fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            if (mExtras != null) {
22924fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger                b = new Bundle(mExtras);
22934fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger            }
22944fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        }
22954fa6a01898be85999e12b62bb52debb838e1bd0cBrad Ebinger        onExtrasChanged(b);
2296dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    }
2297dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn
2298dee56a8a79f9daa1e597f5d4f399d3a5feedcac4Tyler Gunn    /**
229917455a3d39350a39eb995897929977d793358365Anthony Lee     * Notifies listeners that the merge request failed.
230017455a3d39350a39eb995897929977d793358365Anthony Lee     *
230117455a3d39350a39eb995897929977d793358365Anthony Lee     * @hide
230217455a3d39350a39eb995897929977d793358365Anthony Lee     */
230317455a3d39350a39eb995897929977d793358365Anthony Lee    protected final void notifyConferenceMergeFailed() {
230417455a3d39350a39eb995897929977d793358365Anthony Lee        for (Listener l : mListeners) {
230517455a3d39350a39eb995897929977d793358365Anthony Lee            l.onConferenceMergeFailed(this);
230617455a3d39350a39eb995897929977d793358365Anthony Lee        }
230717455a3d39350a39eb995897929977d793358365Anthony Lee    }
230817455a3d39350a39eb995897929977d793358365Anthony Lee
230917455a3d39350a39eb995897929977d793358365Anthony Lee    /**
2310ab4650c4563cd46e65ac37f924fee8febfd759c6Tyler Gunn     * Notifies listeners of a change to conference participant(s).
23113bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn     *
2312ab4650c4563cd46e65ac37f924fee8febfd759c6Tyler Gunn     * @param conferenceParticipants The participants.
23133bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn     * @hide
23143bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn     */
2315ab4650c4563cd46e65ac37f924fee8febfd759c6Tyler Gunn    protected final void updateConferenceParticipants(
2316ab4650c4563cd46e65ac37f924fee8febfd759c6Tyler Gunn            List<ConferenceParticipant> conferenceParticipants) {
23173bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn        for (Listener l : mListeners) {
2318ab4650c4563cd46e65ac37f924fee8febfd759c6Tyler Gunn            l.onConferenceParticipantsChanged(this, conferenceParticipants);
23193bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn        }
23203bffcf78b5e4bd8b60543126fc0bdb09808f28f5Tyler Gunn    }
23218a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn
23228a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn    /**
23238a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn     * Notifies listeners that a conference call has been started.
232455b97525f0f50857f1ab0acd2608053fd0f3416cJay Shrauner     * @hide
23258a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn     */
23268a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn    protected void notifyConferenceStarted() {
23278a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn        for (Listener l : mListeners) {
23288a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn            l.onConferenceStarted();
23298a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn        }
23308a2b1199a6db0c6f2493e96e25ec1d89e3f62769Tyler Gunn    }
2331bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn
2332bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn    /**
2333876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Sends an event associated with this {@code Connection}, with associated event extras.
2334876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     *
2335876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Events are exposed to {@link InCallService} implementations via the
2336876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * {@link Call.Callback#onConnectionEvent(Call, String, Bundle)} API.
2337876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     *
2338876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * No assumptions should be made as to how an In-Call UI or service will handle these events.
2339876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * Events should be fully qualified (e.g., com.example.event.MY_EVENT) to avoid conflicts.
2340bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     *
2341bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     * @param event The connection event.
2342876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn     * @param extras Bundle containing extra information associated with the event.
23431bf206b766654ea9c4e9bc7a703a9d5f1d30ab72Tyler Gunn     * @hide
2344bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn     */
2345876dbfb4767da4a2ba5459d5b78fb6eb55e4516fTyler Gunn    public void sendConnectionEvent(String event, Bundle extras) {
2346bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn        for (Listener l : mListeners) {
2347a8fb8aba7ce464a9d42f4e4ac42f76aa90d050e9Tyler Gunn            l.onConnectionEvent(this, event, extras);
2348bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn        }
2349bd1eb1f105e99d55fe87d758e8eafbe55a221a30Tyler Gunn    }
2350542e0ea8bfa60f09c33e4be366adf8681c25d0bfIhab Awad}
2351