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