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