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