1bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad/*
2ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal * Copyright (C) 2014 The Android Open Source Project
3bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad *
4bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * Licensed under the Apache License, Version 2.0 (the "License");
5bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * you may not use this file except in compliance with the License.
6bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * You may obtain a copy of the License at
7bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad *
8bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad *      http://www.apache.org/licenses/LICENSE-2.0
9bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad *
10bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * Unless required by applicable law or agreed to in writing, software
11bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * distributed under the License is distributed on an "AS IS" BASIS,
12bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * See the License for the specific language governing permissions and
14bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad * limitations under the License.
15bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad */
16bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
17ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnpackage android.telecom;
18bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
19612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepalimport android.net.Uri;
2052d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordonimport android.os.IBinder.DeathRecipient;
21ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepalimport android.os.RemoteException;
22ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal
23ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnimport com.android.internal.telecom.IConnectionServiceAdapter;
24ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunnimport com.android.internal.telecom.RemoteServiceCallback;
25bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
26b0c0e36faf5b4218f290e95584528a41c1f22f21Jay Shraunerimport java.util.Collections;
274dd9df58a6bf662264f0aebddfb14b850358f9b9Sailesh Nepalimport java.util.Iterator;
28980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordonimport java.util.List;
2952d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordonimport java.util.Set;
30b0c0e36faf5b4218f290e95584528a41c1f22f21Jay Shraunerimport java.util.concurrent.ConcurrentHashMap;
31980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon
32bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad/**
332a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal * Provides methods for IConnectionService implementations to interact with the system phone app.
342bed9563edbec63ad41e2cd5fccc205d5b0891e5Sailesh Nepal *
352bed9563edbec63ad41e2cd5fccc205d5b0891e5Sailesh Nepal * @hide
36bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad */
372a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepalfinal class ConnectionServiceAdapter implements DeathRecipient {
38229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner    /**
39229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
40229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     * load factor before resizing, 1 means we only expect a single thread to
41229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     * access the map so make only a single shard
42229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner     */
43b0c0e36faf5b4218f290e95584528a41c1f22f21Jay Shrauner    private final Set<IConnectionServiceAdapter> mAdapters = Collections.newSetFromMap(
44229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner            new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(8, 0.9f, 1));
45ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal
462a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    ConnectionServiceAdapter() {
4752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    }
4852d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon
492a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void addAdapter(IConnectionServiceAdapter adapter) {
5052d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon        if (mAdapters.add(adapter)) {
5152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
5252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.asBinder().linkToDeath(this, 0);
5352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
5452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                mAdapters.remove(adapter);
5552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
5652d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon        }
5752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    }
5852d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon
592a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void removeAdapter(IConnectionServiceAdapter adapter) {
60229e3820dce98f64fd4834d5f421faec9a9d7026Jay Shrauner        if (adapter != null && mAdapters.remove(adapter)) {
6152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            adapter.asBinder().unlinkToDeath(this, 0);
6252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon        }
6352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    }
6452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon
6552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    /** ${inheritDoc} */
6652d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    @Override
6752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    public void binderDied() {
684dd9df58a6bf662264f0aebddfb14b850358f9b9Sailesh Nepal        Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
694dd9df58a6bf662264f0aebddfb14b850358f9b9Sailesh Nepal        while (it.hasNext()) {
704dd9df58a6bf662264f0aebddfb14b850358f9b9Sailesh Nepal            IConnectionServiceAdapter adapter = it.next();
7152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            if (!adapter.asBinder().isBinderAlive()) {
724dd9df58a6bf662264f0aebddfb14b850358f9b9Sailesh Nepal                it.remove();
734dd9df58a6bf662264f0aebddfb14b850358f9b9Sailesh Nepal                adapter.asBinder().unlinkToDeath(this, 0);
7452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
7552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon        }
76ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal    }
77bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
786107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad    void handleCreateConnectionComplete(
79b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            String id,
80b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            ConnectionRequest request,
81b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            ParcelableConnection connection) {
822a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
8352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
846107bab041fb7d851fbf865b7310d294aae970c8Ihab Awad                adapter.handleCreateConnectionComplete(id, request, connection);
85506e38690fe5e3b627e243fdc20948c514b87680Sailesh Nepal            } catch (RemoteException e) {
86506e38690fe5e3b627e243fdc20948c514b87680Sailesh Nepal            }
87506e38690fe5e3b627e243fdc20948c514b87680Sailesh Nepal        }
88ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal    }
89bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
90bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad    /**
91bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     * Sets a call's state to active (e.g., an ongoing call where two parties can actively
92bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     * communicate).
933784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     *
943784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     * @param callId The unique ID of the call whose state is changing to active.
95bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     */
962a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void setActive(String callId) {
972a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
9852d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
9952d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.setActive(callId);
10052d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
10152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
102ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal        }
103ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal    }
104bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
105bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad    /**
106bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     * Sets a call's state to ringing (e.g., an inbound ringing call).
1073784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     *
1083784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     * @param callId The unique ID of the call whose state is changing to ringing.
109bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     */
1102a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void setRinging(String callId) {
1112a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
11252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
11352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.setRinging(callId);
11452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
11552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
116ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal        }
117ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal    }
118bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
119bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad    /**
120bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     * Sets a call's state to dialing (e.g., dialing an outbound call).
1213784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     *
1223784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     * @param callId The unique ID of the call whose state is changing to dialing.
123bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     */
1242a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void setDialing(String callId) {
1252a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
12652d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
12752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.setDialing(callId);
12852d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
12952d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
130ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal        }
131ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal    }
132bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad
133bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad    /**
134bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     * Sets a call's state to disconnected.
1353784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     *
1363784133b95f1206c0c6bbbddb5921ef396b5b941Santos Cordon     * @param callId The unique ID of the call whose state is changing to disconnected.
1377f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     * @param disconnectCause The reason for the disconnection, as described by
1387f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee     *            {@link android.telecomm.DisconnectCause}.
139bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad     */
1407f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee    void setDisconnected(String callId, DisconnectCause disconnectCause) {
1412a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
14252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
1437f3d41fd124dd7c4a8b72c1d48df08a8ee7209ecAndrew Lee                adapter.setDisconnected(callId, disconnectCause);
14452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
14552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
146ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal        }
147ab5d282dd6f487578ae86b2d53d0d8edc9b71747Sailesh Nepal    }
14881ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee
14981ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee    /**
15081ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee     * Sets a call's state to be on hold.
15181ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee     *
15281ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee     * @param callId - The unique ID of the call whose state is changing to be on hold.
15381ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee     */
1542a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void setOnHold(String callId) {
1552a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
15652d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
15752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.setOnHold(callId);
15852d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
15952d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
16081ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee        }
16181ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee    }
16281ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee
163f835897f9f799490de27653ae39141ba6bc14223Ihab Awad    /**
164ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunn     * Asks Telecom to start or stop a ringback tone for a call.
165f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     *
166f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     * @param callId The unique ID of the call whose ringback is being changed.
167ef9f6f957d897ea0ed82114185b8fa3fefd4917bTyler Gunn     * @param ringback Whether Telecom should start playing a ringback tone.
168f835897f9f799490de27653ae39141ba6bc14223Ihab Awad     */
169100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    void setRingbackRequested(String callId, boolean ringback) {
1702a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
17152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
172100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee                adapter.setRingbackRequested(callId, ringback);
17352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
17452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
175f835897f9f799490de27653ae39141ba6bc14223Ihab Awad        }
176f835897f9f799490de27653ae39141ba6bc14223Ihab Awad    }
17781ccaaa25cc90c576c7df7c2cccb8a232e8536a1Yorke Lee
1785c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad    void setConnectionCapabilities(String callId, int capabilities) {
1792a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
18052d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
1815c9c86ec0f95d1f5e1aca212967f508fc736b895Ihab Awad                adapter.setConnectionCapabilities(callId, capabilities);
18252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException ignored) {
18352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
184980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon        }
185980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon    }
186980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon
187980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon    /**
188980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     * Indicates whether or not the specified call is currently conferenced into the specified
189980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     * conference call.
190980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     *
191980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     * @param callId The unique ID of the call being conferenced.
192b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     * @param conferenceCallId The unique ID of the conference call. Null if call is not
19352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon     *            conferenced.
194980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     */
1952a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void setIsConferenced(String callId, String conferenceCallId) {
1962a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
19752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
1980159ac0cfe20e8f85ee4150e64d91392850f8a3fSantos Cordon                Log.d(this, "sending connection %s with conference %s", callId, conferenceCallId);
19952d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.setIsConferenced(callId, conferenceCallId);
20052d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException ignored) {
20152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
202980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon        }
203980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon    }
204980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon
205980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon    /**
206980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     * Indicates that the call no longer exists. Can be used with either a call or a conference
207980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     * call.
208980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     *
209980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     * @param callId The unique ID of the call.
210980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon     */
2112a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void removeCall(String callId) {
2122a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
21352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
21452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.removeCall(callId);
21552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException ignored) {
21652d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
217980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon        }
218980acb9bd6984a9daad5f584bd35e8d503820200Santos Cordon    }
2196dea4aceba8f69ee4be346ec356d277a3c153f3dEvan Charlton
2202a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void onPostDialWait(String callId, String remaining) {
2212a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
22252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
22352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                adapter.onPostDialWait(callId, remaining);
22452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException ignored) {
22552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
2266dea4aceba8f69ee4be346ec356d277a3c153f3dEvan Charlton        }
2276dea4aceba8f69ee4be346ec356d277a3c153f3dEvan Charlton    }
2288b4818d9b4d632f2d460e7ac9dea463b04db43feSailesh Nepal
22927d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen    void onPostDialChar(String callId, char nextChar) {
23027d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen        for (IConnectionServiceAdapter adapter : mAdapters) {
23127d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen            try {
23227d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen                adapter.onPostDialChar(callId, nextChar);
23327d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen            } catch (RemoteException ignored) {
23427d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen            }
23527d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen        }
23627d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen    }
23727d1c2d148fe377ca0d2744f0f85789a42c8f808Nancy Chen
2388b4818d9b4d632f2d460e7ac9dea463b04db43feSailesh Nepal    /**
239b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     * Indicates that a new conference call has been created.
240b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     *
241b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     * @param callId The unique ID of the conference call.
242b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon     */
243823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon    void addConferenceCall(String callId, ParcelableConference parcelableConference) {
2442a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
24552d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
246823fd3c79dd4f762bbc778e0ce9e2204b6d3d454Santos Cordon                adapter.addConferenceCall(callId, parcelableConference);
24752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException ignored) {
24852d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
24952d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon        }
25052d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    }
25152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon
25252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon    /**
25352d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon     * Retrieves a list of remote connection services usable to place calls.
25452d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon     */
2552a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal    void queryRemoteConnectionServices(RemoteServiceCallback callback) {
25652d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon        // Only supported when there is only one adapter.
25752d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon        if (mAdapters.size() == 1) {
25852d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            try {
25952d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                mAdapters.iterator().next().queryRemoteConnectionServices(callback);
26052d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            } catch (RemoteException e) {
26152d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon                Log.e(this, e, "Exception trying to query for remote CSs");
26252d8a15e146e682319380322f94ceb6d93fa1a97Santos Cordon            }
263b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon        }
264b693998fdfdd4498a33c4c69405f2708e4840aa7Santos Cordon    }
2655ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee
2665ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee    /**
2675ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee     * Sets the call video provider for a call.
2685ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee     *
2695ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee     * @param callId The unique ID of the call to set with the given call video provider.
270b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * @param videoProvider The call video provider instance to set on the call.
2715ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee     */
272b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad    void setVideoProvider(
273b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad            String callId, Connection.VideoProvider videoProvider) {
2742a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
2755ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee            try {
276b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                adapter.setVideoProvider(
277e8dc4bef00e391defbdee0264b2ed955b1117841Santos Cordon                        callId,
278b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad                        videoProvider == null ? null : videoProvider.getInterface());
2795ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee            } catch (RemoteException e) {
2805ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee            }
2815ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee        }
2825ffbe8b850c2703b64617f0140d051a5412dd861Andrew Lee    }
2838d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn
2848d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn    /**
28533aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     * Requests that the framework use VOIP audio mode for this connection.
28633aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     *
28733aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     * @param callId The unique ID of the call to set with the given call video provider.
28833aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     * @param isVoip True if the audio mode is VOIP.
28933aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal     */
290100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    void setIsVoipAudioMode(String callId, boolean isVoip) {
29133aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
29233aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal            try {
293100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee                adapter.setIsVoipAudioMode(callId, isVoip);
29433aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal            } catch (RemoteException e) {
29533aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal            }
29633aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal        }
29733aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal    }
29833aaae4a07fdcce223fe74d96d751f4bffa6723aSailesh Nepal
299e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    void setStatusHints(String callId, StatusHints statusHints) {
300e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
301e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal            try {
302e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal                adapter.setStatusHints(callId, statusHints);
303e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal            } catch (RemoteException e) {
304e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal            }
305e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal        }
306e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal    }
307e7ef59a77d55c9802cc7d919f7dd794bd5fea30eSailesh Nepal
308100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee    void setAddress(String callId, Uri address, int presentation) {
3092a46b90222e5c9c73de012382a604a71f9c0c30cSailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
3108d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn            try {
311100e293fa8021caed956597daa4e01cb19be1c33Andrew Lee                adapter.setAddress(callId, address, presentation);
312612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal            } catch (RemoteException e) {
313612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal            }
314612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        }
315612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    }
316612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal
317612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal    void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
318612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal        for (IConnectionServiceAdapter adapter : mAdapters) {
319612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal            try {
320612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal                adapter.setCallerDisplayName(callId, callerDisplayName, presentation);
321612038642fa9cf1545dbcc8274d313192ce928b5Sailesh Nepal            } catch (RemoteException e) {
3228d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn            }
3238d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn        }
3248d83fa9bbd2ad15299a4419241eb10404e7839beTyler Gunn    }
325aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn
326aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    /**
327aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     * Sets the video state associated with a call.
328aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     *
329b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY},
330b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * {@link VideoProfile.VideoState#BIDIRECTIONAL},
331b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * {@link VideoProfile.VideoState#TX_ENABLED},
332b19a0bcdd8a5020c61a0d697f600fdc943c86f59Ihab Awad     * {@link VideoProfile.VideoState#RX_ENABLED}.
333aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     *
334aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     * @param callId The unique ID of the call to set the video state for.
335aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     * @param videoState The video state.
336aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn     */
337aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    void setVideoState(String callId, int videoState) {
338aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn        Log.v(this, "setVideoState: %d", videoState);
339aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn        for (IConnectionServiceAdapter adapter : mAdapters) {
340aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn            try {
341aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn                adapter.setVideoState(callId, videoState);
342aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn            } catch (RemoteException ignored) {
343aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn            }
344aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn        }
345aa07df84f279a87ad6370758c9d792a660f2cebbTyler Gunn    }
3462ab88cc313fc4af7fb9436e236cd3a5d1ac58478Sailesh Nepal
3477c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    void setConferenceableConnections(String callId, List<String> conferenceableCallIds) {
3487c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        Log.v(this, "setConferenceableConnections: %s, %s", callId, conferenceableCallIds);
3497c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        for (IConnectionServiceAdapter adapter : mAdapters) {
3507c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon            try {
3517c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon                adapter.setConferenceableConnections(callId, conferenceableCallIds);
3527c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon            } catch (RemoteException ignored) {
3537c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon            }
3547c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon        }
3557c7bc7f6917484250974c5da00af9ef756844b0aSantos Cordon    }
3564a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn
3574a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn    /**
3584a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     * Informs telecom of an existing connection which was added by the {@link ConnectionService}.
3594a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     *
3604a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     * @param callId The unique ID of the call being added.
3614a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     * @param connection The connection.
3624a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn     */
3634a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn    void addExistingConnection(String callId, ParcelableConnection connection) {
3644a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn        Log.v(this, "addExistingConnection: %s", callId);
3654a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn        for (IConnectionServiceAdapter adapter : mAdapters) {
3664a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn            try {
3674a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn                adapter.addExistingConnection(callId, connection);
3684a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn            } catch (RemoteException ignored) {
3694a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn            }
3704a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn        }
3714a57b9b59b74c97e559a301af0add13cd4c3331cTyler Gunn    }
372bb69b0c2d821a9806fb00037284c399cbc78277dBen Gilad}
373