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