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