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