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