Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 18 | |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 19 | import android.annotation.SdkConstant; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 20 | import android.app.Service; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 22 | import android.content.Intent; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 25 | import android.os.Handler; |
| 26 | import android.os.IBinder; |
| 27 | import android.os.Looper; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 28 | import android.os.Message; |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 29 | import android.os.ParcelFileDescriptor; |
| 30 | import android.os.RemoteException; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 31 | import android.telecom.Logging.Session; |
Andrew Lee | 1418576 | 2014-07-25 09:41:56 -0700 | [diff] [blame] | 32 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 33 | import com.android.internal.os.SomeArgs; |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 34 | import com.android.internal.telecom.IConnectionService; |
| 35 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 36 | import com.android.internal.telecom.RemoteServiceCallback; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 37 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 38 | import java.util.ArrayList; |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 39 | import java.util.Collection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 40 | import java.util.Collections; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 41 | import java.util.List; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 42 | import java.util.Map; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 43 | import java.util.UUID; |
mike dooley | 95e8070 | 2014-09-18 14:07:52 -0700 | [diff] [blame] | 44 | import java.util.concurrent.ConcurrentHashMap; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 45 | |
| 46 | /** |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 47 | * An abstract service that should be implemented by any apps which either: |
| 48 | * <ol> |
| 49 | * <li>Can make phone calls (VoIP or otherwise) and want those calls to be integrated into the |
| 50 | * built-in phone app. Referred to as a <b>system managed</b> {@link ConnectionService}.</li> |
| 51 | * <li>Are a standalone calling app and don't want their calls to be integrated into the |
| 52 | * built-in phone app. Referred to as a <b>self managed</b> {@link ConnectionService}.</li> |
| 53 | * </ol> |
| 54 | * Once implemented, the {@link ConnectionService} needs to take the following steps so that Telecom |
| 55 | * will bind to it: |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 56 | * <p> |
| 57 | * 1. <i>Registration in AndroidManifest.xml</i> |
| 58 | * <br/> |
| 59 | * <pre> |
| 60 | * <service android:name="com.example.package.MyConnectionService" |
| 61 | * android:label="@string/some_label_for_my_connection_service" |
Yorke Lee | 249c12e | 2015-05-13 15:59:29 -0700 | [diff] [blame] | 62 | * android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"> |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 63 | * <intent-filter> |
| 64 | * <action android:name="android.telecom.ConnectionService" /> |
| 65 | * </intent-filter> |
| 66 | * </service> |
| 67 | * </pre> |
| 68 | * <p> |
| 69 | * 2. <i> Registration of {@link PhoneAccount} with {@link TelecomManager}.</i> |
| 70 | * <br/> |
| 71 | * See {@link PhoneAccount} and {@link TelecomManager#registerPhoneAccount} for more information. |
| 72 | * <p> |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 73 | * System managed {@link ConnectionService}s must be enabled by the user in the phone app settings |
| 74 | * before Telecom will bind to them. Self-manged {@link ConnectionService}s must be granted the |
| 75 | * appropriate permission before Telecom will bind to them. |
| 76 | * <p> |
| 77 | * Once registered and enabled by the user in the phone app settings or granted permission, telecom |
| 78 | * will bind to a {@link ConnectionService} implementation when it wants that |
| 79 | * {@link ConnectionService} to place a call or the service has indicated that is has an incoming |
| 80 | * call through {@link TelecomManager#addNewIncomingCall}. The {@link ConnectionService} can then |
| 81 | * expect a call to {@link #onCreateIncomingConnection} or {@link #onCreateOutgoingConnection} |
| 82 | * wherein it should provide a new instance of a {@link Connection} object. It is through this |
| 83 | * {@link Connection} object that telecom receives state updates and the {@link ConnectionService} |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 84 | * receives call-commands such as answer, reject, hold and disconnect. |
| 85 | * <p> |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 86 | * When there are no more live calls, telecom will unbind from the {@link ConnectionService}. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 87 | */ |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 88 | public abstract class ConnectionService extends Service { |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 89 | /** |
| 90 | * The {@link Intent} that must be declared as handled by the service. |
| 91 | */ |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 92 | @SdkConstant(SdkConstant.SdkConstantType.SERVICE_ACTION) |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 93 | public static final String SERVICE_INTERFACE = "android.telecom.ConnectionService"; |
Santos Cordon | 5c6fa95 | 2014-07-20 17:47:12 -0700 | [diff] [blame] | 94 | |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 95 | /** |
| 96 | * Boolean extra used by Telecom to inform a {@link ConnectionService} that the purpose of it |
| 97 | * being asked to create a new outgoing {@link Connection} is to perform a handover of an |
| 98 | * ongoing call on the device from another {@link PhoneAccount}/{@link ConnectionService}. Will |
| 99 | * be specified in the {@link ConnectionRequest#getExtras()} passed by Telecom when |
| 100 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} is called. |
| 101 | * <p> |
Tyler Gunn | 727c6bd | 2017-04-11 09:51:40 -0700 | [diff] [blame] | 102 | * When your {@link ConnectionService} receives this extra, it should communicate the fact that |
| 103 | * this is a handover to the other device's matching {@link ConnectionService}. That |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 104 | * {@link ConnectionService} will continue the handover using |
| 105 | * {@link TelecomManager#addNewIncomingCall(PhoneAccountHandle, Bundle)}, specifying |
Tyler Gunn | 727c6bd | 2017-04-11 09:51:40 -0700 | [diff] [blame] | 106 | * {@link TelecomManager#EXTRA_IS_HANDOVER}. Telecom will match the phone numbers of the |
| 107 | * handover call on the other device with ongoing calls for {@link ConnectionService}s which |
| 108 | * support {@link PhoneAccount#EXTRA_SUPPORTS_HANDOVER_FROM}. |
Tyler Gunn | 8bf7657 | 2017-04-06 15:30:08 -0700 | [diff] [blame] | 109 | * @hide |
| 110 | */ |
| 111 | public static final String EXTRA_IS_HANDOVER = TelecomManager.EXTRA_IS_HANDOVER; |
| 112 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 113 | // Flag controlling whether PII is emitted into the logs |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 114 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 115 | |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 116 | // Session Definitions |
| 117 | private static final String SESSION_HANDLER = "H."; |
| 118 | private static final String SESSION_ADD_CS_ADAPTER = "CS.aCSA"; |
| 119 | private static final String SESSION_REMOVE_CS_ADAPTER = "CS.rCSA"; |
| 120 | private static final String SESSION_CREATE_CONN = "CS.crCo"; |
Tyler Gunn | 041a1fe | 2017-05-12 10:04:49 -0700 | [diff] [blame] | 121 | private static final String SESSION_CREATE_CONN_COMPLETE = "CS.crCoC"; |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 122 | private static final String SESSION_CREATE_CONN_FAILED = "CS.crCoF"; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 123 | private static final String SESSION_ABORT = "CS.ab"; |
| 124 | private static final String SESSION_ANSWER = "CS.an"; |
| 125 | private static final String SESSION_ANSWER_VIDEO = "CS.anV"; |
| 126 | private static final String SESSION_REJECT = "CS.r"; |
| 127 | private static final String SESSION_REJECT_MESSAGE = "CS.rWM"; |
| 128 | private static final String SESSION_SILENCE = "CS.s"; |
| 129 | private static final String SESSION_DISCONNECT = "CS.d"; |
| 130 | private static final String SESSION_HOLD = "CS.h"; |
| 131 | private static final String SESSION_UNHOLD = "CS.u"; |
| 132 | private static final String SESSION_CALL_AUDIO_SC = "CS.cASC"; |
| 133 | private static final String SESSION_PLAY_DTMF = "CS.pDT"; |
| 134 | private static final String SESSION_STOP_DTMF = "CS.sDT"; |
| 135 | private static final String SESSION_CONFERENCE = "CS.c"; |
| 136 | private static final String SESSION_SPLIT_CONFERENCE = "CS.sFC"; |
| 137 | private static final String SESSION_MERGE_CONFERENCE = "CS.mC"; |
| 138 | private static final String SESSION_SWAP_CONFERENCE = "CS.sC"; |
| 139 | private static final String SESSION_POST_DIAL_CONT = "CS.oPDC"; |
| 140 | private static final String SESSION_PULL_EXTERNAL_CALL = "CS.pEC"; |
| 141 | private static final String SESSION_SEND_CALL_EVENT = "CS.sCE"; |
| 142 | private static final String SESSION_EXTRAS_CHANGED = "CS.oEC"; |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 143 | private static final String SESSION_START_RTT = "CS.+RTT"; |
| 144 | private static final String SESSION_STOP_RTT = "CS.-RTT"; |
| 145 | private static final String SESSION_RTT_UPGRADE_RESPONSE = "CS.rTRUR"; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 146 | |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 147 | private static final int MSG_ADD_CONNECTION_SERVICE_ADAPTER = 1; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 148 | private static final int MSG_CREATE_CONNECTION = 2; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 149 | private static final int MSG_ABORT = 3; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 150 | private static final int MSG_ANSWER = 4; |
| 151 | private static final int MSG_REJECT = 5; |
| 152 | private static final int MSG_DISCONNECT = 6; |
| 153 | private static final int MSG_HOLD = 7; |
| 154 | private static final int MSG_UNHOLD = 8; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 155 | private static final int MSG_ON_CALL_AUDIO_STATE_CHANGED = 9; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 156 | private static final int MSG_PLAY_DTMF_TONE = 10; |
| 157 | private static final int MSG_STOP_DTMF_TONE = 11; |
| 158 | private static final int MSG_CONFERENCE = 12; |
| 159 | private static final int MSG_SPLIT_FROM_CONFERENCE = 13; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 160 | private static final int MSG_ON_POST_DIAL_CONTINUE = 14; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 161 | private static final int MSG_REMOVE_CONNECTION_SERVICE_ADAPTER = 16; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 162 | private static final int MSG_ANSWER_VIDEO = 17; |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 163 | private static final int MSG_MERGE_CONFERENCE = 18; |
| 164 | private static final int MSG_SWAP_CONFERENCE = 19; |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 165 | private static final int MSG_REJECT_WITH_MESSAGE = 20; |
Bryce Lee | cac5077 | 2015-11-17 15:13:29 -0800 | [diff] [blame] | 166 | private static final int MSG_SILENCE = 21; |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 167 | private static final int MSG_PULL_EXTERNAL_CALL = 22; |
| 168 | private static final int MSG_SEND_CALL_EVENT = 23; |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 169 | private static final int MSG_ON_EXTRAS_CHANGED = 24; |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 170 | private static final int MSG_CREATE_CONNECTION_FAILED = 25; |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 171 | private static final int MSG_ON_START_RTT = 26; |
| 172 | private static final int MSG_ON_STOP_RTT = 27; |
| 173 | private static final int MSG_RTT_UPGRADE_RESPONSE = 28; |
Tyler Gunn | 041a1fe | 2017-05-12 10:04:49 -0700 | [diff] [blame] | 174 | private static final int MSG_CREATE_CONNECTION_COMPLETE = 29; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 175 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 176 | private static Connection sNullConnection; |
| 177 | |
mike dooley | 95e8070 | 2014-09-18 14:07:52 -0700 | [diff] [blame] | 178 | private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>(); |
| 179 | private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>(); |
| 180 | private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>(); |
| 181 | private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>(); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 182 | private final RemoteConnectionManager mRemoteConnectionManager = |
| 183 | new RemoteConnectionManager(this); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 184 | private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 185 | private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 186 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 187 | private boolean mAreAccountsInitialized = false; |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 188 | private Conference sNullConference; |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 189 | private Object mIdSyncRoot = new Object(); |
| 190 | private int mId = 0; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 191 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 192 | private final IBinder mBinder = new IConnectionService.Stub() { |
| 193 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 194 | public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter, |
| 195 | Session.Info sessionInfo) { |
| 196 | Log.startSession(sessionInfo, SESSION_ADD_CS_ADAPTER); |
| 197 | try { |
| 198 | SomeArgs args = SomeArgs.obtain(); |
| 199 | args.arg1 = adapter; |
| 200 | args.arg2 = Log.createSubsession(); |
| 201 | mHandler.obtainMessage(MSG_ADD_CONNECTION_SERVICE_ADAPTER, args).sendToTarget(); |
| 202 | } finally { |
| 203 | Log.endSession(); |
| 204 | } |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 207 | public void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter, |
| 208 | Session.Info sessionInfo) { |
| 209 | Log.startSession(sessionInfo, SESSION_REMOVE_CS_ADAPTER); |
| 210 | try { |
| 211 | SomeArgs args = SomeArgs.obtain(); |
| 212 | args.arg1 = adapter; |
| 213 | args.arg2 = Log.createSubsession(); |
| 214 | mHandler.obtainMessage(MSG_REMOVE_CONNECTION_SERVICE_ADAPTER, args).sendToTarget(); |
| 215 | } finally { |
| 216 | Log.endSession(); |
| 217 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | @Override |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 221 | public void createConnection( |
| 222 | PhoneAccountHandle connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 223 | String id, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 224 | ConnectionRequest request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 225 | boolean isIncoming, |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 226 | boolean isUnknown, |
| 227 | Session.Info sessionInfo) { |
| 228 | Log.startSession(sessionInfo, SESSION_CREATE_CONN); |
| 229 | try { |
| 230 | SomeArgs args = SomeArgs.obtain(); |
| 231 | args.arg1 = connectionManagerPhoneAccount; |
| 232 | args.arg2 = id; |
| 233 | args.arg3 = request; |
| 234 | args.arg4 = Log.createSubsession(); |
| 235 | args.argi1 = isIncoming ? 1 : 0; |
| 236 | args.argi2 = isUnknown ? 1 : 0; |
| 237 | mHandler.obtainMessage(MSG_CREATE_CONNECTION, args).sendToTarget(); |
| 238 | } finally { |
| 239 | Log.endSession(); |
| 240 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
Tyler Gunn | 041a1fe | 2017-05-12 10:04:49 -0700 | [diff] [blame] | 244 | public void createConnectionComplete(String id, Session.Info sessionInfo) { |
| 245 | Log.startSession(sessionInfo, SESSION_CREATE_CONN_COMPLETE); |
| 246 | try { |
| 247 | SomeArgs args = SomeArgs.obtain(); |
| 248 | args.arg1 = id; |
| 249 | args.arg2 = Log.createSubsession(); |
| 250 | mHandler.obtainMessage(MSG_CREATE_CONNECTION_COMPLETE, args).sendToTarget(); |
| 251 | } finally { |
| 252 | Log.endSession(); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | @Override |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 257 | public void createConnectionFailed( |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 258 | PhoneAccountHandle connectionManagerPhoneAccount, |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 259 | String callId, |
| 260 | ConnectionRequest request, |
| 261 | boolean isIncoming, |
| 262 | Session.Info sessionInfo) { |
| 263 | Log.startSession(sessionInfo, SESSION_CREATE_CONN_FAILED); |
| 264 | try { |
| 265 | SomeArgs args = SomeArgs.obtain(); |
| 266 | args.arg1 = callId; |
| 267 | args.arg2 = request; |
| 268 | args.arg3 = Log.createSubsession(); |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 269 | args.arg4 = connectionManagerPhoneAccount; |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 270 | args.argi1 = isIncoming ? 1 : 0; |
| 271 | mHandler.obtainMessage(MSG_CREATE_CONNECTION_FAILED, args).sendToTarget(); |
| 272 | } finally { |
| 273 | Log.endSession(); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 278 | public void abort(String callId, Session.Info sessionInfo) { |
| 279 | Log.startSession(sessionInfo, SESSION_ABORT); |
| 280 | try { |
| 281 | SomeArgs args = SomeArgs.obtain(); |
| 282 | args.arg1 = callId; |
| 283 | args.arg2 = Log.createSubsession(); |
| 284 | mHandler.obtainMessage(MSG_ABORT, args).sendToTarget(); |
| 285 | } finally { |
| 286 | Log.endSession(); |
| 287 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 291 | public void answerVideo(String callId, int videoState, Session.Info sessionInfo) { |
| 292 | Log.startSession(sessionInfo, SESSION_ANSWER_VIDEO); |
| 293 | try { |
| 294 | SomeArgs args = SomeArgs.obtain(); |
| 295 | args.arg1 = callId; |
| 296 | args.arg2 = Log.createSubsession(); |
| 297 | args.argi1 = videoState; |
| 298 | mHandler.obtainMessage(MSG_ANSWER_VIDEO, args).sendToTarget(); |
| 299 | } finally { |
| 300 | Log.endSession(); |
| 301 | } |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 305 | public void answer(String callId, Session.Info sessionInfo) { |
| 306 | Log.startSession(sessionInfo, SESSION_ANSWER); |
| 307 | try { |
| 308 | SomeArgs args = SomeArgs.obtain(); |
| 309 | args.arg1 = callId; |
| 310 | args.arg2 = Log.createSubsession(); |
| 311 | mHandler.obtainMessage(MSG_ANSWER, args).sendToTarget(); |
| 312 | } finally { |
| 313 | Log.endSession(); |
| 314 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 318 | public void reject(String callId, Session.Info sessionInfo) { |
| 319 | Log.startSession(sessionInfo, SESSION_REJECT); |
| 320 | try { |
| 321 | SomeArgs args = SomeArgs.obtain(); |
| 322 | args.arg1 = callId; |
| 323 | args.arg2 = Log.createSubsession(); |
| 324 | mHandler.obtainMessage(MSG_REJECT, args).sendToTarget(); |
| 325 | } finally { |
| 326 | Log.endSession(); |
| 327 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 331 | public void rejectWithMessage(String callId, String message, Session.Info sessionInfo) { |
| 332 | Log.startSession(sessionInfo, SESSION_REJECT_MESSAGE); |
| 333 | try { |
| 334 | SomeArgs args = SomeArgs.obtain(); |
| 335 | args.arg1 = callId; |
| 336 | args.arg2 = message; |
| 337 | args.arg3 = Log.createSubsession(); |
| 338 | mHandler.obtainMessage(MSG_REJECT_WITH_MESSAGE, args).sendToTarget(); |
| 339 | } finally { |
| 340 | Log.endSession(); |
| 341 | } |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 345 | public void silence(String callId, Session.Info sessionInfo) { |
| 346 | Log.startSession(sessionInfo, SESSION_SILENCE); |
| 347 | try { |
| 348 | SomeArgs args = SomeArgs.obtain(); |
| 349 | args.arg1 = callId; |
| 350 | args.arg2 = Log.createSubsession(); |
| 351 | mHandler.obtainMessage(MSG_SILENCE, args).sendToTarget(); |
| 352 | } finally { |
| 353 | Log.endSession(); |
| 354 | } |
Bryce Lee | cac5077 | 2015-11-17 15:13:29 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 358 | public void disconnect(String callId, Session.Info sessionInfo) { |
| 359 | Log.startSession(sessionInfo, SESSION_DISCONNECT); |
| 360 | try { |
| 361 | SomeArgs args = SomeArgs.obtain(); |
| 362 | args.arg1 = callId; |
| 363 | args.arg2 = Log.createSubsession(); |
| 364 | mHandler.obtainMessage(MSG_DISCONNECT, args).sendToTarget(); |
| 365 | } finally { |
| 366 | Log.endSession(); |
| 367 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 371 | public void hold(String callId, Session.Info sessionInfo) { |
| 372 | Log.startSession(sessionInfo, SESSION_HOLD); |
| 373 | try { |
| 374 | SomeArgs args = SomeArgs.obtain(); |
| 375 | args.arg1 = callId; |
| 376 | args.arg2 = Log.createSubsession(); |
| 377 | mHandler.obtainMessage(MSG_HOLD, args).sendToTarget(); |
| 378 | } finally { |
| 379 | Log.endSession(); |
| 380 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 384 | public void unhold(String callId, Session.Info sessionInfo) { |
| 385 | Log.startSession(sessionInfo, SESSION_UNHOLD); |
| 386 | try { |
| 387 | SomeArgs args = SomeArgs.obtain(); |
| 388 | args.arg1 = callId; |
| 389 | args.arg2 = Log.createSubsession(); |
| 390 | mHandler.obtainMessage(MSG_UNHOLD, args).sendToTarget(); |
| 391 | } finally { |
| 392 | Log.endSession(); |
| 393 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 397 | public void onCallAudioStateChanged(String callId, CallAudioState callAudioState, |
| 398 | Session.Info sessionInfo) { |
| 399 | Log.startSession(sessionInfo, SESSION_CALL_AUDIO_SC); |
| 400 | try { |
| 401 | SomeArgs args = SomeArgs.obtain(); |
| 402 | args.arg1 = callId; |
| 403 | args.arg2 = callAudioState; |
| 404 | args.arg3 = Log.createSubsession(); |
| 405 | mHandler.obtainMessage(MSG_ON_CALL_AUDIO_STATE_CHANGED, args).sendToTarget(); |
| 406 | } finally { |
| 407 | Log.endSession(); |
| 408 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 412 | public void playDtmfTone(String callId, char digit, Session.Info sessionInfo) { |
| 413 | Log.startSession(sessionInfo, SESSION_PLAY_DTMF); |
| 414 | try { |
| 415 | SomeArgs args = SomeArgs.obtain(); |
| 416 | args.arg1 = digit; |
| 417 | args.arg2 = callId; |
| 418 | args.arg3 = Log.createSubsession(); |
| 419 | mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, args).sendToTarget(); |
| 420 | } finally { |
| 421 | Log.endSession(); |
| 422 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 426 | public void stopDtmfTone(String callId, Session.Info sessionInfo) { |
| 427 | Log.startSession(sessionInfo, SESSION_STOP_DTMF); |
| 428 | try { |
| 429 | SomeArgs args = SomeArgs.obtain(); |
| 430 | args.arg1 = callId; |
| 431 | args.arg2 = Log.createSubsession(); |
| 432 | mHandler.obtainMessage(MSG_STOP_DTMF_TONE, args).sendToTarget(); |
| 433 | } finally { |
| 434 | Log.endSession(); |
| 435 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 439 | public void conference(String callId1, String callId2, Session.Info sessionInfo) { |
| 440 | Log.startSession(sessionInfo, SESSION_CONFERENCE); |
| 441 | try { |
| 442 | SomeArgs args = SomeArgs.obtain(); |
| 443 | args.arg1 = callId1; |
| 444 | args.arg2 = callId2; |
| 445 | args.arg3 = Log.createSubsession(); |
| 446 | mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget(); |
| 447 | } finally { |
| 448 | Log.endSession(); |
| 449 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 453 | public void splitFromConference(String callId, Session.Info sessionInfo) { |
| 454 | Log.startSession(sessionInfo, SESSION_SPLIT_CONFERENCE); |
| 455 | try { |
| 456 | SomeArgs args = SomeArgs.obtain(); |
| 457 | args.arg1 = callId; |
| 458 | args.arg2 = Log.createSubsession(); |
| 459 | mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, args).sendToTarget(); |
| 460 | } finally { |
| 461 | Log.endSession(); |
| 462 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 466 | public void mergeConference(String callId, Session.Info sessionInfo) { |
| 467 | Log.startSession(sessionInfo, SESSION_MERGE_CONFERENCE); |
| 468 | try { |
| 469 | SomeArgs args = SomeArgs.obtain(); |
| 470 | args.arg1 = callId; |
| 471 | args.arg2 = Log.createSubsession(); |
| 472 | mHandler.obtainMessage(MSG_MERGE_CONFERENCE, args).sendToTarget(); |
| 473 | } finally { |
| 474 | Log.endSession(); |
| 475 | } |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 479 | public void swapConference(String callId, Session.Info sessionInfo) { |
| 480 | Log.startSession(sessionInfo, SESSION_SWAP_CONFERENCE); |
| 481 | try { |
| 482 | SomeArgs args = SomeArgs.obtain(); |
| 483 | args.arg1 = callId; |
| 484 | args.arg2 = Log.createSubsession(); |
| 485 | mHandler.obtainMessage(MSG_SWAP_CONFERENCE, args).sendToTarget(); |
| 486 | } finally { |
| 487 | Log.endSession(); |
| 488 | } |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 492 | public void onPostDialContinue(String callId, boolean proceed, Session.Info sessionInfo) { |
| 493 | Log.startSession(sessionInfo, SESSION_POST_DIAL_CONT); |
| 494 | try { |
| 495 | SomeArgs args = SomeArgs.obtain(); |
| 496 | args.arg1 = callId; |
| 497 | args.arg2 = Log.createSubsession(); |
| 498 | args.argi1 = proceed ? 1 : 0; |
| 499 | mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget(); |
| 500 | } finally { |
| 501 | Log.endSession(); |
| 502 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 503 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 504 | |
| 505 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 506 | public void pullExternalCall(String callId, Session.Info sessionInfo) { |
| 507 | Log.startSession(sessionInfo, SESSION_PULL_EXTERNAL_CALL); |
| 508 | try { |
| 509 | SomeArgs args = SomeArgs.obtain(); |
| 510 | args.arg1 = callId; |
| 511 | args.arg2 = Log.createSubsession(); |
| 512 | mHandler.obtainMessage(MSG_PULL_EXTERNAL_CALL, args).sendToTarget(); |
| 513 | } finally { |
| 514 | Log.endSession(); |
| 515 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 519 | public void sendCallEvent(String callId, String event, Bundle extras, |
| 520 | Session.Info sessionInfo) { |
| 521 | Log.startSession(sessionInfo, SESSION_SEND_CALL_EVENT); |
| 522 | try { |
| 523 | SomeArgs args = SomeArgs.obtain(); |
| 524 | args.arg1 = callId; |
| 525 | args.arg2 = event; |
| 526 | args.arg3 = extras; |
| 527 | args.arg4 = Log.createSubsession(); |
| 528 | mHandler.obtainMessage(MSG_SEND_CALL_EVENT, args).sendToTarget(); |
| 529 | } finally { |
| 530 | Log.endSession(); |
| 531 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 532 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 533 | |
| 534 | @Override |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 535 | public void onExtrasChanged(String callId, Bundle extras, Session.Info sessionInfo) { |
| 536 | Log.startSession(sessionInfo, SESSION_EXTRAS_CHANGED); |
| 537 | try { |
| 538 | SomeArgs args = SomeArgs.obtain(); |
| 539 | args.arg1 = callId; |
| 540 | args.arg2 = extras; |
| 541 | args.arg3 = Log.createSubsession(); |
| 542 | mHandler.obtainMessage(MSG_ON_EXTRAS_CHANGED, args).sendToTarget(); |
| 543 | } finally { |
| 544 | Log.endSession(); |
| 545 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 546 | } |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 547 | |
| 548 | @Override |
| 549 | public void startRtt(String callId, ParcelFileDescriptor fromInCall, |
| 550 | ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException { |
| 551 | Log.startSession(sessionInfo, SESSION_START_RTT); |
| 552 | try { |
| 553 | SomeArgs args = SomeArgs.obtain(); |
| 554 | args.arg1 = callId; |
| 555 | args.arg2 = new Connection.RttTextStream(toInCall, fromInCall); |
| 556 | args.arg3 = Log.createSubsession(); |
| 557 | mHandler.obtainMessage(MSG_ON_START_RTT, args).sendToTarget(); |
| 558 | } finally { |
| 559 | Log.endSession(); |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | @Override |
| 564 | public void stopRtt(String callId, Session.Info sessionInfo) throws RemoteException { |
| 565 | Log.startSession(sessionInfo, SESSION_STOP_RTT); |
| 566 | try { |
| 567 | SomeArgs args = SomeArgs.obtain(); |
| 568 | args.arg1 = callId; |
| 569 | args.arg2 = Log.createSubsession(); |
| 570 | mHandler.obtainMessage(MSG_ON_STOP_RTT, args).sendToTarget(); |
| 571 | } finally { |
| 572 | Log.endSession(); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | @Override |
| 577 | public void respondToRttUpgradeRequest(String callId, ParcelFileDescriptor fromInCall, |
| 578 | ParcelFileDescriptor toInCall, Session.Info sessionInfo) throws RemoteException { |
| 579 | Log.startSession(sessionInfo, SESSION_RTT_UPGRADE_RESPONSE); |
| 580 | try { |
| 581 | SomeArgs args = SomeArgs.obtain(); |
| 582 | args.arg1 = callId; |
| 583 | if (toInCall == null || fromInCall == null) { |
| 584 | args.arg2 = null; |
| 585 | } else { |
| 586 | args.arg2 = new Connection.RttTextStream(toInCall, fromInCall); |
| 587 | } |
| 588 | args.arg3 = Log.createSubsession(); |
| 589 | mHandler.obtainMessage(MSG_RTT_UPGRADE_RESPONSE, args).sendToTarget(); |
| 590 | } finally { |
| 591 | Log.endSession(); |
| 592 | } |
| 593 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 594 | }; |
| 595 | |
| 596 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 597 | @Override |
| 598 | public void handleMessage(Message msg) { |
| 599 | switch (msg.what) { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 600 | case MSG_ADD_CONNECTION_SERVICE_ADAPTER: { |
| 601 | SomeArgs args = (SomeArgs) msg.obj; |
| 602 | try { |
| 603 | IConnectionServiceAdapter adapter = (IConnectionServiceAdapter) args.arg1; |
| 604 | Log.continueSession((Session) args.arg2, |
| 605 | SESSION_HANDLER + SESSION_ADD_CS_ADAPTER); |
| 606 | mAdapter.addAdapter(adapter); |
| 607 | onAdapterAttached(); |
| 608 | } finally { |
| 609 | args.recycle(); |
| 610 | Log.endSession(); |
| 611 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 612 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 613 | } |
| 614 | case MSG_REMOVE_CONNECTION_SERVICE_ADAPTER: { |
| 615 | SomeArgs args = (SomeArgs) msg.obj; |
| 616 | try { |
| 617 | Log.continueSession((Session) args.arg2, |
| 618 | SESSION_HANDLER + SESSION_REMOVE_CS_ADAPTER); |
| 619 | mAdapter.removeAdapter((IConnectionServiceAdapter) args.arg1); |
| 620 | } finally { |
| 621 | args.recycle(); |
| 622 | Log.endSession(); |
| 623 | } |
Ihab Awad | 8aecfed | 2014-08-08 17:06:11 -0700 | [diff] [blame] | 624 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 625 | } |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 626 | case MSG_CREATE_CONNECTION: { |
| 627 | SomeArgs args = (SomeArgs) msg.obj; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 628 | Log.continueSession((Session) args.arg4, SESSION_HANDLER + SESSION_CREATE_CONN); |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 629 | try { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 630 | final PhoneAccountHandle connectionManagerPhoneAccount = |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 631 | (PhoneAccountHandle) args.arg1; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 632 | final String id = (String) args.arg2; |
| 633 | final ConnectionRequest request = (ConnectionRequest) args.arg3; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 634 | final boolean isIncoming = args.argi1 == 1; |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 635 | final boolean isUnknown = args.argi2 == 1; |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 636 | if (!mAreAccountsInitialized) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 637 | Log.d(this, "Enqueueing pre-init request %s", id); |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 638 | mPreInitializationConnectionRequests.add( |
| 639 | new android.telecom.Logging.Runnable( |
| 640 | SESSION_HANDLER + SESSION_CREATE_CONN + ".pICR", |
| 641 | null /*lock*/) { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 642 | @Override |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 643 | public void loggedRun() { |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 644 | createConnection( |
| 645 | connectionManagerPhoneAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 646 | id, |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 647 | request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 648 | isIncoming, |
| 649 | isUnknown); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 650 | } |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 651 | }.prepare()); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 652 | } else { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 653 | createConnection( |
| 654 | connectionManagerPhoneAccount, |
| 655 | id, |
| 656 | request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 657 | isIncoming, |
| 658 | isUnknown); |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 659 | } |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 660 | } finally { |
| 661 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 662 | Log.endSession(); |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 663 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 664 | break; |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 665 | } |
Tyler Gunn | 041a1fe | 2017-05-12 10:04:49 -0700 | [diff] [blame] | 666 | case MSG_CREATE_CONNECTION_COMPLETE: { |
| 667 | SomeArgs args = (SomeArgs) msg.obj; |
| 668 | Log.continueSession((Session) args.arg2, |
| 669 | SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE); |
| 670 | try { |
| 671 | final String id = (String) args.arg1; |
| 672 | if (!mAreAccountsInitialized) { |
| 673 | Log.d(this, "Enqueueing pre-init request %s", id); |
| 674 | mPreInitializationConnectionRequests.add( |
| 675 | new android.telecom.Logging.Runnable( |
| 676 | SESSION_HANDLER + SESSION_CREATE_CONN_COMPLETE |
| 677 | + ".pICR", |
| 678 | null /*lock*/) { |
| 679 | @Override |
| 680 | public void loggedRun() { |
| 681 | notifyCreateConnectionComplete(id); |
| 682 | } |
| 683 | }.prepare()); |
| 684 | } else { |
| 685 | notifyCreateConnectionComplete(id); |
| 686 | } |
| 687 | } finally { |
| 688 | args.recycle(); |
| 689 | Log.endSession(); |
| 690 | } |
| 691 | break; |
| 692 | } |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 693 | case MSG_CREATE_CONNECTION_FAILED: { |
| 694 | SomeArgs args = (SomeArgs) msg.obj; |
| 695 | Log.continueSession((Session) args.arg3, SESSION_HANDLER + |
| 696 | SESSION_CREATE_CONN_FAILED); |
| 697 | try { |
| 698 | final String id = (String) args.arg1; |
| 699 | final ConnectionRequest request = (ConnectionRequest) args.arg2; |
| 700 | final boolean isIncoming = args.argi1 == 1; |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 701 | final PhoneAccountHandle connectionMgrPhoneAccount = |
| 702 | (PhoneAccountHandle) args.arg4; |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 703 | if (!mAreAccountsInitialized) { |
| 704 | Log.d(this, "Enqueueing pre-init request %s", id); |
| 705 | mPreInitializationConnectionRequests.add( |
| 706 | new android.telecom.Logging.Runnable( |
| 707 | SESSION_HANDLER + SESSION_CREATE_CONN_FAILED + ".pICR", |
| 708 | null /*lock*/) { |
| 709 | @Override |
| 710 | public void loggedRun() { |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 711 | createConnectionFailed(connectionMgrPhoneAccount, id, |
| 712 | request, isIncoming); |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 713 | } |
| 714 | }.prepare()); |
| 715 | } else { |
| 716 | Log.i(this, "createConnectionFailed %s", id); |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 717 | createConnectionFailed(connectionMgrPhoneAccount, id, request, |
| 718 | isIncoming); |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 719 | } |
| 720 | } finally { |
| 721 | args.recycle(); |
| 722 | Log.endSession(); |
| 723 | } |
| 724 | break; |
| 725 | } |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 726 | case MSG_ABORT: { |
| 727 | SomeArgs args = (SomeArgs) msg.obj; |
| 728 | Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ABORT); |
| 729 | try { |
| 730 | abort((String) args.arg1); |
| 731 | } finally { |
| 732 | args.recycle(); |
| 733 | Log.endSession(); |
| 734 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 735 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 736 | } |
| 737 | case MSG_ANSWER: { |
| 738 | SomeArgs args = (SomeArgs) msg.obj; |
| 739 | Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_ANSWER); |
| 740 | try { |
| 741 | answer((String) args.arg1); |
| 742 | } finally { |
| 743 | args.recycle(); |
| 744 | Log.endSession(); |
| 745 | } |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 746 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 747 | } |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 748 | case MSG_ANSWER_VIDEO: { |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 749 | SomeArgs args = (SomeArgs) msg.obj; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 750 | Log.continueSession((Session) args.arg2, |
| 751 | SESSION_HANDLER + SESSION_ANSWER_VIDEO); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 752 | try { |
| 753 | String callId = (String) args.arg1; |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 754 | int videoState = args.argi1; |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 755 | answerVideo(callId, videoState); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 756 | } finally { |
| 757 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 758 | Log.endSession(); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 759 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 760 | break; |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 761 | } |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 762 | case MSG_REJECT: { |
| 763 | SomeArgs args = (SomeArgs) msg.obj; |
| 764 | Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT); |
| 765 | try { |
| 766 | reject((String) args.arg1); |
| 767 | } finally { |
| 768 | args.recycle(); |
| 769 | Log.endSession(); |
| 770 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 771 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 772 | } |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 773 | case MSG_REJECT_WITH_MESSAGE: { |
| 774 | SomeArgs args = (SomeArgs) msg.obj; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 775 | Log.continueSession((Session) args.arg3, |
| 776 | SESSION_HANDLER + SESSION_REJECT_MESSAGE); |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 777 | try { |
| 778 | reject((String) args.arg1, (String) args.arg2); |
| 779 | } finally { |
| 780 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 781 | Log.endSession(); |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 782 | } |
| 783 | break; |
| 784 | } |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 785 | case MSG_DISCONNECT: { |
| 786 | SomeArgs args = (SomeArgs) msg.obj; |
| 787 | Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_DISCONNECT); |
| 788 | try { |
| 789 | disconnect((String) args.arg1); |
| 790 | } finally { |
| 791 | args.recycle(); |
| 792 | Log.endSession(); |
| 793 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 794 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 795 | } |
| 796 | case MSG_SILENCE: { |
| 797 | SomeArgs args = (SomeArgs) msg.obj; |
| 798 | Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_SILENCE); |
| 799 | try { |
| 800 | silence((String) args.arg1); |
| 801 | } finally { |
| 802 | args.recycle(); |
| 803 | Log.endSession(); |
| 804 | } |
Bryce Lee | cac5077 | 2015-11-17 15:13:29 -0800 | [diff] [blame] | 805 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 806 | } |
| 807 | case MSG_HOLD: { |
| 808 | SomeArgs args = (SomeArgs) msg.obj; |
| 809 | Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_REJECT); |
| 810 | try { |
| 811 | hold((String) args.arg1); |
| 812 | } finally { |
| 813 | args.recycle(); |
| 814 | Log.endSession(); |
| 815 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 816 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 817 | } |
| 818 | case MSG_UNHOLD: { |
| 819 | SomeArgs args = (SomeArgs) msg.obj; |
| 820 | Log.continueSession((Session) args.arg2, SESSION_HANDLER + SESSION_UNHOLD); |
| 821 | try { |
| 822 | unhold((String) args.arg1); |
| 823 | } finally { |
| 824 | args.recycle(); |
| 825 | Log.endSession(); |
| 826 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 827 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 828 | } |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 829 | case MSG_ON_CALL_AUDIO_STATE_CHANGED: { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 830 | SomeArgs args = (SomeArgs) msg.obj; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 831 | Log.continueSession((Session) args.arg3, |
| 832 | SESSION_HANDLER + SESSION_CALL_AUDIO_SC); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 833 | try { |
| 834 | String callId = (String) args.arg1; |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 835 | CallAudioState audioState = (CallAudioState) args.arg2; |
| 836 | onCallAudioStateChanged(callId, new CallAudioState(audioState)); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 837 | } finally { |
| 838 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 839 | Log.endSession(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 840 | } |
| 841 | break; |
| 842 | } |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 843 | case MSG_PLAY_DTMF_TONE: { |
| 844 | SomeArgs args = (SomeArgs) msg.obj; |
| 845 | try { |
| 846 | Log.continueSession((Session) args.arg3, |
| 847 | SESSION_HANDLER + SESSION_PLAY_DTMF); |
| 848 | playDtmfTone((String) args.arg2, (char) args.arg1); |
| 849 | } finally { |
| 850 | args.recycle(); |
| 851 | Log.endSession(); |
| 852 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 853 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 854 | } |
| 855 | case MSG_STOP_DTMF_TONE: { |
| 856 | SomeArgs args = (SomeArgs) msg.obj; |
| 857 | try { |
| 858 | Log.continueSession((Session) args.arg2, |
| 859 | SESSION_HANDLER + SESSION_STOP_DTMF); |
| 860 | stopDtmfTone((String) args.arg1); |
| 861 | } finally { |
| 862 | args.recycle(); |
| 863 | Log.endSession(); |
| 864 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 865 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 866 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 867 | case MSG_CONFERENCE: { |
| 868 | SomeArgs args = (SomeArgs) msg.obj; |
| 869 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 870 | Log.continueSession((Session) args.arg3, |
| 871 | SESSION_HANDLER + SESSION_CONFERENCE); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 872 | String callId1 = (String) args.arg1; |
| 873 | String callId2 = (String) args.arg2; |
| 874 | conference(callId1, callId2); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 875 | } finally { |
| 876 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 877 | Log.endSession(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 878 | } |
| 879 | break; |
| 880 | } |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 881 | case MSG_SPLIT_FROM_CONFERENCE: { |
| 882 | SomeArgs args = (SomeArgs) msg.obj; |
| 883 | try { |
| 884 | Log.continueSession((Session) args.arg2, |
| 885 | SESSION_HANDLER + SESSION_SPLIT_CONFERENCE); |
| 886 | splitFromConference((String) args.arg1); |
| 887 | } finally { |
| 888 | args.recycle(); |
| 889 | Log.endSession(); |
| 890 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 891 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 892 | } |
| 893 | case MSG_MERGE_CONFERENCE: { |
| 894 | SomeArgs args = (SomeArgs) msg.obj; |
| 895 | try { |
| 896 | Log.continueSession((Session) args.arg2, |
| 897 | SESSION_HANDLER + SESSION_MERGE_CONFERENCE); |
| 898 | mergeConference((String) args.arg1); |
| 899 | } finally { |
| 900 | args.recycle(); |
| 901 | Log.endSession(); |
| 902 | } |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 903 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 904 | } |
| 905 | case MSG_SWAP_CONFERENCE: { |
| 906 | SomeArgs args = (SomeArgs) msg.obj; |
| 907 | try { |
| 908 | Log.continueSession((Session) args.arg2, |
| 909 | SESSION_HANDLER + SESSION_SWAP_CONFERENCE); |
| 910 | swapConference((String) args.arg1); |
| 911 | } finally { |
| 912 | args.recycle(); |
| 913 | Log.endSession(); |
| 914 | } |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 915 | break; |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 916 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 917 | case MSG_ON_POST_DIAL_CONTINUE: { |
| 918 | SomeArgs args = (SomeArgs) msg.obj; |
| 919 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 920 | Log.continueSession((Session) args.arg2, |
| 921 | SESSION_HANDLER + SESSION_POST_DIAL_CONT); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 922 | String callId = (String) args.arg1; |
| 923 | boolean proceed = (args.argi1 == 1); |
| 924 | onPostDialContinue(callId, proceed); |
| 925 | } finally { |
| 926 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 927 | Log.endSession(); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 928 | } |
| 929 | break; |
| 930 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 931 | case MSG_PULL_EXTERNAL_CALL: { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 932 | SomeArgs args = (SomeArgs) msg.obj; |
| 933 | try { |
| 934 | Log.continueSession((Session) args.arg2, |
| 935 | SESSION_HANDLER + SESSION_PULL_EXTERNAL_CALL); |
| 936 | pullExternalCall((String) args.arg1); |
| 937 | } finally { |
| 938 | args.recycle(); |
| 939 | Log.endSession(); |
| 940 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 941 | break; |
| 942 | } |
| 943 | case MSG_SEND_CALL_EVENT: { |
| 944 | SomeArgs args = (SomeArgs) msg.obj; |
| 945 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 946 | Log.continueSession((Session) args.arg4, |
| 947 | SESSION_HANDLER + SESSION_SEND_CALL_EVENT); |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 948 | String callId = (String) args.arg1; |
| 949 | String event = (String) args.arg2; |
| 950 | Bundle extras = (Bundle) args.arg3; |
| 951 | sendCallEvent(callId, event, extras); |
| 952 | } finally { |
| 953 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 954 | Log.endSession(); |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 955 | } |
| 956 | break; |
| 957 | } |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 958 | case MSG_ON_EXTRAS_CHANGED: { |
| 959 | SomeArgs args = (SomeArgs) msg.obj; |
| 960 | try { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 961 | Log.continueSession((Session) args.arg3, |
| 962 | SESSION_HANDLER + SESSION_EXTRAS_CHANGED); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 963 | String callId = (String) args.arg1; |
| 964 | Bundle extras = (Bundle) args.arg2; |
| 965 | handleExtrasChanged(callId, extras); |
| 966 | } finally { |
| 967 | args.recycle(); |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 968 | Log.endSession(); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 969 | } |
| 970 | break; |
| 971 | } |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 972 | case MSG_ON_START_RTT: { |
| 973 | SomeArgs args = (SomeArgs) msg.obj; |
| 974 | try { |
| 975 | Log.continueSession((Session) args.arg3, |
| 976 | SESSION_HANDLER + SESSION_START_RTT); |
| 977 | String callId = (String) args.arg1; |
| 978 | Connection.RttTextStream rttTextStream = |
| 979 | (Connection.RttTextStream) args.arg2; |
| 980 | startRtt(callId, rttTextStream); |
| 981 | } finally { |
| 982 | args.recycle(); |
| 983 | Log.endSession(); |
| 984 | } |
| 985 | break; |
| 986 | } |
| 987 | case MSG_ON_STOP_RTT: { |
| 988 | SomeArgs args = (SomeArgs) msg.obj; |
| 989 | try { |
| 990 | Log.continueSession((Session) args.arg2, |
| 991 | SESSION_HANDLER + SESSION_STOP_RTT); |
| 992 | String callId = (String) args.arg1; |
| 993 | stopRtt(callId); |
| 994 | } finally { |
| 995 | args.recycle(); |
| 996 | Log.endSession(); |
| 997 | } |
| 998 | break; |
| 999 | } |
| 1000 | case MSG_RTT_UPGRADE_RESPONSE: { |
| 1001 | SomeArgs args = (SomeArgs) msg.obj; |
| 1002 | try { |
| 1003 | Log.continueSession((Session) args.arg3, |
| 1004 | SESSION_HANDLER + SESSION_RTT_UPGRADE_RESPONSE); |
| 1005 | String callId = (String) args.arg1; |
| 1006 | Connection.RttTextStream rttTextStream = |
| 1007 | (Connection.RttTextStream) args.arg2; |
| 1008 | handleRttUpgradeResponse(callId, rttTextStream); |
| 1009 | } finally { |
| 1010 | args.recycle(); |
| 1011 | Log.endSession(); |
| 1012 | } |
| 1013 | break; |
| 1014 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1015 | default: |
| 1016 | break; |
| 1017 | } |
| 1018 | } |
| 1019 | }; |
| 1020 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1021 | private final Conference.Listener mConferenceListener = new Conference.Listener() { |
| 1022 | @Override |
| 1023 | public void onStateChanged(Conference conference, int oldState, int newState) { |
| 1024 | String id = mIdByConference.get(conference); |
| 1025 | switch (newState) { |
| 1026 | case Connection.STATE_ACTIVE: |
| 1027 | mAdapter.setActive(id); |
| 1028 | break; |
| 1029 | case Connection.STATE_HOLDING: |
| 1030 | mAdapter.setOnHold(id); |
| 1031 | break; |
| 1032 | case Connection.STATE_DISCONNECTED: |
| 1033 | // handled by onDisconnected |
| 1034 | break; |
| 1035 | } |
| 1036 | } |
| 1037 | |
| 1038 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1039 | public void onDisconnected(Conference conference, DisconnectCause disconnectCause) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1040 | String id = mIdByConference.get(conference); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1041 | mAdapter.setDisconnected(id, disconnectCause); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | @Override |
| 1045 | public void onConnectionAdded(Conference conference, Connection connection) { |
| 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | public void onConnectionRemoved(Conference conference, Connection connection) { |
| 1050 | } |
| 1051 | |
| 1052 | @Override |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 1053 | public void onConferenceableConnectionsChanged( |
| 1054 | Conference conference, List<Connection> conferenceableConnections) { |
| 1055 | mAdapter.setConferenceableConnections( |
| 1056 | mIdByConference.get(conference), |
| 1057 | createConnectionIdList(conferenceableConnections)); |
| 1058 | } |
| 1059 | |
| 1060 | @Override |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1061 | public void onDestroyed(Conference conference) { |
| 1062 | removeConference(conference); |
| 1063 | } |
| 1064 | |
| 1065 | @Override |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1066 | public void onConnectionCapabilitiesChanged( |
| 1067 | Conference conference, |
| 1068 | int connectionCapabilities) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1069 | String id = mIdByConference.get(conference); |
| 1070 | Log.d(this, "call capabilities: conference: %s", |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1071 | Connection.capabilitiesToString(connectionCapabilities)); |
| 1072 | mAdapter.setConnectionCapabilities(id, connectionCapabilities); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1073 | } |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 1074 | |
| 1075 | @Override |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1076 | public void onConnectionPropertiesChanged( |
| 1077 | Conference conference, |
| 1078 | int connectionProperties) { |
| 1079 | String id = mIdByConference.get(conference); |
| 1080 | Log.d(this, "call capabilities: conference: %s", |
| 1081 | Connection.propertiesToString(connectionProperties)); |
| 1082 | mAdapter.setConnectionProperties(id, connectionProperties); |
| 1083 | } |
| 1084 | |
| 1085 | @Override |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 1086 | public void onVideoStateChanged(Conference c, int videoState) { |
| 1087 | String id = mIdByConference.get(c); |
| 1088 | Log.d(this, "onVideoStateChanged set video state %d", videoState); |
| 1089 | mAdapter.setVideoState(id, videoState); |
| 1090 | } |
| 1091 | |
| 1092 | @Override |
| 1093 | public void onVideoProviderChanged(Conference c, Connection.VideoProvider videoProvider) { |
| 1094 | String id = mIdByConference.get(c); |
| 1095 | Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c, |
| 1096 | videoProvider); |
| 1097 | mAdapter.setVideoProvider(id, videoProvider); |
| 1098 | } |
Andrew Lee | 0f51da3 | 2015-04-16 13:11:55 -0700 | [diff] [blame] | 1099 | |
| 1100 | @Override |
Andrew Lee | edc625f | 2015-04-14 13:38:12 -0700 | [diff] [blame] | 1101 | public void onStatusHintsChanged(Conference conference, StatusHints statusHints) { |
| 1102 | String id = mIdByConference.get(conference); |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1103 | if (id != null) { |
| 1104 | mAdapter.setStatusHints(id, statusHints); |
| 1105 | } |
Andrew Lee | edc625f | 2015-04-14 13:38:12 -0700 | [diff] [blame] | 1106 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1107 | |
| 1108 | @Override |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1109 | public void onExtrasChanged(Conference c, Bundle extras) { |
| 1110 | String id = mIdByConference.get(c); |
| 1111 | if (id != null) { |
| 1112 | mAdapter.putExtras(id, extras); |
| 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | @Override |
| 1117 | public void onExtrasRemoved(Conference c, List<String> keys) { |
| 1118 | String id = mIdByConference.get(c); |
| 1119 | if (id != null) { |
| 1120 | mAdapter.removeExtras(id, keys); |
| 1121 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1122 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1123 | }; |
| 1124 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1125 | private final Connection.Listener mConnectionListener = new Connection.Listener() { |
| 1126 | @Override |
| 1127 | public void onStateChanged(Connection c, int state) { |
| 1128 | String id = mIdByConnection.get(c); |
Ihab Awad | 42b30e1 | 2014-05-22 09:49:34 -0700 | [diff] [blame] | 1129 | Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1130 | switch (state) { |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1131 | case Connection.STATE_ACTIVE: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1132 | mAdapter.setActive(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1133 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1134 | case Connection.STATE_DIALING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1135 | mAdapter.setDialing(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1136 | break; |
Tyler Gunn | c96b5e0 | 2016-07-07 22:53:57 -0700 | [diff] [blame] | 1137 | case Connection.STATE_PULLING_CALL: |
| 1138 | mAdapter.setPulling(id); |
| 1139 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1140 | case Connection.STATE_DISCONNECTED: |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1141 | // Handled in onDisconnected() |
| 1142 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1143 | case Connection.STATE_HOLDING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1144 | mAdapter.setOnHold(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1145 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1146 | case Connection.STATE_NEW: |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1147 | // Nothing to tell Telecom |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1148 | break; |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1149 | case Connection.STATE_RINGING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1150 | mAdapter.setRinging(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | @Override |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1156 | public void onDisconnected(Connection c, DisconnectCause disconnectCause) { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1157 | String id = mIdByConnection.get(c); |
Andrew Lee | 2678639 | 2014-09-16 18:14:59 -0700 | [diff] [blame] | 1158 | Log.d(this, "Adapter set disconnected %s", disconnectCause); |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1159 | mAdapter.setDisconnected(id, disconnectCause); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | @Override |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 1163 | public void onVideoStateChanged(Connection c, int videoState) { |
| 1164 | String id = mIdByConnection.get(c); |
| 1165 | Log.d(this, "Adapter set video state %d", videoState); |
| 1166 | mAdapter.setVideoState(id, videoState); |
| 1167 | } |
| 1168 | |
| 1169 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1170 | public void onAddressChanged(Connection c, Uri address, int presentation) { |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 1171 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1172 | mAdapter.setAddress(id, address, presentation); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | @Override |
| 1176 | public void onCallerDisplayNameChanged( |
| 1177 | Connection c, String callerDisplayName, int presentation) { |
| 1178 | String id = mIdByConnection.get(c); |
| 1179 | mAdapter.setCallerDisplayName(id, callerDisplayName, presentation); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1183 | public void onDestroyed(Connection c) { |
| 1184 | removeConnection(c); |
| 1185 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1186 | |
| 1187 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1188 | public void onPostDialWait(Connection c, String remaining) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1189 | String id = mIdByConnection.get(c); |
| 1190 | Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1191 | mAdapter.onPostDialWait(id, remaining); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | @Override |
Nancy Chen | 27d1c2d | 2014-12-15 16:12:50 -0800 | [diff] [blame] | 1195 | public void onPostDialChar(Connection c, char nextChar) { |
| 1196 | String id = mIdByConnection.get(c); |
| 1197 | Log.d(this, "Adapter onPostDialChar %s, %s", c, nextChar); |
| 1198 | mAdapter.onPostDialChar(id, nextChar); |
| 1199 | } |
| 1200 | |
| 1201 | @Override |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1202 | public void onRingbackRequested(Connection c, boolean ringback) { |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1203 | String id = mIdByConnection.get(c); |
| 1204 | Log.d(this, "Adapter onRingback %b", ringback); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1205 | mAdapter.setRingbackRequested(id, ringback); |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 1206 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1207 | |
| 1208 | @Override |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1209 | public void onConnectionCapabilitiesChanged(Connection c, int capabilities) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1210 | String id = mIdByConnection.get(c); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1211 | Log.d(this, "capabilities: parcelableconnection: %s", |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1212 | Connection.capabilitiesToString(capabilities)); |
| 1213 | mAdapter.setConnectionCapabilities(id, capabilities); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1216 | @Override |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1217 | public void onConnectionPropertiesChanged(Connection c, int properties) { |
| 1218 | String id = mIdByConnection.get(c); |
| 1219 | Log.d(this, "properties: parcelableconnection: %s", |
| 1220 | Connection.propertiesToString(properties)); |
| 1221 | mAdapter.setConnectionProperties(id, properties); |
| 1222 | } |
| 1223 | |
| 1224 | @Override |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1225 | public void onVideoProviderChanged(Connection c, Connection.VideoProvider videoProvider) { |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 1226 | String id = mIdByConnection.get(c); |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 1227 | Log.d(this, "onVideoProviderChanged: Connection: %s, VideoProvider: %s", c, |
| 1228 | videoProvider); |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1229 | mAdapter.setVideoProvider(id, videoProvider); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 1230 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 1231 | |
| 1232 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 1233 | public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) { |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 1234 | String id = mIdByConnection.get(c); |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1235 | mAdapter.setIsVoipAudioMode(id, isVoip); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 1236 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1237 | |
| 1238 | @Override |
Sailesh Nepal | 001bbbb | 2014-07-15 14:40:39 -0700 | [diff] [blame] | 1239 | public void onStatusHintsChanged(Connection c, StatusHints statusHints) { |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 1240 | String id = mIdByConnection.get(c); |
| 1241 | mAdapter.setStatusHints(id, statusHints); |
| 1242 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame] | 1243 | |
| 1244 | @Override |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1245 | public void onConferenceablesChanged( |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 1246 | Connection connection, List<Conferenceable> conferenceables) { |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1247 | mAdapter.setConferenceableConnections( |
| 1248 | mIdByConnection.get(connection), |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1249 | createIdList(conferenceables)); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1250 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1251 | |
| 1252 | @Override |
| 1253 | public void onConferenceChanged(Connection connection, Conference conference) { |
| 1254 | String id = mIdByConnection.get(connection); |
| 1255 | if (id != null) { |
| 1256 | String conferenceId = null; |
| 1257 | if (conference != null) { |
| 1258 | conferenceId = mIdByConference.get(conference); |
| 1259 | } |
| 1260 | mAdapter.setIsConferenced(id, conferenceId); |
| 1261 | } |
| 1262 | } |
Anthony Lee | 17455a3 | 2015-04-24 15:25:29 -0700 | [diff] [blame] | 1263 | |
| 1264 | @Override |
| 1265 | public void onConferenceMergeFailed(Connection connection) { |
| 1266 | String id = mIdByConnection.get(connection); |
| 1267 | if (id != null) { |
| 1268 | mAdapter.onConferenceMergeFailed(id); |
| 1269 | } |
| 1270 | } |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1271 | |
| 1272 | @Override |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1273 | public void onExtrasChanged(Connection c, Bundle extras) { |
| 1274 | String id = mIdByConnection.get(c); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1275 | if (id != null) { |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1276 | mAdapter.putExtras(id, extras); |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1277 | } |
| 1278 | } |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 1279 | |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1280 | @Override |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1281 | public void onExtrasRemoved(Connection c, List<String> keys) { |
| 1282 | String id = mIdByConnection.get(c); |
| 1283 | if (id != null) { |
| 1284 | mAdapter.removeExtras(id, keys); |
| 1285 | } |
| 1286 | } |
| 1287 | |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 1288 | @Override |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1289 | public void onConnectionEvent(Connection connection, String event, Bundle extras) { |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 1290 | String id = mIdByConnection.get(connection); |
| 1291 | if (id != null) { |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1292 | mAdapter.onConnectionEvent(id, event, extras); |
Tyler Gunn | bd1eb1f | 2016-02-16 14:36:20 -0800 | [diff] [blame] | 1293 | } |
| 1294 | } |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1295 | |
| 1296 | @Override |
| 1297 | public void onAudioRouteChanged(Connection c, int audioRoute) { |
| 1298 | String id = mIdByConnection.get(c); |
| 1299 | if (id != null) { |
| 1300 | mAdapter.setAudioRoute(id, audioRoute); |
| 1301 | } |
| 1302 | } |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1303 | |
| 1304 | @Override |
| 1305 | public void onRttInitiationSuccess(Connection c) { |
| 1306 | String id = mIdByConnection.get(c); |
| 1307 | if (id != null) { |
| 1308 | mAdapter.onRttInitiationSuccess(id); |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | @Override |
| 1313 | public void onRttInitiationFailure(Connection c, int reason) { |
| 1314 | String id = mIdByConnection.get(c); |
| 1315 | if (id != null) { |
| 1316 | mAdapter.onRttInitiationFailure(id, reason); |
| 1317 | } |
| 1318 | } |
| 1319 | |
| 1320 | @Override |
| 1321 | public void onRttSessionRemotelyTerminated(Connection c) { |
| 1322 | String id = mIdByConnection.get(c); |
| 1323 | if (id != null) { |
| 1324 | mAdapter.onRttSessionRemotelyTerminated(id); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | @Override |
| 1329 | public void onRemoteRttRequest(Connection c) { |
| 1330 | String id = mIdByConnection.get(c); |
| 1331 | if (id != null) { |
| 1332 | mAdapter.onRemoteRttRequest(id); |
| 1333 | } |
| 1334 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1335 | }; |
| 1336 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1337 | /** {@inheritDoc} */ |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1338 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1339 | public final IBinder onBind(Intent intent) { |
| 1340 | return mBinder; |
| 1341 | } |
| 1342 | |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 1343 | /** {@inheritDoc} */ |
| 1344 | @Override |
| 1345 | public boolean onUnbind(Intent intent) { |
| 1346 | endAllConnections(); |
| 1347 | return super.onUnbind(intent); |
| 1348 | } |
| 1349 | |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1350 | /** |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 1351 | * This can be used by telecom to either create a new outgoing call or attach to an existing |
| 1352 | * incoming call. In either case, telecom will cycle through a set of services and call |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1353 | * createConnection util a connection service cancels the process or completes it successfully. |
| 1354 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1355 | private void createConnection( |
| 1356 | final PhoneAccountHandle callManagerAccount, |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1357 | final String callId, |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1358 | final ConnectionRequest request, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 1359 | boolean isIncoming, |
| 1360 | boolean isUnknown) { |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1361 | Log.d(this, "createConnection, callManagerAccount: %s, callId: %s, request: %s, " + |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 1362 | "isIncoming: %b, isUnknown: %b", callManagerAccount, callId, request, |
| 1363 | isIncoming, |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 1364 | isUnknown); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1365 | |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 1366 | Connection connection = isUnknown ? onCreateUnknownConnection(callManagerAccount, request) |
| 1367 | : isIncoming ? onCreateIncomingConnection(callManagerAccount, request) |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1368 | : onCreateOutgoingConnection(callManagerAccount, request); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1369 | Log.d(this, "createConnection, connection: %s", connection); |
| 1370 | if (connection == null) { |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 1371 | connection = Connection.createFailedConnection( |
| 1372 | new DisconnectCause(DisconnectCause.ERROR)); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1373 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1374 | |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 1375 | connection.setTelecomCallId(callId); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1376 | if (connection.getState() != Connection.STATE_DISCONNECTED) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1377 | addConnection(callId, connection); |
| 1378 | } |
| 1379 | |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1380 | Uri address = connection.getAddress(); |
| 1381 | String number = address == null ? "null" : address.getSchemeSpecificPart(); |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1382 | Log.v(this, "createConnection, number: %s, state: %s, capabilities: %s, properties: %s", |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1383 | Connection.toLogSafePhoneNumber(number), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1384 | Connection.stateToString(connection.getState()), |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1385 | Connection.capabilitiesToString(connection.getConnectionCapabilities()), |
| 1386 | Connection.propertiesToString(connection.getConnectionProperties())); |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 1387 | |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1388 | Log.d(this, "createConnection, calling handleCreateConnectionSuccessful %s", callId); |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1389 | mAdapter.handleCreateConnectionComplete( |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1390 | callId, |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1391 | request, |
| 1392 | new ParcelableConnection( |
| 1393 | request.getAccountHandle(), |
| 1394 | connection.getState(), |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1395 | connection.getConnectionCapabilities(), |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1396 | connection.getConnectionProperties(), |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 1397 | connection.getSupportedAudioRoutes(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1398 | connection.getAddress(), |
| 1399 | connection.getAddressPresentation(), |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1400 | connection.getCallerDisplayName(), |
| 1401 | connection.getCallerDisplayNamePresentation(), |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 1402 | connection.getVideoProvider() == null ? |
| 1403 | null : connection.getVideoProvider().getInterface(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1404 | connection.getVideoState(), |
Andrew Lee | 100e293 | 2014-09-08 15:34:24 -0700 | [diff] [blame] | 1405 | connection.isRingbackRequested(), |
Sailesh Nepal | 8b9d3ca | 2014-08-14 17:39:34 -0700 | [diff] [blame] | 1406 | connection.getAudioModeIsVoip(), |
Roshan Pius | e927ec0 | 2015-07-15 15:47:21 -0700 | [diff] [blame] | 1407 | connection.getConnectTimeMillis(), |
Tyler Gunn | 40f5ccd | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 1408 | connection.getConnectElapsedTimeMillis(), |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1409 | connection.getStatusHints(), |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1410 | connection.getDisconnectCause(), |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1411 | createIdList(connection.getConferenceables()), |
| 1412 | connection.getExtras())); |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1413 | |
| 1414 | if (isIncoming && request.shouldShowIncomingCallUi() && |
| 1415 | (connection.getConnectionProperties() & Connection.PROPERTY_SELF_MANAGED) == |
| 1416 | Connection.PROPERTY_SELF_MANAGED) { |
| 1417 | // Tell ConnectionService to show its incoming call UX. |
| 1418 | connection.onShowIncomingCallUi(); |
| 1419 | } |
Shriram Ganesh | 6bf35ac | 2014-12-11 17:53:38 -0800 | [diff] [blame] | 1420 | if (isUnknown) { |
| 1421 | triggerConferenceRecalculate(); |
| 1422 | } |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1425 | private void createConnectionFailed(final PhoneAccountHandle callManagerAccount, |
| 1426 | final String callId, final ConnectionRequest request, |
| 1427 | boolean isIncoming) { |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 1428 | |
| 1429 | Log.i(this, "createConnectionFailed %s", callId); |
| 1430 | if (isIncoming) { |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1431 | onCreateIncomingConnectionFailed(callManagerAccount, request); |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 1432 | } else { |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1433 | onCreateOutgoingConnectionFailed(callManagerAccount, request); |
Tyler Gunn | 44e0191 | 2017-01-31 10:49:05 -0800 | [diff] [blame] | 1434 | } |
| 1435 | } |
| 1436 | |
Tyler Gunn | 041a1fe | 2017-05-12 10:04:49 -0700 | [diff] [blame] | 1437 | /** |
| 1438 | * Called by Telecom when the creation of a new Connection has completed and it is now added |
| 1439 | * to Telecom. |
| 1440 | * @param callId The ID of the connection. |
| 1441 | */ |
| 1442 | private void notifyCreateConnectionComplete(final String callId) { |
| 1443 | Log.i(this, "notifyCreateConnectionComplete %s", callId); |
Tyler Gunn | 9a351ca | 2017-06-16 20:20:34 -0700 | [diff] [blame] | 1444 | if (callId == null) { |
| 1445 | // This could happen if the connection fails quickly and is removed from the |
| 1446 | // ConnectionService before Telecom sends the create connection complete callback. |
| 1447 | Log.w(this, "notifyCreateConnectionComplete: callId is null."); |
| 1448 | return; |
| 1449 | } |
Tyler Gunn | 041a1fe | 2017-05-12 10:04:49 -0700 | [diff] [blame] | 1450 | onCreateConnectionComplete(findConnectionForAction(callId, |
| 1451 | "notifyCreateConnectionComplete")); |
| 1452 | } |
| 1453 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1454 | private void abort(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 1455 | Log.d(this, "abort %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1456 | findConnectionForAction(callId, "abort").onAbort(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1459 | private void answerVideo(String callId, int videoState) { |
| 1460 | Log.d(this, "answerVideo %s", callId); |
Andrew Lee | 8da4c3c | 2014-07-16 10:11:42 -0700 | [diff] [blame] | 1461 | findConnectionForAction(callId, "answer").onAnswer(videoState); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 1464 | private void answer(String callId) { |
| 1465 | Log.d(this, "answer %s", callId); |
| 1466 | findConnectionForAction(callId, "answer").onAnswer(); |
| 1467 | } |
| 1468 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1469 | private void reject(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 1470 | Log.d(this, "reject %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1471 | findConnectionForAction(callId, "reject").onReject(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Bryce Lee | 8190168 | 2015-08-28 16:38:02 -0700 | [diff] [blame] | 1474 | private void reject(String callId, String rejectWithMessage) { |
| 1475 | Log.d(this, "reject %s with message", callId); |
| 1476 | findConnectionForAction(callId, "reject").onReject(rejectWithMessage); |
| 1477 | } |
| 1478 | |
Bryce Lee | cac5077 | 2015-11-17 15:13:29 -0800 | [diff] [blame] | 1479 | private void silence(String callId) { |
| 1480 | Log.d(this, "silence %s", callId); |
| 1481 | findConnectionForAction(callId, "silence").onSilence(); |
| 1482 | } |
| 1483 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1484 | private void disconnect(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 1485 | Log.d(this, "disconnect %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1486 | if (mConnectionById.containsKey(callId)) { |
| 1487 | findConnectionForAction(callId, "disconnect").onDisconnect(); |
| 1488 | } else { |
| 1489 | findConferenceForAction(callId, "disconnect").onDisconnect(); |
| 1490 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1493 | private void hold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 1494 | Log.d(this, "hold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1495 | if (mConnectionById.containsKey(callId)) { |
| 1496 | findConnectionForAction(callId, "hold").onHold(); |
| 1497 | } else { |
| 1498 | findConferenceForAction(callId, "hold").onHold(); |
| 1499 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1502 | private void unhold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 1503 | Log.d(this, "unhold %s", callId); |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1504 | if (mConnectionById.containsKey(callId)) { |
| 1505 | findConnectionForAction(callId, "unhold").onUnhold(); |
| 1506 | } else { |
| 1507 | findConferenceForAction(callId, "unhold").onUnhold(); |
| 1508 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 1511 | private void onCallAudioStateChanged(String callId, CallAudioState callAudioState) { |
| 1512 | Log.d(this, "onAudioStateChanged %s %s", callId, callAudioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 1513 | if (mConnectionById.containsKey(callId)) { |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 1514 | findConnectionForAction(callId, "onCallAudioStateChanged").setCallAudioState( |
| 1515 | callAudioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 1516 | } else { |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 1517 | findConferenceForAction(callId, "onCallAudioStateChanged").setCallAudioState( |
| 1518 | callAudioState); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 1519 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1522 | private void playDtmfTone(String callId, char digit) { |
| 1523 | Log.d(this, "playDtmfTone %s %c", callId, digit); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 1524 | if (mConnectionById.containsKey(callId)) { |
| 1525 | findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 1526 | } else { |
| 1527 | findConferenceForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 1528 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | private void stopDtmfTone(String callId) { |
| 1532 | Log.d(this, "stopDtmfTone %s", callId); |
Yorke Lee | a0d3ca9 | 2014-09-15 19:18:13 -0700 | [diff] [blame] | 1533 | if (mConnectionById.containsKey(callId)) { |
| 1534 | findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 1535 | } else { |
| 1536 | findConferenceForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 1537 | } |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1540 | private void conference(String callId1, String callId2) { |
| 1541 | Log.d(this, "conference %s, %s", callId1, callId2); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 1542 | |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1543 | // Attempt to get second connection or conference. |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1544 | Connection connection2 = findConnectionForAction(callId2, "conference"); |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1545 | Conference conference2 = getNullConference(); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1546 | if (connection2 == getNullConnection()) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1547 | conference2 = findConferenceForAction(callId2, "conference"); |
| 1548 | if (conference2 == getNullConference()) { |
| 1549 | Log.w(this, "Connection2 or Conference2 missing in conference request %s.", |
| 1550 | callId2); |
| 1551 | return; |
| 1552 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1553 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1554 | |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1555 | // Attempt to get first connection or conference and perform merge. |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 1556 | Connection connection1 = findConnectionForAction(callId1, "conference"); |
| 1557 | if (connection1 == getNullConnection()) { |
| 1558 | Conference conference1 = findConferenceForAction(callId1, "addConnection"); |
| 1559 | if (conference1 == getNullConference()) { |
| 1560 | Log.w(this, |
| 1561 | "Connection1 or Conference1 missing in conference request %s.", |
| 1562 | callId1); |
| 1563 | } else { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1564 | // Call 1 is a conference. |
| 1565 | if (connection2 != getNullConnection()) { |
| 1566 | // Call 2 is a connection so merge via call 1 (conference). |
| 1567 | conference1.onMerge(connection2); |
| 1568 | } else { |
| 1569 | // Call 2 is ALSO a conference; this should never happen. |
| 1570 | Log.wtf(this, "There can only be one conference and an attempt was made to " + |
| 1571 | "merge two conferences."); |
| 1572 | return; |
| 1573 | } |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } else { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 1576 | // Call 1 is a connection. |
| 1577 | if (conference2 != getNullConference()) { |
| 1578 | // Call 2 is a conference, so merge via call 2. |
| 1579 | conference2.onMerge(connection1); |
| 1580 | } else { |
| 1581 | // Call 2 is a connection, so merge together. |
| 1582 | onConference(connection1, connection2); |
| 1583 | } |
Ihab Awad | 50e3506 | 2014-09-30 09:17:03 -0700 | [diff] [blame] | 1584 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1587 | private void splitFromConference(String callId) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1588 | Log.d(this, "splitFromConference(%s)", callId); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 1589 | |
| 1590 | Connection connection = findConnectionForAction(callId, "splitFromConference"); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 1591 | if (connection == getNullConnection()) { |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 1592 | Log.w(this, "Connection missing in conference request %s.", callId); |
| 1593 | return; |
| 1594 | } |
| 1595 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 1596 | Conference conference = connection.getConference(); |
| 1597 | if (conference != null) { |
| 1598 | conference.onSeparate(connection); |
| 1599 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Santos Cordon | a486804 | 2014-09-04 17:39:22 -0700 | [diff] [blame] | 1602 | private void mergeConference(String callId) { |
| 1603 | Log.d(this, "mergeConference(%s)", callId); |
| 1604 | Conference conference = findConferenceForAction(callId, "mergeConference"); |
| 1605 | if (conference != null) { |
| 1606 | conference.onMerge(); |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | private void swapConference(String callId) { |
| 1611 | Log.d(this, "swapConference(%s)", callId); |
| 1612 | Conference conference = findConferenceForAction(callId, "swapConference"); |
| 1613 | if (conference != null) { |
| 1614 | conference.onSwap(); |
| 1615 | } |
| 1616 | } |
| 1617 | |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1618 | /** |
| 1619 | * Notifies a {@link Connection} of a request to pull an external call. |
| 1620 | * |
| 1621 | * See {@link Call#pullExternalCall()}. |
| 1622 | * |
| 1623 | * @param callId The ID of the call to pull. |
| 1624 | */ |
| 1625 | private void pullExternalCall(String callId) { |
| 1626 | Log.d(this, "pullExternalCall(%s)", callId); |
| 1627 | Connection connection = findConnectionForAction(callId, "pullExternalCall"); |
| 1628 | if (connection != null) { |
| 1629 | connection.onPullExternalCall(); |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | /** |
| 1634 | * Notifies a {@link Connection} of a call event. |
| 1635 | * |
| 1636 | * See {@link Call#sendCallEvent(String, Bundle)}. |
| 1637 | * |
| 1638 | * @param callId The ID of the call receiving the event. |
| 1639 | * @param event The event. |
| 1640 | * @param extras Extras associated with the event. |
| 1641 | */ |
| 1642 | private void sendCallEvent(String callId, String event, Bundle extras) { |
| 1643 | Log.d(this, "sendCallEvent(%s, %s)", callId, event); |
| 1644 | Connection connection = findConnectionForAction(callId, "sendCallEvent"); |
| 1645 | if (connection != null) { |
| 1646 | connection.onCallEvent(event, extras); |
| 1647 | } |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 1648 | } |
| 1649 | |
Tyler Gunn | dee56a8 | 2016-03-23 16:06:34 -0700 | [diff] [blame] | 1650 | /** |
| 1651 | * Notifies a {@link Connection} or {@link Conference} of a change to the extras from Telecom. |
| 1652 | * <p> |
| 1653 | * These extra changes can originate from Telecom itself, or from an {@link InCallService} via |
| 1654 | * the {@link android.telecom.Call#putExtra(String, boolean)}, |
| 1655 | * {@link android.telecom.Call#putExtra(String, int)}, |
| 1656 | * {@link android.telecom.Call#putExtra(String, String)}, |
| 1657 | * {@link Call#removeExtras(List)}. |
| 1658 | * |
| 1659 | * @param callId The ID of the call receiving the event. |
| 1660 | * @param extras The new extras bundle. |
| 1661 | */ |
| 1662 | private void handleExtrasChanged(String callId, Bundle extras) { |
| 1663 | Log.d(this, "handleExtrasChanged(%s, %s)", callId, extras); |
| 1664 | if (mConnectionById.containsKey(callId)) { |
| 1665 | findConnectionForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras); |
| 1666 | } else if (mConferenceById.containsKey(callId)) { |
| 1667 | findConferenceForAction(callId, "handleExtrasChanged").handleExtrasChanged(extras); |
| 1668 | } |
| 1669 | } |
| 1670 | |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1671 | private void startRtt(String callId, Connection.RttTextStream rttTextStream) { |
| 1672 | Log.d(this, "startRtt(%s)", callId); |
| 1673 | if (mConnectionById.containsKey(callId)) { |
| 1674 | findConnectionForAction(callId, "startRtt").onStartRtt(rttTextStream); |
| 1675 | } else if (mConferenceById.containsKey(callId)) { |
| 1676 | Log.w(this, "startRtt called on a conference."); |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | private void stopRtt(String callId) { |
| 1681 | Log.d(this, "stopRtt(%s)", callId); |
| 1682 | if (mConnectionById.containsKey(callId)) { |
| 1683 | findConnectionForAction(callId, "stopRtt").onStopRtt(); |
Hall Liu | ffa4a81 | 2017-03-02 16:11:00 -0800 | [diff] [blame] | 1684 | findConnectionForAction(callId, "stopRtt").unsetRttProperty(); |
Hall Liu | b64ac4c | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 1685 | } else if (mConferenceById.containsKey(callId)) { |
| 1686 | Log.w(this, "stopRtt called on a conference."); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | private void handleRttUpgradeResponse(String callId, Connection.RttTextStream rttTextStream) { |
| 1691 | Log.d(this, "handleRttUpgradeResponse(%s, %s)", callId, rttTextStream == null); |
| 1692 | if (mConnectionById.containsKey(callId)) { |
| 1693 | findConnectionForAction(callId, "handleRttUpgradeResponse") |
| 1694 | .handleRttUpgradeResponse(rttTextStream); |
| 1695 | } else if (mConferenceById.containsKey(callId)) { |
| 1696 | Log.w(this, "handleRttUpgradeResponse called on a conference."); |
| 1697 | } |
| 1698 | } |
| 1699 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1700 | private void onPostDialContinue(String callId, boolean proceed) { |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1701 | Log.d(this, "onPostDialContinue(%s)", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1702 | findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed); |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1705 | private void onAdapterAttached() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 1706 | if (mAreAccountsInitialized) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1707 | // No need to query again if we already did it. |
| 1708 | return; |
| 1709 | } |
| 1710 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1711 | mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1712 | @Override |
| 1713 | public void onResult( |
| 1714 | final List<ComponentName> componentNames, |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1715 | final List<IBinder> services) { |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 1716 | mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oR", null /*lock*/) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1717 | @Override |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 1718 | public void loggedRun() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1719 | for (int i = 0; i < componentNames.size() && i < services.size(); i++) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1720 | mRemoteConnectionManager.addConnectionService( |
| 1721 | componentNames.get(i), |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 1722 | IConnectionService.Stub.asInterface(services.get(i))); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1723 | } |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 1724 | onAccountsInitialized(); |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1725 | Log.d(this, "remote connection services found: " + services); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1726 | } |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 1727 | }.prepare()); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | @Override |
| 1731 | public void onError() { |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 1732 | mHandler.post(new android.telecom.Logging.Runnable("oAA.qRCS.oE", null /*lock*/) { |
Ihab Awad | 6107bab | 2014-08-18 09:23:25 -0700 | [diff] [blame] | 1733 | @Override |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 1734 | public void loggedRun() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 1735 | mAreAccountsInitialized = true; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1736 | } |
Brad Ebinger | 0c3541b | 2016-11-01 14:11:38 -0700 | [diff] [blame] | 1737 | }.prepare()); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1738 | } |
| 1739 | }); |
| 1740 | } |
| 1741 | |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1742 | /** |
| 1743 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 1744 | * incoming request. This is used by {@code ConnectionService}s that are registered with |
| 1745 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to manage |
| 1746 | * SIM-based incoming calls. |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1747 | * |
| 1748 | * @param connectionManagerPhoneAccount See description at |
| 1749 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 1750 | * @param request Details about the incoming call. |
| 1751 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 1752 | * not handle the call. |
| 1753 | */ |
| 1754 | public final RemoteConnection createRemoteIncomingConnection( |
| 1755 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 1756 | ConnectionRequest request) { |
| 1757 | return mRemoteConnectionManager.createRemoteConnection( |
| 1758 | connectionManagerPhoneAccount, request, true); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1762 | * Ask some other {@code ConnectionService} to create a {@code RemoteConnection} given an |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 1763 | * outgoing request. This is used by {@code ConnectionService}s that are registered with |
| 1764 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER} and want to be able to use the |
| 1765 | * SIM-based {@code ConnectionService} to place its outgoing calls. |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1766 | * |
| 1767 | * @param connectionManagerPhoneAccount See description at |
| 1768 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
Cuihtlauac ALVARADO | 0b3b2a5 | 2016-09-13 14:49:41 +0200 | [diff] [blame] | 1769 | * @param request Details about the outgoing call. |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1770 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 1771 | * not handle the call. |
| 1772 | */ |
| 1773 | public final RemoteConnection createRemoteOutgoingConnection( |
| 1774 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 1775 | ConnectionRequest request) { |
| 1776 | return mRemoteConnectionManager.createRemoteConnection( |
| 1777 | connectionManagerPhoneAccount, request, false); |
| 1778 | } |
| 1779 | |
| 1780 | /** |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 1781 | * Indicates to the relevant {@code RemoteConnectionService} that the specified |
| 1782 | * {@link RemoteConnection}s should be merged into a conference call. |
| 1783 | * <p> |
| 1784 | * If the conference request is successful, the method {@link #onRemoteConferenceAdded} will |
| 1785 | * be invoked. |
| 1786 | * |
| 1787 | * @param remoteConnection1 The first of the remote connections to conference. |
| 1788 | * @param remoteConnection2 The second of the remote connections to conference. |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1789 | */ |
| 1790 | public final void conferenceRemoteConnections( |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 1791 | RemoteConnection remoteConnection1, |
| 1792 | RemoteConnection remoteConnection2) { |
| 1793 | mRemoteConnectionManager.conferenceRemoteConnections(remoteConnection1, remoteConnection2); |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1797 | * Adds a new conference call. When a conference call is created either as a result of an |
| 1798 | * explicit request via {@link #onConference} or otherwise, the connection service should supply |
| 1799 | * an instance of {@link Conference} by invoking this method. A conference call provided by this |
| 1800 | * method will persist until {@link Conference#destroy} is invoked on the conference instance. |
| 1801 | * |
| 1802 | * @param conference The new conference object. |
| 1803 | */ |
| 1804 | public final void addConference(Conference conference) { |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 1805 | Log.d(this, "addConference: conference=%s", conference); |
| 1806 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1807 | String id = addConferenceInternal(conference); |
| 1808 | if (id != null) { |
| 1809 | List<String> connectionIds = new ArrayList<>(2); |
| 1810 | for (Connection connection : conference.getConnections()) { |
| 1811 | if (mIdByConnection.containsKey(connection)) { |
| 1812 | connectionIds.add(mIdByConnection.get(connection)); |
| 1813 | } |
| 1814 | } |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 1815 | conference.setTelecomCallId(id); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1816 | ParcelableConference parcelableConference = new ParcelableConference( |
Nancy Chen | ea38cca | 2014-09-05 16:38:49 -0700 | [diff] [blame] | 1817 | conference.getPhoneAccountHandle(), |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1818 | conference.getState(), |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1819 | conference.getConnectionCapabilities(), |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1820 | conference.getConnectionProperties(), |
Tyler Gunn | cd5d33c | 2015-01-12 09:02:01 -0800 | [diff] [blame] | 1821 | connectionIds, |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 1822 | conference.getVideoProvider() == null ? |
| 1823 | null : conference.getVideoProvider().getInterface(), |
| 1824 | conference.getVideoState(), |
Andrew Lee | 3e3e2f2 | 2015-04-16 13:48:43 -0700 | [diff] [blame] | 1825 | conference.getConnectTimeMillis(), |
Tyler Gunn | 40f5ccd | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 1826 | conference.getConnectElapsedTime(), |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1827 | conference.getStatusHints(), |
| 1828 | conference.getExtras()); |
Andrew Lee | 0f51da3 | 2015-04-16 13:11:55 -0700 | [diff] [blame] | 1829 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1830 | mAdapter.addConferenceCall(id, parcelableConference); |
Rekha Kumar | 0736681 | 2015-03-24 16:42:31 -0700 | [diff] [blame] | 1831 | mAdapter.setVideoProvider(id, conference.getVideoProvider()); |
| 1832 | mAdapter.setVideoState(id, conference.getVideoState()); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 1833 | |
| 1834 | // Go through any child calls and set the parent. |
| 1835 | for (Connection connection : conference.getConnections()) { |
| 1836 | String connectionId = mIdByConnection.get(connection); |
| 1837 | if (connectionId != null) { |
| 1838 | mAdapter.setIsConferenced(connectionId, id); |
| 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | /** |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1845 | * Adds a connection created by the {@link ConnectionService} and informs telecom of the new |
| 1846 | * connection. |
| 1847 | * |
| 1848 | * @param phoneAccountHandle The phone account handle for the connection. |
| 1849 | * @param connection The connection to add. |
| 1850 | */ |
| 1851 | public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle, |
| 1852 | Connection connection) { |
Tyler Gunn | 78da781 | 2017-05-09 14:34:57 -0700 | [diff] [blame] | 1853 | addExistingConnection(phoneAccountHandle, connection, null /* conference */); |
| 1854 | } |
| 1855 | |
| 1856 | /** |
| 1857 | * Adds a connection created by the {@link ConnectionService} and informs telecom of the new |
| 1858 | * connection. |
| 1859 | * |
| 1860 | * @param phoneAccountHandle The phone account handle for the connection. |
| 1861 | * @param connection The connection to add. |
| 1862 | * @param conference The parent conference of the new connection. |
| 1863 | * @hide |
| 1864 | */ |
| 1865 | public final void addExistingConnection(PhoneAccountHandle phoneAccountHandle, |
| 1866 | Connection connection, Conference conference) { |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1867 | |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 1868 | String id = addExistingConnectionInternal(phoneAccountHandle, connection); |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1869 | if (id != null) { |
| 1870 | List<String> emptyList = new ArrayList<>(0); |
Tyler Gunn | 78da781 | 2017-05-09 14:34:57 -0700 | [diff] [blame] | 1871 | String conferenceId = null; |
| 1872 | if (conference != null) { |
| 1873 | conferenceId = mIdByConference.get(conference); |
| 1874 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1875 | |
| 1876 | ParcelableConnection parcelableConnection = new ParcelableConnection( |
| 1877 | phoneAccountHandle, |
| 1878 | connection.getState(), |
Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 1879 | connection.getConnectionCapabilities(), |
Tyler Gunn | 720c664 | 2016-03-22 09:02:47 -0700 | [diff] [blame] | 1880 | connection.getConnectionProperties(), |
Christine Hallstrom | 2830ce9 | 2016-11-30 16:06:42 -0800 | [diff] [blame] | 1881 | connection.getSupportedAudioRoutes(), |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1882 | connection.getAddress(), |
| 1883 | connection.getAddressPresentation(), |
| 1884 | connection.getCallerDisplayName(), |
| 1885 | connection.getCallerDisplayNamePresentation(), |
| 1886 | connection.getVideoProvider() == null ? |
| 1887 | null : connection.getVideoProvider().getInterface(), |
| 1888 | connection.getVideoState(), |
| 1889 | connection.isRingbackRequested(), |
| 1890 | connection.getAudioModeIsVoip(), |
Roshan Pius | e927ec0 | 2015-07-15 15:47:21 -0700 | [diff] [blame] | 1891 | connection.getConnectTimeMillis(), |
Tyler Gunn | 40f5ccd | 2017-08-04 09:27:26 -0700 | [diff] [blame] | 1892 | connection.getConnectElapsedTimeMillis(), |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1893 | connection.getStatusHints(), |
| 1894 | connection.getDisconnectCause(), |
Santos Cordon | 6b7f955 | 2015-05-27 17:21:45 -0700 | [diff] [blame] | 1895 | emptyList, |
Tyler Gunn | 78da781 | 2017-05-09 14:34:57 -0700 | [diff] [blame] | 1896 | connection.getExtras(), |
| 1897 | conferenceId); |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 1898 | mAdapter.addExistingConnection(id, parcelableConnection); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1903 | * Returns all the active {@code Connection}s for which this {@code ConnectionService} |
| 1904 | * has taken responsibility. |
| 1905 | * |
| 1906 | * @return A collection of {@code Connection}s created by this {@code ConnectionService}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1907 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 1908 | public final Collection<Connection> getAllConnections() { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 1909 | return mConnectionById.values(); |
| 1910 | } |
| 1911 | |
| 1912 | /** |
Santos Cordon | a6018b9 | 2016-02-16 14:23:12 -0800 | [diff] [blame] | 1913 | * Returns all the active {@code Conference}s for which this {@code ConnectionService} |
| 1914 | * has taken responsibility. |
| 1915 | * |
| 1916 | * @return A collection of {@code Conference}s created by this {@code ConnectionService}. |
| 1917 | */ |
| 1918 | public final Collection<Conference> getAllConferences() { |
| 1919 | return mConferenceById.values(); |
| 1920 | } |
| 1921 | |
| 1922 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1923 | * Create a {@code Connection} given an incoming request. This is used to attach to existing |
| 1924 | * incoming calls. |
Evan Charlton | bf11f98 | 2014-07-20 22:06:28 -0700 | [diff] [blame] | 1925 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1926 | * @param connectionManagerPhoneAccount See description at |
| 1927 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
| 1928 | * @param request Details about the incoming call. |
| 1929 | * @return The {@code Connection} object to satisfy this call, or {@code null} to |
| 1930 | * not handle the call. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 1931 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1932 | public Connection onCreateIncomingConnection( |
| 1933 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 1934 | ConnectionRequest request) { |
| 1935 | return null; |
| 1936 | } |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 1937 | |
| 1938 | /** |
Tyler Gunn | 041a1fe | 2017-05-12 10:04:49 -0700 | [diff] [blame] | 1939 | * Called after the {@link Connection} returned by |
| 1940 | * {@link #onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest)} |
| 1941 | * or {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)} has been |
| 1942 | * added to the {@link ConnectionService} and sent to Telecom. |
| 1943 | * |
| 1944 | * @param connection the {@link Connection}. |
| 1945 | * @hide |
| 1946 | */ |
| 1947 | public void onCreateConnectionComplete(Connection connection) { |
| 1948 | } |
| 1949 | |
| 1950 | /** |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1951 | * Called by Telecom to inform the {@link ConnectionService} that its request to create a new |
| 1952 | * incoming {@link Connection} was denied. |
| 1953 | * <p> |
| 1954 | * Used when a self-managed {@link ConnectionService} attempts to create a new incoming |
| 1955 | * {@link Connection}, but Telecom has determined that the call cannot be allowed at this time. |
| 1956 | * The {@link ConnectionService} is responsible for silently rejecting the new incoming |
| 1957 | * {@link Connection}. |
| 1958 | * <p> |
| 1959 | * See {@link TelecomManager#isIncomingCallPermitted(PhoneAccountHandle)} for more information. |
| 1960 | * |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1961 | * @param connectionManagerPhoneAccount See description at |
| 1962 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1963 | * @param request The incoming connection request. |
| 1964 | */ |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1965 | public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, |
| 1966 | ConnectionRequest request) { |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | /** |
| 1970 | * Called by Telecom to inform the {@link ConnectionService} that its request to create a new |
| 1971 | * outgoing {@link Connection} was denied. |
| 1972 | * <p> |
| 1973 | * Used when a self-managed {@link ConnectionService} attempts to create a new outgoing |
| 1974 | * {@link Connection}, but Telecom has determined that the call cannot be placed at this time. |
| 1975 | * The {@link ConnectionService} is responisible for informing the user that the |
| 1976 | * {@link Connection} cannot be made at this time. |
| 1977 | * <p> |
| 1978 | * See {@link TelecomManager#isOutgoingCallPermitted(PhoneAccountHandle)} for more information. |
| 1979 | * |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1980 | * @param connectionManagerPhoneAccount See description at |
| 1981 | * {@link #onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest)}. |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1982 | * @param request The outgoing connection request. |
| 1983 | */ |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 1984 | public void onCreateOutgoingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, |
| 1985 | ConnectionRequest request) { |
Tyler Gunn | f503543 | 2017-01-09 09:43:12 -0800 | [diff] [blame] | 1986 | } |
| 1987 | |
| 1988 | /** |
Shriram Ganesh | 6bf35ac | 2014-12-11 17:53:38 -0800 | [diff] [blame] | 1989 | * Trigger recalculate functinality for conference calls. This is used when a Telephony |
| 1990 | * Connection is part of a conference controller but is not yet added to Connection |
| 1991 | * Service and hence cannot be added to the conference call. |
| 1992 | * |
| 1993 | * @hide |
| 1994 | */ |
| 1995 | public void triggerConferenceRecalculate() { |
| 1996 | } |
| 1997 | |
| 1998 | /** |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 1999 | * Create a {@code Connection} given an outgoing request. This is used to initiate new |
| 2000 | * outgoing calls. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 2001 | * |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 2002 | * @param connectionManagerPhoneAccount The connection manager account to use for managing |
| 2003 | * this call. |
| 2004 | * <p> |
| 2005 | * If this parameter is not {@code null}, it means that this {@code ConnectionService} |
| 2006 | * has registered one or more {@code PhoneAccount}s having |
| 2007 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. This parameter will contain |
| 2008 | * one of these {@code PhoneAccount}s, while the {@code request} will contain another |
| 2009 | * (usually but not always distinct) {@code PhoneAccount} to be used for actually |
| 2010 | * making the connection. |
| 2011 | * <p> |
| 2012 | * If this parameter is {@code null}, it means that this {@code ConnectionService} is |
| 2013 | * being asked to make a direct connection. The |
| 2014 | * {@link ConnectionRequest#getAccountHandle()} of parameter {@code request} will be |
| 2015 | * a {@code PhoneAccount} registered by this {@code ConnectionService} to use for |
| 2016 | * making the connection. |
| 2017 | * @param request Details about the outgoing call. |
| 2018 | * @return The {@code Connection} object to satisfy this call, or the result of an invocation |
Andrew Lee | 7f3d41f | 2014-09-11 17:33:16 -0700 | [diff] [blame] | 2019 | * of {@link Connection#createFailedConnection(DisconnectCause)} to not handle the call. |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 2020 | */ |
Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 2021 | public Connection onCreateOutgoingConnection( |
| 2022 | PhoneAccountHandle connectionManagerPhoneAccount, |
| 2023 | ConnectionRequest request) { |
| 2024 | return null; |
| 2025 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2026 | |
| 2027 | /** |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 2028 | * Create a {@code Connection} for a new unknown call. An unknown call is a call originating |
| 2029 | * from the ConnectionService that was neither a user-initiated outgoing call, nor an incoming |
| 2030 | * call created using |
| 2031 | * {@code TelecomManager#addNewIncomingCall(PhoneAccountHandle, android.os.Bundle)}. |
| 2032 | * |
Yorke Lee | 770ed6e | 2014-10-06 18:58:52 -0700 | [diff] [blame] | 2033 | * @hide |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 2034 | */ |
| 2035 | public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount, |
| 2036 | ConnectionRequest request) { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 2037 | return null; |
Yorke Lee | c3cf982 | 2014-10-02 09:38:39 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2041 | * Conference two specified connections. Invoked when the user has made a request to merge the |
| 2042 | * specified connections into a conference call. In response, the connection service should |
| 2043 | * create an instance of {@link Conference} and pass it into {@link #addConference}. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 2044 | * |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2045 | * @param connection1 A connection to merge into a conference call. |
| 2046 | * @param connection2 A connection to merge into a conference call. |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 2047 | */ |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2048 | public void onConference(Connection connection1, Connection connection2) {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 2049 | |
Santos Cordon | a663f86 | 2014-10-29 13:49:58 -0700 | [diff] [blame] | 2050 | /** |
| 2051 | * Indicates that a remote conference has been created for existing {@link RemoteConnection}s. |
| 2052 | * When this method is invoked, this {@link ConnectionService} should create its own |
| 2053 | * representation of the conference call and send it to telecom using {@link #addConference}. |
| 2054 | * <p> |
| 2055 | * This is only relevant to {@link ConnectionService}s which are registered with |
| 2056 | * {@link PhoneAccount#CAPABILITY_CONNECTION_MANAGER}. |
| 2057 | * |
| 2058 | * @param conference The remote conference call. |
| 2059 | */ |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 2060 | public void onRemoteConferenceAdded(RemoteConference conference) {} |
| 2061 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2062 | /** |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 2063 | * Called when an existing connection is added remotely. |
| 2064 | * @param connection The existing connection which was added. |
| 2065 | */ |
| 2066 | public void onRemoteExistingConnectionAdded(RemoteConnection connection) {} |
| 2067 | |
| 2068 | /** |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2069 | * @hide |
| 2070 | */ |
| 2071 | public boolean containsConference(Conference conference) { |
| 2072 | return mIdByConference.containsKey(conference); |
| 2073 | } |
| 2074 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 2075 | /** {@hide} */ |
| 2076 | void addRemoteConference(RemoteConference remoteConference) { |
| 2077 | onRemoteConferenceAdded(remoteConference); |
| 2078 | } |
| 2079 | |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 2080 | /** {@hide} */ |
| 2081 | void addRemoteExistingConnection(RemoteConnection remoteConnection) { |
| 2082 | onRemoteExistingConnectionAdded(remoteConnection); |
| 2083 | } |
| 2084 | |
Ihab Awad | 5d0410f | 2014-07-30 10:07:40 -0700 | [diff] [blame] | 2085 | private void onAccountsInitialized() { |
| 2086 | mAreAccountsInitialized = true; |
| 2087 | for (Runnable r : mPreInitializationConnectionRequests) { |
| 2088 | r.run(); |
| 2089 | } |
| 2090 | mPreInitializationConnectionRequests.clear(); |
| 2091 | } |
| 2092 | |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 2093 | /** |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2094 | * Adds an existing connection to the list of connections, identified by a new call ID unique |
| 2095 | * to this connection service. |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 2096 | * |
| 2097 | * @param connection The connection. |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2098 | * @return The ID of the connection (e.g. the call-id). |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 2099 | */ |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2100 | private String addExistingConnectionInternal(PhoneAccountHandle handle, Connection connection) { |
| 2101 | String id; |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 2102 | |
| 2103 | if (connection.getExtras() != null && connection.getExtras() |
| 2104 | .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) { |
| 2105 | id = connection.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID); |
| 2106 | Log.d(this, "addExistingConnectionInternal - conn %s reusing original id %s", |
| 2107 | connection.getTelecomCallId(), id); |
| 2108 | } else if (handle == null) { |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2109 | // If no phone account handle was provided, we cannot be sure the call ID is unique, |
| 2110 | // so just use a random UUID. |
| 2111 | id = UUID.randomUUID().toString(); |
| 2112 | } else { |
| 2113 | // Phone account handle was provided, so use the ConnectionService class name as a |
| 2114 | // prefix for a unique incremental call ID. |
| 2115 | id = handle.getComponentName().getClassName() + "@" + getNextCallId(); |
| 2116 | } |
Tyler Gunn | 4a57b9b | 2014-10-30 14:27:48 -0700 | [diff] [blame] | 2117 | addConnection(id, connection); |
| 2118 | return id; |
| 2119 | } |
| 2120 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2121 | private void addConnection(String callId, Connection connection) { |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2122 | connection.setTelecomCallId(callId); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2123 | mConnectionById.put(callId, connection); |
| 2124 | mIdByConnection.put(connection, callId); |
| 2125 | connection.addConnectionListener(mConnectionListener); |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2126 | connection.setConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
Anthony Lee | 30e6584 | 2014-11-06 16:30:53 -0800 | [diff] [blame] | 2129 | /** {@hide} */ |
| 2130 | protected void removeConnection(Connection connection) { |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2131 | connection.unsetConnectionService(this); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2132 | connection.removeConnectionListener(mConnectionListener); |
Chenjie Luo | e370b53 | 2016-05-12 16:59:43 -0700 | [diff] [blame] | 2133 | String id = mIdByConnection.get(connection); |
| 2134 | if (id != null) { |
| 2135 | mConnectionById.remove(id); |
| 2136 | mIdByConnection.remove(connection); |
| 2137 | mAdapter.removeCall(id); |
| 2138 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2141 | private String addConferenceInternal(Conference conference) { |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 2142 | String originalId = null; |
| 2143 | if (conference.getExtras() != null && conference.getExtras() |
| 2144 | .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) { |
| 2145 | originalId = conference.getExtras().getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID); |
| 2146 | Log.d(this, "addConferenceInternal: conf %s reusing original id %s", |
| 2147 | conference.getTelecomCallId(), |
| 2148 | originalId); |
| 2149 | } |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2150 | if (mIdByConference.containsKey(conference)) { |
| 2151 | Log.w(this, "Re-adding an existing conference: %s.", conference); |
| 2152 | } else if (conference != null) { |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2153 | // Conferences do not (yet) have a PhoneAccountHandle associated with them, so we |
| 2154 | // cannot determine a ConnectionService class name to associate with the ID, so use |
| 2155 | // a unique UUID (for now). |
Tyler Gunn | cd6ccfd | 2016-10-17 15:48:19 -0700 | [diff] [blame] | 2156 | String id = originalId == null ? UUID.randomUUID().toString() : originalId; |
Santos Cordon | 823fd3c | 2014-08-07 18:35:18 -0700 | [diff] [blame] | 2157 | mConferenceById.put(id, conference); |
| 2158 | mIdByConference.put(conference, id); |
| 2159 | conference.addListener(mConferenceListener); |
| 2160 | return id; |
| 2161 | } |
| 2162 | |
| 2163 | return null; |
| 2164 | } |
| 2165 | |
| 2166 | private void removeConference(Conference conference) { |
| 2167 | if (mIdByConference.containsKey(conference)) { |
| 2168 | conference.removeListener(mConferenceListener); |
| 2169 | |
| 2170 | String id = mIdByConference.get(conference); |
| 2171 | mConferenceById.remove(id); |
| 2172 | mIdByConference.remove(conference); |
| 2173 | mAdapter.removeCall(id); |
| 2174 | } |
| 2175 | } |
| 2176 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2177 | private Connection findConnectionForAction(String callId, String action) { |
Tyler Gunn | 9a351ca | 2017-06-16 20:20:34 -0700 | [diff] [blame] | 2178 | if (callId != null && mConnectionById.containsKey(callId)) { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 2179 | return mConnectionById.get(callId); |
| 2180 | } |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 2181 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
Sailesh Nepal | cf7020b | 2014-08-20 10:07:19 -0700 | [diff] [blame] | 2182 | return getNullConnection(); |
| 2183 | } |
| 2184 | |
| 2185 | static synchronized Connection getNullConnection() { |
| 2186 | if (sNullConnection == null) { |
| 2187 | sNullConnection = new Connection() {}; |
| 2188 | } |
| 2189 | return sNullConnection; |
Santos Cordon | 7c7bc7f | 2014-07-28 18:15:48 -0700 | [diff] [blame] | 2190 | } |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 2191 | |
| 2192 | private Conference findConferenceForAction(String conferenceId, String action) { |
| 2193 | if (mConferenceById.containsKey(conferenceId)) { |
| 2194 | return mConferenceById.get(conferenceId); |
| 2195 | } |
| 2196 | Log.w(this, "%s - Cannot find conference %s", action, conferenceId); |
| 2197 | return getNullConference(); |
| 2198 | } |
| 2199 | |
Ihab Awad | b8e85c7 | 2014-08-23 20:34:57 -0700 | [diff] [blame] | 2200 | private List<String> createConnectionIdList(List<Connection> connections) { |
| 2201 | List<String> ids = new ArrayList<>(); |
| 2202 | for (Connection c : connections) { |
| 2203 | if (mIdByConnection.containsKey(c)) { |
| 2204 | ids.add(mIdByConnection.get(c)); |
| 2205 | } |
| 2206 | } |
| 2207 | Collections.sort(ids); |
| 2208 | return ids; |
| 2209 | } |
| 2210 | |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 2211 | /** |
| 2212 | * Builds a list of {@link Connection} and {@link Conference} IDs based on the list of |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 2213 | * {@link Conferenceable}s passed in. |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 2214 | * |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 2215 | * @param conferenceables The {@link Conferenceable} connections and conferences. |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 2216 | * @return List of string conference and call Ids. |
| 2217 | */ |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 2218 | private List<String> createIdList(List<Conferenceable> conferenceables) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 2219 | List<String> ids = new ArrayList<>(); |
Tyler Gunn | df2cbc8 | 2015-04-20 09:13:01 -0700 | [diff] [blame] | 2220 | for (Conferenceable c : conferenceables) { |
Tyler Gunn | 6d76ca0 | 2014-11-17 15:49:51 -0800 | [diff] [blame] | 2221 | // Only allow Connection and Conference conferenceables. |
| 2222 | if (c instanceof Connection) { |
| 2223 | Connection connection = (Connection) c; |
| 2224 | if (mIdByConnection.containsKey(connection)) { |
| 2225 | ids.add(mIdByConnection.get(connection)); |
| 2226 | } |
| 2227 | } else if (c instanceof Conference) { |
| 2228 | Conference conference = (Conference) c; |
| 2229 | if (mIdByConference.containsKey(conference)) { |
| 2230 | ids.add(mIdByConference.get(conference)); |
| 2231 | } |
| 2232 | } |
| 2233 | } |
| 2234 | Collections.sort(ids); |
| 2235 | return ids; |
| 2236 | } |
| 2237 | |
Santos Cordon | 0159ac0 | 2014-08-21 14:28:11 -0700 | [diff] [blame] | 2238 | private Conference getNullConference() { |
| 2239 | if (sNullConference == null) { |
| 2240 | sNullConference = new Conference(null) {}; |
| 2241 | } |
| 2242 | return sNullConference; |
| 2243 | } |
Santos Cordon | 29f2f2e | 2014-09-11 19:50:24 -0700 | [diff] [blame] | 2244 | |
| 2245 | private void endAllConnections() { |
| 2246 | // Unbound from telecomm. We should end all connections and conferences. |
| 2247 | for (Connection connection : mIdByConnection.keySet()) { |
| 2248 | // only operate on top-level calls. Conference calls will be removed on their own. |
| 2249 | if (connection.getConference() == null) { |
| 2250 | connection.onDisconnect(); |
| 2251 | } |
| 2252 | } |
| 2253 | for (Conference conference : mIdByConference.keySet()) { |
| 2254 | conference.onDisconnect(); |
| 2255 | } |
| 2256 | } |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2257 | |
| 2258 | /** |
| 2259 | * Retrieves the next call ID as maintainted by the connection service. |
| 2260 | * |
| 2261 | * @return The call ID. |
| 2262 | */ |
| 2263 | private int getNextCallId() { |
Brad Ebinger | b32d4f8 | 2016-10-24 16:40:49 -0700 | [diff] [blame] | 2264 | synchronized (mIdSyncRoot) { |
Tyler Gunn | f0500bd | 2015-09-01 10:59:48 -0700 | [diff] [blame] | 2265 | return ++mId; |
| 2266 | } |
| 2267 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 2268 | } |