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