blob: 6dd9a3a08e34541a67313d2b1308d453c7a9e61d [file] [log] [blame]
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001/*
2 * Copyright 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 Gunn7cc70b42014-09-12 22:17:27 -070017package com.android.server.telecom;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070018
Brad Ebinger91350952016-06-29 17:27:08 -070019import android.app.AppOpsManager;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070020import android.content.ComponentName;
Tyler Gunn91d43cf2014-09-17 12:19:39 -070021import android.content.Context;
Sailesh Nepale8ecb982014-07-11 17:19:42 -070022import android.net.Uri;
Ihab Awad512d6352015-03-26 13:43:22 -070023import android.os.Binder;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070024import android.os.Bundle;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070025import android.os.IBinder;
Hall Liuaeece4e2017-02-14 16:42:12 -080026import android.os.ParcelFileDescriptor;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070027import android.os.RemoteException;
Evan Charlton105d9772014-11-25 14:08:53 -080028import android.os.UserHandle;
Yorke Lee2a66f7b2015-05-13 14:21:19 -070029import android.telecom.CallAudioState;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070030import android.telecom.Connection;
31import android.telecom.ConnectionRequest;
32import android.telecom.ConnectionService;
Andrew Lee701dc002014-09-11 21:29:12 -070033import android.telecom.DisconnectCause;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070034import android.telecom.GatewayInfo;
Brad Ebinger953e1af2016-10-05 15:45:22 -070035import android.telecom.Log;
Brad Ebingerb78b0232016-10-24 16:40:33 -070036import android.telecom.Logging.Session;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070037import android.telecom.ParcelableConference;
38import android.telecom.ParcelableConnection;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070039import android.telecom.PhoneAccountHandle;
40import android.telecom.StatusHints;
41import android.telecom.TelecomManager;
42import android.telecom.VideoProfile;
Srikanth Chintala1c586c62017-05-04 20:55:01 +053043import android.telephony.TelephonyManager;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070044
Hall Liuf62630a2015-10-27 14:53:39 -070045import com.android.internal.annotations.VisibleForTesting;
Tyler Gunn7cc70b42014-09-12 22:17:27 -070046import com.android.internal.telecom.IConnectionService;
47import com.android.internal.telecom.IConnectionServiceAdapter;
48import com.android.internal.telecom.IVideoProvider;
49import com.android.internal.telecom.RemoteServiceCallback;
Tyler Gunn91d43cf2014-09-17 12:19:39 -070050import com.android.internal.util.Preconditions;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070051
Sailesh Nepalc92c4362014-07-04 18:33:21 -070052import java.util.ArrayList;
Ihab Awadb78b2762014-07-25 15:16:23 -070053import java.util.Collections;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070054import java.util.HashMap;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070055import java.util.List;
56import java.util.Map;
57import java.util.Set;
Jay Shraunera82c8f72014-08-14 15:49:16 -070058import java.util.concurrent.ConcurrentHashMap;
Sailesh Nepalc92c4362014-07-04 18:33:21 -070059
60/**
61 * Wrapper for {@link IConnectionService}s, handles binding to {@link IConnectionService} and keeps
62 * track of when the object can safely be unbound. Other classes should not use
63 * {@link IConnectionService} directly and instead should use this class to invoke methods of
64 * {@link IConnectionService}.
65 */
Hall Liuf62630a2015-10-27 14:53:39 -070066@VisibleForTesting
Pengquan Mengd7f92cf2017-11-21 17:52:42 -080067public class ConnectionServiceWrapper extends ServiceBinder implements
68 ConnectionServiceFocusManager.ConnectionServiceFocus {
Sailesh Nepalc92c4362014-07-04 18:33:21 -070069
70 private final class Adapter extends IConnectionServiceAdapter.Stub {
Ihab Awad6fb37c82014-08-07 19:48:57 -070071
Sailesh Nepalc92c4362014-07-04 18:33:21 -070072 @Override
Brad Ebinger11623a32015-11-25 13:52:02 -080073 public void handleCreateConnectionComplete(String callId, ConnectionRequest request,
Brad Ebinger65912752016-10-28 12:32:06 -070074 ParcelableConnection connection, Session.Info sessionInfo) {
75 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_HANDLE_CREATE_CONNECTION_COMPLETE);
Ihab Awad512d6352015-03-26 13:43:22 -070076 long token = Binder.clearCallingIdentity();
77 try {
78 synchronized (mLock) {
79 logIncoming("handleCreateConnectionComplete %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -070080 ConnectionServiceWrapper.this
81 .handleCreateConnectionComplete(callId, request, connection);
Tyler Gunnddb03e12017-05-12 11:54:41 -070082
83 if (mServiceInterface != null) {
84 logOutgoing("createConnectionComplete %s", callId);
85 try {
86 mServiceInterface.createConnectionComplete(callId,
87 Log.getExternalSession());
88 } catch (RemoteException e) {
89 }
90 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -070091 }
Hall Liu62630f72018-05-10 17:48:59 -070092 } catch (Throwable t) {
93 Log.e(ConnectionServiceWrapper.this, t, "");
94 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -070095 } finally {
96 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -080097 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -070098 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -070099 }
100
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700101 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700102 public void setActive(String callId, Session.Info sessionInfo) {
103 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ACTIVE);
Ihab Awad512d6352015-03-26 13:43:22 -0700104 long token = Binder.clearCallingIdentity();
105 try {
106 synchronized (mLock) {
107 logIncoming("setActive %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -0700108 Call call = mCallIdMapper.getCall(callId);
109 if (call != null) {
110 mCallsManager.markCallAsActive(call);
111 } else {
112 // Log.w(this, "setActive, unknown call id: %s", msg.obj);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700113 }
114 }
Hall Liu62630f72018-05-10 17:48:59 -0700115 } catch (Throwable t) {
116 Log.e(ConnectionServiceWrapper.this, t, "");
117 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700118 } finally {
119 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800120 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700121 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700122 }
123
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700124 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700125 public void setRinging(String callId, Session.Info sessionInfo) {
126 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_RINGING);
Ihab Awad512d6352015-03-26 13:43:22 -0700127 long token = Binder.clearCallingIdentity();
128 try {
129 synchronized (mLock) {
130 logIncoming("setRinging %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -0700131 Call call = mCallIdMapper.getCall(callId);
132 if (call != null) {
133 mCallsManager.markCallAsRinging(call);
134 } else {
135 // Log.w(this, "setRinging, unknown call id: %s", msg.obj);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700136 }
137 }
Hall Liu62630f72018-05-10 17:48:59 -0700138 } catch (Throwable t) {
139 Log.e(ConnectionServiceWrapper.this, t, "");
140 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700141 } finally {
142 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800143 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700144 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700145 }
146
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700147 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700148 public void setVideoProvider(String callId, IVideoProvider videoProvider,
149 Session.Info sessionInfo) {
150 Log.startSession(sessionInfo, "CSW.sVP");
Ihab Awad512d6352015-03-26 13:43:22 -0700151 long token = Binder.clearCallingIdentity();
152 try {
153 synchronized (mLock) {
154 logIncoming("setVideoProvider %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -0700155 Call call = mCallIdMapper.getCall(callId);
156 if (call != null) {
157 call.setVideoProvider(videoProvider);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700158 }
159 }
Hall Liu62630f72018-05-10 17:48:59 -0700160 } catch (Throwable t) {
161 Log.e(ConnectionServiceWrapper.this, t, "");
162 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700163 } finally {
164 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800165 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700166 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700167 }
168
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700169 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700170 public void setDialing(String callId, Session.Info sessionInfo) {
171 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DIALING);
Ihab Awad512d6352015-03-26 13:43:22 -0700172 long token = Binder.clearCallingIdentity();
173 try {
174 synchronized (mLock) {
175 logIncoming("setDialing %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -0700176 Call call = mCallIdMapper.getCall(callId);
177 if (call != null) {
178 mCallsManager.markCallAsDialing(call);
179 } else {
180 // Log.w(this, "setDialing, unknown call id: %s", msg.obj);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700181 }
182 }
Hall Liu62630f72018-05-10 17:48:59 -0700183 } catch (Throwable t) {
184 Log.e(ConnectionServiceWrapper.this, t, "");
185 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700186 } finally {
187 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800188 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700189 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700190 }
191
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700192 @Override
Hall Liu62630f72018-05-10 17:48:59 -0700193 public void setPulling(String callId, Session.Info sessionInfo) {
Brad Ebinger65912752016-10-28 12:32:06 -0700194 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_PULLING);
Tyler Gunn1e37be52016-07-11 08:54:23 -0700195 long token = Binder.clearCallingIdentity();
196 try {
197 synchronized (mLock) {
198 logIncoming("setPulling %s", callId);
199 Call call = mCallIdMapper.getCall(callId);
200 if (call != null) {
201 mCallsManager.markCallAsPulling(call);
202 }
203 }
Hall Liu62630f72018-05-10 17:48:59 -0700204 } catch (Throwable t) {
205 Log.e(ConnectionServiceWrapper.this, t, "");
206 throw t;
Tyler Gunn1e37be52016-07-11 08:54:23 -0700207 } finally {
208 Binder.restoreCallingIdentity(token);
209 Log.endSession();
210 }
211 }
212
213 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700214 public void setDisconnected(String callId, DisconnectCause disconnectCause,
215 Session.Info sessionInfo) {
216 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DISCONNECTED);
Ihab Awad512d6352015-03-26 13:43:22 -0700217 long token = Binder.clearCallingIdentity();
218 try {
219 synchronized (mLock) {
220 logIncoming("setDisconnected %s %s", callId, disconnectCause);
Tyler Gunn8452be02015-09-17 09:57:02 -0700221 Call call = mCallIdMapper.getCall(callId);
222 Log.d(this, "disconnect call %s %s", disconnectCause, call);
223 if (call != null) {
224 mCallsManager.markCallAsDisconnected(call, disconnectCause);
225 } else {
226 // Log.w(this, "setDisconnected, unknown call id: %s", args.arg1);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700227 }
228 }
Hall Liu62630f72018-05-10 17:48:59 -0700229 } catch (Throwable t) {
230 Log.e(ConnectionServiceWrapper.this, t, "");
231 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700232 } finally {
233 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800234 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700235 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700236 }
237
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700238 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700239 public void setOnHold(String callId, Session.Info sessionInfo) {
240 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ON_HOLD);
Ihab Awad512d6352015-03-26 13:43:22 -0700241 long token = Binder.clearCallingIdentity();
242 try {
243 synchronized (mLock) {
244 logIncoming("setOnHold %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -0700245 Call call = mCallIdMapper.getCall(callId);
246 if (call != null) {
247 mCallsManager.markCallAsOnHold(call);
248 } else {
249 // Log.w(this, "setOnHold, unknown call id: %s", msg.obj);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700250 }
251 }
Hall Liu62630f72018-05-10 17:48:59 -0700252 } catch (Throwable t) {
253 Log.e(ConnectionServiceWrapper.this, t, "");
254 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700255 } finally {
256 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800257 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700258 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700259 }
260
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700261 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700262 public void setRingbackRequested(String callId, boolean ringback,
263 Session.Info sessionInfo) {
264 Log.startSession(sessionInfo, "CSW.SRR");
Ihab Awad512d6352015-03-26 13:43:22 -0700265 long token = Binder.clearCallingIdentity();
266 try {
267 synchronized (mLock) {
268 logIncoming("setRingbackRequested %s %b", callId, ringback);
Tyler Gunn8452be02015-09-17 09:57:02 -0700269 Call call = mCallIdMapper.getCall(callId);
270 if (call != null) {
271 call.setRingbackRequested(ringback);
272 } else {
273 // Log.w(this, "setRingback, unknown call id: %s", args.arg1);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700274 }
275 }
Hall Liu62630f72018-05-10 17:48:59 -0700276 } catch (Throwable t) {
277 Log.e(ConnectionServiceWrapper.this, t, "");
278 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700279 } finally {
280 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800281 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700282 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700283 }
284
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700285 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700286 public void removeCall(String callId, Session.Info sessionInfo) {
287 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_REMOVE_CALL);
Ihab Awad512d6352015-03-26 13:43:22 -0700288 long token = Binder.clearCallingIdentity();
289 try {
290 synchronized (mLock) {
291 logIncoming("removeCall %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -0700292 Call call = mCallIdMapper.getCall(callId);
293 if (call != null) {
294 if (call.isAlive()) {
295 mCallsManager.markCallAsDisconnected(
296 call, new DisconnectCause(DisconnectCause.REMOTE));
297 } else {
298 mCallsManager.markCallAsRemoved(call);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700299 }
300 }
301 }
Hall Liu62630f72018-05-10 17:48:59 -0700302 } catch (Throwable t) {
303 Log.e(ConnectionServiceWrapper.this, t, "");
304 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700305 } finally {
306 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800307 Log.endSession();
Ihab Awada02bef52014-08-13 18:18:42 -0700308 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700309 }
310
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700311 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700312 public void setConnectionCapabilities(String callId, int connectionCapabilities,
313 Session.Info sessionInfo) {
314 Log.startSession(sessionInfo, "CSW.sCC");
Ihab Awad512d6352015-03-26 13:43:22 -0700315 long token = Binder.clearCallingIdentity();
316 try {
317 synchronized (mLock) {
318 logIncoming("setConnectionCapabilities %s %d", callId, connectionCapabilities);
Tyler Gunn8452be02015-09-17 09:57:02 -0700319 Call call = mCallIdMapper.getCall(callId);
320 if (call != null) {
321 call.setConnectionCapabilities(connectionCapabilities);
322 } else {
323 // Log.w(ConnectionServiceWrapper.this,
324 // "setConnectionCapabilities, unknown call id: %s", msg.obj);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700325 }
326 }
Hall Liu62630f72018-05-10 17:48:59 -0700327 } catch (Throwable t) {
328 Log.e(ConnectionServiceWrapper.this, t, "");
329 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700330 } finally {
331 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800332 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700333 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700334 }
335
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700336 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700337 public void setConnectionProperties(String callId, int connectionProperties,
338 Session.Info sessionInfo) {
Tyler Gunn571d5e62016-03-15 15:55:18 -0700339 Log.startSession("CSW.sCP");
340 long token = Binder.clearCallingIdentity();
341 try {
342 synchronized (mLock) {
343 logIncoming("setConnectionProperties %s %d", callId, connectionProperties);
344 Call call = mCallIdMapper.getCall(callId);
345 if (call != null) {
346 call.setConnectionProperties(connectionProperties);
347 }
348 }
Hall Liu62630f72018-05-10 17:48:59 -0700349 } catch (Throwable t) {
350 Log.e(ConnectionServiceWrapper.this, t, "");
351 throw t;
Tyler Gunn571d5e62016-03-15 15:55:18 -0700352 } finally {
353 Binder.restoreCallingIdentity(token);
354 Log.endSession();
355 }
356 }
357
358 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700359 public void setIsConferenced(String callId, String conferenceCallId,
360 Session.Info sessionInfo) {
361 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_IS_CONFERENCED);
Ihab Awad512d6352015-03-26 13:43:22 -0700362 long token = Binder.clearCallingIdentity();
363 try {
364 synchronized (mLock) {
365 logIncoming("setIsConferenced %s %s", callId, conferenceCallId);
366 Call childCall = mCallIdMapper.getCall(callId);
367 if (childCall != null) {
368 if (conferenceCallId == null) {
369 Log.d(this, "unsetting parent: %s", conferenceCallId);
Tyler Gunn76581712017-05-09 14:39:42 -0700370 childCall.setParentAndChildCall(null);
Ihab Awad512d6352015-03-26 13:43:22 -0700371 } else {
372 Call conferenceCall = mCallIdMapper.getCall(conferenceCallId);
Tyler Gunn76581712017-05-09 14:39:42 -0700373 childCall.setParentAndChildCall(conferenceCall);
Ihab Awad512d6352015-03-26 13:43:22 -0700374 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700375 } else {
Ihab Awad512d6352015-03-26 13:43:22 -0700376 // Log.w(this, "setIsConferenced, unknown call id: %s", args.arg1);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700377 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700378 }
Hall Liu62630f72018-05-10 17:48:59 -0700379 } catch (Throwable t) {
380 Log.e(ConnectionServiceWrapper.this, t, "");
381 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700382 } finally {
383 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800384 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700385 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700386 }
387
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700388 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700389 public void setConferenceMergeFailed(String callId, Session.Info sessionInfo) {
390 Log.startSession(sessionInfo, "CSW.sCMF");
Anthony Leece75aa12015-04-24 15:36:26 -0700391 long token = Binder.clearCallingIdentity();
392 try {
393 synchronized (mLock) {
394 logIncoming("setConferenceMergeFailed %s", callId);
Tyler Gunn8452be02015-09-17 09:57:02 -0700395 // TODO: we should move the UI for indication a merge failure here
396 // from CallNotifier.onSuppServiceFailed(). This way the InCallUI can
397 // deliver the message anyway that they want. b/20530631.
398 Call call = mCallIdMapper.getCall(callId);
399 if (call != null) {
Brad Ebinger0d402552016-05-27 16:02:53 -0700400 call.onConnectionEvent(Connection.EVENT_CALL_MERGE_FAILED, null);
Tyler Gunn8452be02015-09-17 09:57:02 -0700401 } else {
402 Log.w(this, "setConferenceMergeFailed, unknown call id: %s", callId);
Anthony Leece75aa12015-04-24 15:36:26 -0700403 }
Anthony Leece75aa12015-04-24 15:36:26 -0700404 }
Hall Liu62630f72018-05-10 17:48:59 -0700405 } catch (Throwable t) {
406 Log.e(ConnectionServiceWrapper.this, t, "");
407 throw t;
Anthony Leece75aa12015-04-24 15:36:26 -0700408 } finally {
409 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800410 Log.endSession();
Anthony Leece75aa12015-04-24 15:36:26 -0700411 }
412 }
413
414 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700415 public void addConferenceCall(String callId, ParcelableConference parcelableConference,
416 Session.Info sessionInfo) {
417 Log.startSession(sessionInfo, LogUtils.Sessions.CSW_ADD_CONFERENCE_CALL);
Ihab Awad512d6352015-03-26 13:43:22 -0700418 long token = Binder.clearCallingIdentity();
419 try {
420 synchronized (mLock) {
421 if (mCallIdMapper.getCall(callId) != null) {
422 Log.w(this, "Attempting to add a conference call using an existing " +
423 "call id %s", callId);
424 return;
425 }
Tyler Gunn9b618b82016-10-17 15:54:35 -0700426 logIncoming("addConferenceCall %s %s [%s]", callId, parcelableConference,
427 parcelableConference.getConnectionIds());
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700428
Ihab Awad512d6352015-03-26 13:43:22 -0700429 // Make sure that there's at least one valid call. For remote connections
430 // we'll get a add conference msg from both the remote connection service
431 // and from the real connection service.
432 boolean hasValidCalls = false;
433 for (String connId : parcelableConference.getConnectionIds()) {
434 if (mCallIdMapper.getCall(connId) != null) {
435 hasValidCalls = true;
436 }
437 }
438 // But don't bail out if the connection count is 0, because that is a valid
439 // IMS conference state.
440 if (!hasValidCalls && parcelableConference.getConnectionIds().size() > 0) {
441 Log.d(this, "Attempting to add a conference with no valid calls");
442 return;
443 }
444
Ihab Awad512d6352015-03-26 13:43:22 -0700445 PhoneAccountHandle phAcc = null;
446 if (parcelableConference != null &&
447 parcelableConference.getPhoneAccount() != null) {
448 phAcc = parcelableConference.getPhoneAccount();
449 }
Tyler Gunn9b618b82016-10-17 15:54:35 -0700450
451 Bundle connectionExtras = parcelableConference.getExtras();
452
453 String connectIdToCheck = null;
454 if (connectionExtras != null && connectionExtras
455 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
456 // Conference was added via a connection manager, see if its original id is
457 // known.
458 connectIdToCheck = connectionExtras
459 .getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
460 } else {
461 connectIdToCheck = callId;
462 }
463
464 Call conferenceCall;
465 // Check to see if this conference has already been added.
466 Call alreadyAddedConnection = mCallsManager
467 .getAlreadyAddedConnection(connectIdToCheck);
468 if (alreadyAddedConnection != null && mCallIdMapper.getCall(callId) == null) {
469 // We are currently attempting to add the conference via a connection mgr,
470 // and the originating ConnectionService has already added it. Instead of
471 // making a new Telecom call, we will simply add it to the ID mapper here,
472 // and replace the ConnectionService on the call.
473 mCallIdMapper.addCall(alreadyAddedConnection, callId);
474 alreadyAddedConnection.replaceConnectionService(
475 ConnectionServiceWrapper.this);
476 conferenceCall = alreadyAddedConnection;
477 } else {
478 // need to create a new Call
479 Call newConferenceCall = mCallsManager.createConferenceCall(callId,
480 phAcc, parcelableConference);
481 mCallIdMapper.addCall(newConferenceCall, callId);
482 newConferenceCall.setConnectionService(ConnectionServiceWrapper.this);
483 conferenceCall = newConferenceCall;
484 }
Ihab Awad512d6352015-03-26 13:43:22 -0700485
486 Log.d(this, "adding children to conference %s phAcc %s",
487 parcelableConference.getConnectionIds(), phAcc);
488 for (String connId : parcelableConference.getConnectionIds()) {
489 Call childCall = mCallIdMapper.getCall(connId);
490 Log.d(this, "found child: %s", connId);
491 if (childCall != null) {
Tyler Gunn76581712017-05-09 14:39:42 -0700492 childCall.setParentAndChildCall(conferenceCall);
Ihab Awad512d6352015-03-26 13:43:22 -0700493 }
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700494 }
495 }
Hall Liu62630f72018-05-10 17:48:59 -0700496 } catch (Throwable t) {
497 Log.e(ConnectionServiceWrapper.this, t, "");
498 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700499 } finally {
500 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800501 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700502 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700503 }
504
505 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700506 public void onPostDialWait(String callId, String remaining,
507 Session.Info sessionInfo) throws RemoteException {
508 Log.startSession(sessionInfo, "CSW.oPDW");
Ihab Awad512d6352015-03-26 13:43:22 -0700509 long token = Binder.clearCallingIdentity();
510 try {
511 synchronized (mLock) {
512 logIncoming("onPostDialWait %s %s", callId, remaining);
Tyler Gunn8452be02015-09-17 09:57:02 -0700513 Call call = mCallIdMapper.getCall(callId);
514 if (call != null) {
515 call.onPostDialWait(remaining);
516 } else {
517 // Log.w(this, "onPostDialWait, unknown call id: %s", args.arg1);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700518 }
519 }
Hall Liu62630f72018-05-10 17:48:59 -0700520 } catch (Throwable t) {
521 Log.e(ConnectionServiceWrapper.this, t, "");
522 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700523 } finally {
524 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800525 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700526 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700527 }
528
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700529 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700530 public void onPostDialChar(String callId, char nextChar,
531 Session.Info sessionInfo) throws RemoteException {
532 Log.startSession(sessionInfo, "CSW.oPDC");
Ihab Awad512d6352015-03-26 13:43:22 -0700533 long token = Binder.clearCallingIdentity();
534 try {
535 synchronized (mLock) {
536 logIncoming("onPostDialChar %s %s", callId, nextChar);
Tyler Gunn8452be02015-09-17 09:57:02 -0700537 Call call = mCallIdMapper.getCall(callId);
538 if (call != null) {
539 call.onPostDialChar(nextChar);
540 } else {
541 // Log.w(this, "onPostDialChar, unknown call id: %s", args.arg1);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700542 }
543 }
Hall Liu62630f72018-05-10 17:48:59 -0700544 } catch (Throwable t) {
545 Log.e(ConnectionServiceWrapper.this, t, "");
546 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700547 } finally {
548 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800549 Log.endSession();
Nancy Chena469f762014-12-09 18:29:20 -0800550 }
551 }
552
553 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700554 public void queryRemoteConnectionServices(RemoteServiceCallback callback,
555 Session.Info sessionInfo) {
Tony Mak240656f2015-12-04 11:36:22 +0000556 final UserHandle callingUserHandle = Binder.getCallingUserHandle();
Brad Ebinger65912752016-10-28 12:32:06 -0700557 Log.startSession(sessionInfo, "CSW.qRCS");
Ihab Awad512d6352015-03-26 13:43:22 -0700558 long token = Binder.clearCallingIdentity();
559 try {
560 synchronized (mLock) {
561 logIncoming("queryRemoteConnectionServices %s", callback);
Tony Mak240656f2015-12-04 11:36:22 +0000562 ConnectionServiceWrapper.this
563 .queryRemoteConnectionServices(callingUserHandle, callback);
Ihab Awad512d6352015-03-26 13:43:22 -0700564 }
Hall Liu62630f72018-05-10 17:48:59 -0700565 } catch (Throwable t) {
566 Log.e(ConnectionServiceWrapper.this, t, "");
567 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700568 } finally {
569 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800570 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700571 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700572 }
573
574 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700575 public void setVideoState(String callId, int videoState, Session.Info sessionInfo) {
576 Log.startSession(sessionInfo, "CSW.sVS");
Ihab Awad512d6352015-03-26 13:43:22 -0700577 long token = Binder.clearCallingIdentity();
578 try {
579 synchronized (mLock) {
580 logIncoming("setVideoState %s %d", callId, videoState);
Tyler Gunn8452be02015-09-17 09:57:02 -0700581 Call call = mCallIdMapper.getCall(callId);
582 if (call != null) {
583 call.setVideoState(videoState);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700584 }
585 }
Hall Liu62630f72018-05-10 17:48:59 -0700586 } catch (Throwable t) {
587 Log.e(ConnectionServiceWrapper.this, t, "");
588 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700589 } finally {
590 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800591 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700592 }
Tyler Gunn0a388fc2014-07-17 12:21:17 -0700593 }
594
595 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700596 public void setIsVoipAudioMode(String callId, boolean isVoip, Session.Info sessionInfo) {
597 Log.startSession(sessionInfo, "CSW.sIVAM");
Ihab Awad512d6352015-03-26 13:43:22 -0700598 long token = Binder.clearCallingIdentity();
599 try {
600 synchronized (mLock) {
601 logIncoming("setIsVoipAudioMode %s %b", callId, isVoip);
Tyler Gunn8452be02015-09-17 09:57:02 -0700602 Call call = mCallIdMapper.getCall(callId);
603 if (call != null) {
604 call.setIsVoipAudioMode(isVoip);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700605 }
606 }
Hall Liu62630f72018-05-10 17:48:59 -0700607 } catch (Throwable t) {
608 Log.e(ConnectionServiceWrapper.this, t, "");
609 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700610 } finally {
611 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800612 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700613 }
Sailesh Nepal7e669572014-07-08 21:29:12 -0700614 }
Sailesh Nepal35faf8c2014-07-08 22:02:34 -0700615
616 @Override
Hall Liu9086fb12017-11-07 18:01:53 -0800617 public void setAudioRoute(String callId, int audioRoute,
618 String bluetoothAddress, Session.Info sessionInfo) {
Tyler Gunnacb3bc82017-01-09 09:43:56 -0800619 Log.startSession(sessionInfo, "CSW.sAR");
620 long token = Binder.clearCallingIdentity();
621 try {
622 synchronized (mLock) {
623 logIncoming("setAudioRoute %s %s", callId,
624 CallAudioState.audioRouteToString(audioRoute));
Hall Liu9086fb12017-11-07 18:01:53 -0800625 mCallsManager.setAudioRoute(audioRoute, bluetoothAddress);
Tyler Gunnacb3bc82017-01-09 09:43:56 -0800626 }
Hall Liu62630f72018-05-10 17:48:59 -0700627 } catch (Throwable t) {
628 Log.e(ConnectionServiceWrapper.this, t, "");
629 throw t;
Tyler Gunnacb3bc82017-01-09 09:43:56 -0800630 } finally {
631 Binder.restoreCallingIdentity(token);
632 Log.endSession();
633 }
634 }
635
636 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700637 public void setStatusHints(String callId, StatusHints statusHints,
638 Session.Info sessionInfo) {
639 Log.startSession(sessionInfo, "CSW.sSH");
Ihab Awad512d6352015-03-26 13:43:22 -0700640 long token = Binder.clearCallingIdentity();
641 try {
642 synchronized (mLock) {
643 logIncoming("setStatusHints %s %s", callId, statusHints);
Tyler Gunn8452be02015-09-17 09:57:02 -0700644 Call call = mCallIdMapper.getCall(callId);
645 if (call != null) {
646 call.setStatusHints(statusHints);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700647 }
648 }
Hall Liu62630f72018-05-10 17:48:59 -0700649 } catch (Throwable t) {
650 Log.e(ConnectionServiceWrapper.this, t, "");
651 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700652 } finally {
653 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800654 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700655 }
Sailesh Nepal35faf8c2014-07-08 22:02:34 -0700656 }
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700657
658 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700659 public void putExtras(String callId, Bundle extras, Session.Info sessionInfo) {
660 Log.startSession(sessionInfo, "CSW.pE");
Santos Cordonb3907b32015-05-27 17:39:59 -0700661 long token = Binder.clearCallingIdentity();
662 try {
Brad Ebinger11623a32015-11-25 13:52:02 -0800663 synchronized (mLock) {
Jeff Sharkeye2e4cdf2016-03-18 12:19:02 -0600664 Bundle.setDefusable(extras, true);
Tyler Gunn8452be02015-09-17 09:57:02 -0700665 Call call = mCallIdMapper.getCall(callId);
666 if (call != null) {
Tyler Gunn961694a2016-03-21 16:01:40 -0700667 call.putExtras(Call.SOURCE_CONNECTION_SERVICE, extras);
668 }
669 }
Hall Liu62630f72018-05-10 17:48:59 -0700670 } catch (Throwable t) {
671 Log.e(ConnectionServiceWrapper.this, t, "");
672 throw t;
Tyler Gunn961694a2016-03-21 16:01:40 -0700673 } finally {
674 Binder.restoreCallingIdentity(token);
675 Log.endSession();
676 }
677 }
678
679 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700680 public void removeExtras(String callId, List<String> keys, Session.Info sessionInfo) {
681 Log.startSession(sessionInfo, "CSW.rE");
Tyler Gunn961694a2016-03-21 16:01:40 -0700682 long token = Binder.clearCallingIdentity();
683 try {
684 synchronized (mLock) {
685 logIncoming("removeExtra %s %s", callId, keys);
686 Call call = mCallIdMapper.getCall(callId);
687 if (call != null) {
688 call.removeExtras(Call.SOURCE_CONNECTION_SERVICE, keys);
Santos Cordonb3907b32015-05-27 17:39:59 -0700689 }
690 }
Hall Liu62630f72018-05-10 17:48:59 -0700691 } catch (Throwable t) {
692 Log.e(ConnectionServiceWrapper.this, t, "");
693 throw t;
Santos Cordonb3907b32015-05-27 17:39:59 -0700694 } finally {
695 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800696 Log.endSession();
Santos Cordonb3907b32015-05-27 17:39:59 -0700697 }
698 }
699
700 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700701 public void setAddress(String callId, Uri address, int presentation,
702 Session.Info sessionInfo) {
703 Log.startSession(sessionInfo, "CSW.sA");
Ihab Awad512d6352015-03-26 13:43:22 -0700704 long token = Binder.clearCallingIdentity();
705 try {
706 synchronized (mLock) {
707 logIncoming("setAddress %s %s %d", callId, address, presentation);
Tyler Gunn8452be02015-09-17 09:57:02 -0700708 Call call = mCallIdMapper.getCall(callId);
709 if (call != null) {
710 call.setHandle(address, presentation);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700711 }
712 }
Hall Liu62630f72018-05-10 17:48:59 -0700713 } catch (Throwable t) {
714 Log.e(ConnectionServiceWrapper.this, t, "");
715 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700716 } finally {
717 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800718 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700719 }
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700720 }
721
722 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700723 public void setCallerDisplayName(String callId, String callerDisplayName, int presentation,
724 Session.Info sessionInfo) {
725 Log.startSession(sessionInfo, "CSW.sCDN");
Ihab Awad512d6352015-03-26 13:43:22 -0700726 long token = Binder.clearCallingIdentity();
727 try {
728 synchronized (mLock) {
729 logIncoming("setCallerDisplayName %s %s %d", callId, callerDisplayName,
730 presentation);
Tyler Gunn8452be02015-09-17 09:57:02 -0700731 Call call = mCallIdMapper.getCall(callId);
732 if (call != null) {
733 call.setCallerDisplayName(callerDisplayName, presentation);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700734 }
735 }
Hall Liu62630f72018-05-10 17:48:59 -0700736 } catch (Throwable t) {
737 Log.e(ConnectionServiceWrapper.this, t, "");
738 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700739 } finally {
740 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800741 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700742 }
Sailesh Nepale8ecb982014-07-11 17:19:42 -0700743 }
Sailesh Nepal9d58de52014-07-18 14:53:19 -0700744
745 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700746 public void setConferenceableConnections(String callId, List<String> conferenceableCallIds,
747 Session.Info sessionInfo) {
748 Log.startSession(sessionInfo, "CSW.sCC");
Ihab Awad512d6352015-03-26 13:43:22 -0700749 long token = Binder.clearCallingIdentity();
750 try {
751 synchronized (mLock) {
Tyler Gunn9b618b82016-10-17 15:54:35 -0700752
Tyler Gunn8452be02015-09-17 09:57:02 -0700753 Call call = mCallIdMapper.getCall(callId);
754 if (call != null) {
Tyler Gunn9b618b82016-10-17 15:54:35 -0700755 logIncoming("setConferenceableConnections %s %s", callId,
756 conferenceableCallIds);
Tyler Gunn8452be02015-09-17 09:57:02 -0700757 List<Call> conferenceableCalls =
758 new ArrayList<>(conferenceableCallIds.size());
759 for (String otherId : conferenceableCallIds) {
760 Call otherCall = mCallIdMapper.getCall(otherId);
761 if (otherCall != null && otherCall != call) {
762 conferenceableCalls.add(otherCall);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700763 }
764 }
Tyler Gunn8452be02015-09-17 09:57:02 -0700765 call.setConferenceableCalls(conferenceableCalls);
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700766 }
767 }
Hall Liu62630f72018-05-10 17:48:59 -0700768 } catch (Throwable t) {
769 Log.e(ConnectionServiceWrapper.this, t, "");
770 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700771 } finally {
772 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800773 Log.endSession();
Jay Shrauner969755a2014-08-11 20:34:43 -0700774 }
Santos Cordon12d61822014-07-29 16:02:20 -0700775 }
Tyler Gunn6e2b94e2014-10-30 11:05:22 -0700776
777 @Override
Hall Liu62630f72018-05-10 17:48:59 -0700778 public void addExistingConnection(String callId, ParcelableConnection connection,
779 Session.Info sessionInfo) {
Brad Ebinger65912752016-10-28 12:32:06 -0700780 Log.startSession(sessionInfo, "CSW.aEC");
Brad Ebinger91350952016-06-29 17:27:08 -0700781 UserHandle userHandle = Binder.getCallingUserHandle();
782 // Check that the Calling Package matches PhoneAccountHandle's Component Package
783 PhoneAccountHandle callingPhoneAccountHandle = connection.getPhoneAccount();
784 if (callingPhoneAccountHandle != null) {
785 mAppOpsManager.checkPackage(Binder.getCallingUid(),
786 callingPhoneAccountHandle.getComponentName().getPackageName());
787 }
Ihab Awad512d6352015-03-26 13:43:22 -0700788 long token = Binder.clearCallingIdentity();
789 try {
790 synchronized (mLock) {
Brad Ebinger91350952016-06-29 17:27:08 -0700791 // Make sure that the PhoneAccount associated with the incoming
792 // ParcelableConnection is in fact registered to Telecom and is being called
793 // from the correct user.
794 List<PhoneAccountHandle> accountHandles =
795 mPhoneAccountRegistrar.getCallCapablePhoneAccounts(null /*uriScheme*/,
796 false /*includeDisabledAccounts*/, userHandle);
797 PhoneAccountHandle phoneAccountHandle = null;
798 for (PhoneAccountHandle accountHandle : accountHandles) {
799 if(accountHandle.equals(callingPhoneAccountHandle)) {
800 phoneAccountHandle = accountHandle;
801 }
802 }
Tyler Gunn9b618b82016-10-17 15:54:35 -0700803 // Allow the Sim call manager account as well, even if its disabled.
804 if (phoneAccountHandle == null && callingPhoneAccountHandle != null) {
805 if (callingPhoneAccountHandle.equals(
806 mPhoneAccountRegistrar.getSimCallManager(userHandle))) {
807 phoneAccountHandle = callingPhoneAccountHandle;
808 }
809 }
Brad Ebinger91350952016-06-29 17:27:08 -0700810 if (phoneAccountHandle != null) {
Tyler Gunn9b618b82016-10-17 15:54:35 -0700811 logIncoming("addExistingConnection %s %s", callId, connection);
812
813 Bundle connectionExtras = connection.getExtras();
814 String connectIdToCheck = null;
815 if (connectionExtras != null && connectionExtras
816 .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
817 connectIdToCheck = connectionExtras
818 .getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID);
819 } else {
820 connectIdToCheck = callId;
821 }
822 // Check to see if this Connection has already been added.
823 Call alreadyAddedConnection = mCallsManager
824 .getAlreadyAddedConnection(connectIdToCheck);
825
826 if (alreadyAddedConnection != null
827 && mCallIdMapper.getCall(callId) == null) {
828 mCallIdMapper.addCall(alreadyAddedConnection, callId);
829 alreadyAddedConnection
830 .replaceConnectionService(ConnectionServiceWrapper.this);
831 return;
832 }
833
Brad Ebinger91350952016-06-29 17:27:08 -0700834 Call existingCall = mCallsManager
835 .createCallForExistingConnection(callId, connection);
836 mCallIdMapper.addCall(existingCall, callId);
837 existingCall.setConnectionService(ConnectionServiceWrapper.this);
838 } else {
839 Log.e(this, new RemoteException("The PhoneAccount being used is not " +
840 "currently registered with Telecom."), "Unable to " +
841 "addExistingConnection.");
842 }
Ihab Awad512d6352015-03-26 13:43:22 -0700843 }
Hall Liu62630f72018-05-10 17:48:59 -0700844 } catch (Throwable t) {
845 Log.e(ConnectionServiceWrapper.this, t, "");
846 throw t;
Ihab Awad512d6352015-03-26 13:43:22 -0700847 } finally {
848 Binder.restoreCallingIdentity(token);
Brad Ebinger11623a32015-11-25 13:52:02 -0800849 Log.endSession();
Ihab Awad8d5d9dd2015-03-12 11:11:06 -0700850 }
Tyler Gunn6e2b94e2014-10-30 11:05:22 -0700851 }
Tyler Gunndb821912016-02-16 14:35:25 -0800852
853 @Override
Brad Ebinger65912752016-10-28 12:32:06 -0700854 public void onConnectionEvent(String callId, String event, Bundle extras,
855 Session.Info sessionInfo) {
856 Log.startSession(sessionInfo, "CSW.oCE");
Tyler Gunndb821912016-02-16 14:35:25 -0800857 long token = Binder.clearCallingIdentity();
858 try {
859 synchronized (mLock) {
Jeff Sharkeye2e4cdf2016-03-18 12:19:02 -0600860 Bundle.setDefusable(extras, true);
Tyler Gunndb821912016-02-16 14:35:25 -0800861 Call call = mCallIdMapper.getCall(callId);
862 if (call != null) {
Tyler Gunnd45e6d92016-03-10 20:15:39 -0800863 call.onConnectionEvent(event, extras);
Tyler Gunndb821912016-02-16 14:35:25 -0800864 }
865 }
Hall Liu62630f72018-05-10 17:48:59 -0700866 } catch (Throwable t) {
867 Log.e(ConnectionServiceWrapper.this, t, "");
868 throw t;
Tyler Gunndb821912016-02-16 14:35:25 -0800869 } finally {
870 Binder.restoreCallingIdentity(token);
871 Log.endSession();
872 }
873 }
Hall Liuaeece4e2017-02-14 16:42:12 -0800874
875 @Override
876 public void onRttInitiationSuccess(String callId, Session.Info sessionInfo)
877 throws RemoteException {
878
879 }
880
881 @Override
882 public void onRttInitiationFailure(String callId, int reason, Session.Info sessionInfo)
883 throws RemoteException {
884 Log.startSession(sessionInfo, "CSW.oRIF");
885 long token = Binder.clearCallingIdentity();
886 try {
887 synchronized (mLock) {
888 Call call = mCallIdMapper.getCall(callId);
889 if (call != null) {
890 call.onRttConnectionFailure(reason);
891 }
892 }
Hall Liu62630f72018-05-10 17:48:59 -0700893 } catch (Throwable t) {
894 Log.e(ConnectionServiceWrapper.this, t, "");
895 throw t;
Hall Liuaeece4e2017-02-14 16:42:12 -0800896 } finally {
897 Binder.restoreCallingIdentity(token);
898 Log.endSession();
899 }
900 }
901
902 @Override
903 public void onRttSessionRemotelyTerminated(String callId, Session.Info sessionInfo)
904 throws RemoteException {
905
906 }
907
908 @Override
909 public void onRemoteRttRequest(String callId, Session.Info sessionInfo)
910 throws RemoteException {
911 Log.startSession(sessionInfo, "CSW.oRRR");
912 long token = Binder.clearCallingIdentity();
913 try {
914 synchronized (mLock) {
915 Call call = mCallIdMapper.getCall(callId);
916 if (call != null) {
917 call.onRemoteRttRequest();
918 }
919 }
Hall Liu62630f72018-05-10 17:48:59 -0700920 } catch (Throwable t) {
921 Log.e(ConnectionServiceWrapper.this, t, "");
922 throw t;
Hall Liuaeece4e2017-02-14 16:42:12 -0800923 } finally {
924 Binder.restoreCallingIdentity(token);
925 Log.endSession();
926 }
927 }
Srikanth Chintala1c586c62017-05-04 20:55:01 +0530928
929 @Override
930 public void onPhoneAccountChanged(String callId, PhoneAccountHandle pHandle,
931 Session.Info sessionInfo) throws RemoteException {
Brad Ebinger702f8f52017-08-18 13:09:06 -0700932 // Check that the Calling Package matches PhoneAccountHandle's Component Package
933 if (pHandle != null) {
934 mAppOpsManager.checkPackage(Binder.getCallingUid(),
935 pHandle.getComponentName().getPackageName());
936 }
Srikanth Chintala1c586c62017-05-04 20:55:01 +0530937 Log.startSession(sessionInfo, "CSW.oPAC");
938 long token = Binder.clearCallingIdentity();
939 try {
940 synchronized (mLock) {
941 Call call = mCallIdMapper.getCall(callId);
942 if (call != null) {
943 call.setTargetPhoneAccount(pHandle);
944 }
945 }
Hall Liu62630f72018-05-10 17:48:59 -0700946 } catch (Throwable t) {
947 Log.e(ConnectionServiceWrapper.this, t, "");
948 throw t;
Srikanth Chintala1c586c62017-05-04 20:55:01 +0530949 } finally {
950 Binder.restoreCallingIdentity(token);
951 Log.endSession();
952 }
953 }
Pengquan Meng4845c9b2017-12-01 12:03:28 -0800954
955 @Override
956 public void onConnectionServiceFocusReleased(Session.Info sessionInfo)
957 throws RemoteException {
Pengquan Meng4832f202017-12-20 16:13:04 -0800958 Log.startSession(sessionInfo, "CSW.oCSFR");
959 long token = Binder.clearCallingIdentity();
960 try {
961 synchronized (mLock) {
962 mConnSvrFocusListener.onConnectionServiceReleased(
963 ConnectionServiceWrapper.this);
964 }
Hall Liu62630f72018-05-10 17:48:59 -0700965 } catch (Throwable t) {
966 Log.e(ConnectionServiceWrapper.this, t, "");
967 throw t;
Pengquan Meng4832f202017-12-20 16:13:04 -0800968 } finally {
969 Binder.restoreCallingIdentity(token);
970 Log.endSession();
971 }
Pengquan Meng4845c9b2017-12-01 12:03:28 -0800972 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700973 }
974
975 private final Adapter mAdapter = new Adapter();
Brad Ebinger6e8f3d72016-06-20 11:35:42 -0700976 private final CallIdMapper mCallIdMapper = new CallIdMapper(Call::getConnectionId);
Sailesh Nepal664837f2014-07-14 16:31:51 -0700977 private final Map<String, CreateConnectionResponse> mPendingResponses = new HashMap<>();
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700978
Ihab Awad512d6352015-03-26 13:43:22 -0700979 private Binder2 mBinder = new Binder2();
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700980 private IConnectionService mServiceInterface;
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700981 private final ConnectionServiceRepository mConnectionServiceRepository;
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700982 private final PhoneAccountRegistrar mPhoneAccountRegistrar;
Ihab Awad8de76912015-02-17 12:25:52 -0800983 private final CallsManager mCallsManager;
Brad Ebinger91350952016-06-29 17:27:08 -0700984 private final AppOpsManager mAppOpsManager;
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700985
Pengquan Mengd7f92cf2017-11-21 17:52:42 -0800986 private ConnectionServiceFocusManager.ConnectionServiceFocusListener mConnSvrFocusListener;
987
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700988 /**
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700989 * Creates a connection service.
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700990 *
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700991 * @param componentName The component name of the service with which to bind.
Sailesh Nepal905dfba2014-07-14 08:20:41 -0700992 * @param connectionServiceRepository Connection service repository.
Ihab Awadb78b2762014-07-25 15:16:23 -0700993 * @param phoneAccountRegistrar Phone account registrar
Ihab Awad8de76912015-02-17 12:25:52 -0800994 * @param callsManager Calls manager
Tyler Gunn91d43cf2014-09-17 12:19:39 -0700995 * @param context The context.
Evan Charlton105d9772014-11-25 14:08:53 -0800996 * @param userHandle The {@link UserHandle} to use when binding.
Sailesh Nepalc92c4362014-07-04 18:33:21 -0700997 */
998 ConnectionServiceWrapper(
Ihab Awadb78b2762014-07-25 15:16:23 -0700999 ComponentName componentName,
1000 ConnectionServiceRepository connectionServiceRepository,
Tyler Gunn91d43cf2014-09-17 12:19:39 -07001001 PhoneAccountRegistrar phoneAccountRegistrar,
Ihab Awad8de76912015-02-17 12:25:52 -08001002 CallsManager callsManager,
Evan Charlton105d9772014-11-25 14:08:53 -08001003 Context context,
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001004 TelecomSystem.SyncRoot lock,
Evan Charlton105d9772014-11-25 14:08:53 -08001005 UserHandle userHandle) {
Ihab Awad8d5d9dd2015-03-12 11:11:06 -07001006 super(ConnectionService.SERVICE_INTERFACE, componentName, context, lock, userHandle);
Sailesh Nepal905dfba2014-07-14 08:20:41 -07001007 mConnectionServiceRepository = connectionServiceRepository;
Ihab Awadb78b2762014-07-25 15:16:23 -07001008 phoneAccountRegistrar.addListener(new PhoneAccountRegistrar.Listener() {
1009 // TODO -- Upon changes to PhoneAccountRegistrar, need to re-wire connections
1010 // To do this, we must proxy remote ConnectionService objects
1011 });
Tyler Gunn91d43cf2014-09-17 12:19:39 -07001012 mPhoneAccountRegistrar = phoneAccountRegistrar;
Ihab Awad8de76912015-02-17 12:25:52 -08001013 mCallsManager = callsManager;
Brad Ebinger91350952016-06-29 17:27:08 -07001014 mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001015 }
1016
1017 /** See {@link IConnectionService#addConnectionServiceAdapter}. */
1018 private void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) {
1019 if (isServiceValid("addConnectionServiceAdapter")) {
1020 try {
Sailesh Nepal3fe8b722014-07-08 10:07:26 -07001021 logOutgoing("addConnectionServiceAdapter %s", adapter);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001022 mServiceInterface.addConnectionServiceAdapter(adapter, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001023 } catch (RemoteException e) {
1024 }
1025 }
1026 }
1027
Brad Ebinger6e8f3d72016-06-20 11:35:42 -07001028 /** See {@link IConnectionService#removeConnectionServiceAdapter}. */
1029 private void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) {
1030 if (isServiceValid("removeConnectionServiceAdapter")) {
1031 try {
1032 logOutgoing("removeConnectionServiceAdapter %s", adapter);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001033 mServiceInterface.removeConnectionServiceAdapter(adapter, Log.getExternalSession());
Brad Ebinger6e8f3d72016-06-20 11:35:42 -07001034 } catch (RemoteException e) {
1035 }
1036 }
1037 }
1038
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001039 /**
Sailesh Nepal664837f2014-07-14 16:31:51 -07001040 * Creates a new connection for a new outgoing call or to attach to an existing incoming call.
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001041 */
Brad Ebingerf1900072015-11-12 17:25:06 -08001042 @VisibleForTesting
1043 public void createConnection(final Call call, final CreateConnectionResponse response) {
Sailesh Nepal664837f2014-07-14 16:31:51 -07001044 Log.d(this, "createConnection(%s) via %s.", call, getComponentName());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001045 BindCallback callback = new BindCallback() {
1046 @Override
1047 public void onSuccess() {
1048 String callId = mCallIdMapper.getCallId(call);
Sailesh Nepal664837f2014-07-14 16:31:51 -07001049 mPendingResponses.put(callId, response);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001050
1051 GatewayInfo gatewayInfo = call.getGatewayInfo();
Santos Cordonb3907b32015-05-27 17:39:59 -07001052 Bundle extras = call.getIntentExtras();
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001053 if (gatewayInfo != null && gatewayInfo.getGatewayProviderPackageName() != null &&
Nancy Chen201b4372014-09-08 14:18:24 -07001054 gatewayInfo.getOriginalAddress() != null) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001055 extras = (Bundle) extras.clone();
1056 extras.putString(
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001057 TelecomManager.GATEWAY_PROVIDER_PACKAGE,
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001058 gatewayInfo.getGatewayProviderPackageName());
1059 extras.putParcelable(
Tyler Gunn7cc70b42014-09-12 22:17:27 -07001060 TelecomManager.GATEWAY_ORIGINAL_ADDRESS,
Nancy Chen201b4372014-09-08 14:18:24 -07001061 gatewayInfo.getOriginalAddress());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001062 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001063
mike dooley66f26d12016-12-19 13:25:47 -08001064 if (call.isIncoming() && mCallsManager.getEmergencyCallHelper()
1065 .getLastEmergencyCallTimeMillis() > 0) {
mike dooleya2b067e2017-02-13 19:41:10 -08001066 // Add the last emergency call time to the connection request for incoming calls
1067 if (extras == call.getIntentExtras()) {
1068 extras = (Bundle) extras.clone();
1069 }
mike dooley66f26d12016-12-19 13:25:47 -08001070 extras.putLong(android.telecom.Call.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS,
1071 mCallsManager.getEmergencyCallHelper().getLastEmergencyCallTimeMillis());
mike dooley66f26d12016-12-19 13:25:47 -08001072 }
1073
Tyler Gunn6f6f1c52017-04-17 18:22:04 -07001074 // Call is incoming and added because we're handing over from another; tell CS
1075 // that its expected to handover.
Tyler Gunn141ef582017-05-26 13:38:13 -07001076 if (call.isIncoming() && call.getHandoverSourceCall() != null) {
Tyler Gunn6f6f1c52017-04-17 18:22:04 -07001077 extras.putBoolean(TelecomManager.EXTRA_IS_HANDOVER, true);
Tyler Gunn141ef582017-05-26 13:38:13 -07001078 extras.putParcelable(TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT,
1079 call.getHandoverSourceCall().getTargetPhoneAccount());
Tyler Gunn6f6f1c52017-04-17 18:22:04 -07001080 }
1081
Hall Liuaeece4e2017-02-14 16:42:12 -08001082 Log.addEvent(call, LogUtils.Events.START_CONNECTION,
1083 Log.piiHandle(call.getHandle()));
Tyler Gunna90ba732017-01-26 07:24:08 -08001084
Hall Liudd68bc32017-01-25 17:14:23 -08001085 ConnectionRequest connectionRequest = new ConnectionRequest.Builder()
1086 .setAccountHandle(call.getTargetPhoneAccount())
1087 .setAddress(call.getHandle())
Brad Ebinger6b0b6032017-02-23 17:03:01 -08001088 .setExtras(extras)
Hall Liudd68bc32017-01-25 17:14:23 -08001089 .setVideoState(call.getVideoState())
1090 .setTelecomCallId(callId)
Tyler Gunn2b17f232017-03-08 08:51:00 -08001091 // For self-managed incoming calls, if there is another ongoing call Telecom
1092 // is responsible for showing a UI to ask the user if they'd like to answer
1093 // this new incoming call.
1094 .setShouldShowIncomingCallUi(
1095 !mCallsManager.shouldShowSystemIncomingCallUi(call))
Hall Liudd68bc32017-01-25 17:14:23 -08001096 .setRttPipeFromInCall(call.getInCallToCsRttPipeForCs())
1097 .setRttPipeToInCall(call.getCsToInCallRttPipeForCs())
1098 .build();
1099
1100 try {
Ihab Awadb78b2762014-07-25 15:16:23 -07001101 mServiceInterface.createConnection(
1102 call.getConnectionManagerPhoneAccount(),
Ihab Awad6fb37c82014-08-07 19:48:57 -07001103 callId,
Hall Liudd68bc32017-01-25 17:14:23 -08001104 connectionRequest,
Hall Liu32587202015-11-18 11:10:08 -08001105 call.shouldAttachToExistingConnection(),
Brad Ebingerb78b0232016-10-24 16:40:33 -07001106 call.isUnknown(),
1107 Log.getExternalSession());
Tyler Gunna90ba732017-01-26 07:24:08 -08001108
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001109 } catch (RemoteException e) {
Sailesh Nepal664837f2014-07-14 16:31:51 -07001110 Log.e(this, e, "Failure to createConnection -- %s", getComponentName());
Ihab Awadfb5560d2014-08-18 09:32:51 -07001111 mPendingResponses.remove(callId).handleCreateConnectionFailure(
Andrew Lee701dc002014-09-11 21:29:12 -07001112 new DisconnectCause(DisconnectCause.ERROR, e.toString()));
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001113 }
1114 }
1115
1116 @Override
1117 public void onFailure() {
Sailesh Nepal905dfba2014-07-14 08:20:41 -07001118 Log.e(this, new Exception(), "Failure to call %s", getComponentName());
Andrew Lee701dc002014-09-11 21:29:12 -07001119 response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.ERROR));
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001120 }
1121 };
1122
Santos Cordon165c1ce2015-07-10 16:07:59 -07001123 mBinder.bind(callback, call);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001124 }
1125
Tyler Gunna90ba732017-01-26 07:24:08 -08001126 /**
1127 * Notifies the {@link ConnectionService} associated with a {@link Call} that the request to
1128 * create a connection has been denied or failed.
1129 * @param call The call.
1130 */
1131 void createConnectionFailed(final Call call) {
1132 Log.d(this, "createConnectionFailed(%s) via %s.", call, getComponentName());
1133 BindCallback callback = new BindCallback() {
1134 @Override
1135 public void onSuccess() {
1136 final String callId = mCallIdMapper.getCallId(call);
1137 // If still bound, tell the connection service create connection has failed.
1138 if (callId != null && isServiceValid("createConnectionFailed")) {
1139 Log.addEvent(call, LogUtils.Events.CREATE_CONNECTION_FAILED,
1140 Log.piiHandle(call.getHandle()));
1141 try {
1142 logOutgoing("createConnectionFailed %s", callId);
Tyler Gunn115c06e2017-03-02 09:29:07 -08001143 mServiceInterface.createConnectionFailed(
1144 call.getConnectionManagerPhoneAccount(),
1145 callId,
Tyler Gunna90ba732017-01-26 07:24:08 -08001146 new ConnectionRequest(
1147 call.getTargetPhoneAccount(),
1148 call.getHandle(),
1149 call.getIntentExtras(),
1150 call.getVideoState(),
1151 callId,
1152 false),
1153 call.isIncoming(),
1154 Log.getExternalSession());
1155 call.setDisconnectCause(new DisconnectCause(DisconnectCause.CANCELED));
1156 call.disconnect();
1157 } catch (RemoteException e) {
1158 }
1159 }
1160 }
1161
1162 @Override
1163 public void onFailure() {
1164 // Binding failed. Oh no.
1165 Log.w(this, "onFailure - could not bind to CS for call %s", call.getId());
1166 }
1167 };
1168
1169 mBinder.bind(callback, call);
1170 }
1171
Sanket Padawe29411c92017-11-30 16:51:08 -08001172 void handoverFailed(final Call call, final int reason) {
1173 Log.d(this, "handoverFailed(%s) via %s.", call, getComponentName());
1174 BindCallback callback = new BindCallback() {
1175 @Override
1176 public void onSuccess() {
1177 final String callId = mCallIdMapper.getCallId(call);
1178 // If still bound, tell the connection service create connection has failed.
1179 if (callId != null && isServiceValid("handoverFailed")) {
1180 Log.addEvent(call, LogUtils.Events.HANDOVER_FAILED,
1181 Log.piiHandle(call.getHandle()));
1182 try {
1183 mServiceInterface.handoverFailed(
1184 callId,
1185 new ConnectionRequest(
1186 call.getTargetPhoneAccount(),
1187 call.getHandle(),
1188 call.getIntentExtras(),
1189 call.getVideoState(),
1190 callId,
1191 false), reason, Log.getExternalSession());
1192 } catch (RemoteException e) {
1193 }
1194 }
1195 }
1196
1197 @Override
1198 public void onFailure() {
1199 // Binding failed.
1200 Log.w(this, "onFailure - could not bind to CS for call %s",
1201 call.getId());
1202 }
1203 };
1204
1205 mBinder.bind(callback, call);
1206 }
1207
Tyler Gunn7c031f22018-01-18 15:00:41 -08001208 void handoverComplete(final Call call) {
1209 Log.d(this, "handoverComplete(%s) via %s.", call, getComponentName());
1210 BindCallback callback = new BindCallback() {
1211 @Override
1212 public void onSuccess() {
1213 final String callId = mCallIdMapper.getCallId(call);
1214 // If still bound, tell the connection service create connection has failed.
1215 if (callId != null && isServiceValid("handoverComplete")) {
1216 try {
1217 mServiceInterface.handoverComplete(
1218 callId,
1219 Log.getExternalSession());
1220 } catch (RemoteException e) {
1221 }
1222 }
1223 }
1224
1225 @Override
1226 public void onFailure() {
1227 // Binding failed.
1228 Log.w(this, "onFailure - could not bind to CS for call %s",
1229 call.getId());
1230 }
1231 };
1232
1233 mBinder.bind(callback, call);
1234 }
1235
Brad Ebingerb78b0232016-10-24 16:40:33 -07001236 /** @see IConnectionService#abort(String, Session.Info) */
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001237 void abort(Call call) {
1238 // Clear out any pending outgoing call data
Jay Shrauner969755a2014-08-11 20:34:43 -07001239 final String callId = mCallIdMapper.getCallId(call);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001240
1241 // If still bound, tell the connection service to abort.
Jay Shrauner969755a2014-08-11 20:34:43 -07001242 if (callId != null && isServiceValid("abort")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001243 try {
1244 logOutgoing("abort %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001245 mServiceInterface.abort(callId, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001246 } catch (RemoteException e) {
1247 }
1248 }
1249
Andrew Lee701dc002014-09-11 21:29:12 -07001250 removeCall(call, new DisconnectCause(DisconnectCause.LOCAL));
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001251 }
1252
Brad Ebingerb78b0232016-10-24 16:40:33 -07001253 /** @see IConnectionService#silence(String, Session.Info) */
Bryce Lee6d962522015-11-30 10:28:37 -08001254 void silence(Call call) {
1255 final String callId = mCallIdMapper.getCallId(call);
1256 if (callId != null && isServiceValid("silence")) {
1257 try {
1258 logOutgoing("silence %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001259 mServiceInterface.silence(callId, Log.getExternalSession());
Bryce Lee6d962522015-11-30 10:28:37 -08001260 } catch (RemoteException e) {
1261 }
1262 }
1263 }
1264
Brad Ebingerb78b0232016-10-24 16:40:33 -07001265 /** @see IConnectionService#hold(String, Session.Info) */
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001266 void hold(Call call) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001267 final String callId = mCallIdMapper.getCallId(call);
1268 if (callId != null && isServiceValid("hold")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001269 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001270 logOutgoing("hold %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001271 mServiceInterface.hold(callId, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001272 } catch (RemoteException e) {
1273 }
1274 }
1275 }
1276
Brad Ebingerb78b0232016-10-24 16:40:33 -07001277 /** @see IConnectionService#unhold(String, Session.Info) */
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001278 void unhold(Call call) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001279 final String callId = mCallIdMapper.getCallId(call);
1280 if (callId != null && isServiceValid("unhold")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001281 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001282 logOutgoing("unhold %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001283 mServiceInterface.unhold(callId, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001284 } catch (RemoteException e) {
1285 }
1286 }
1287 }
1288
Brad Ebingerb78b0232016-10-24 16:40:33 -07001289 /** @see IConnectionService#onCallAudioStateChanged(String, CallAudioState, Session.Info) */
Hall Liuf62630a2015-10-27 14:53:39 -07001290 @VisibleForTesting
1291 public void onCallAudioStateChanged(Call activeCall, CallAudioState audioState) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001292 final String callId = mCallIdMapper.getCallId(activeCall);
Yorke Lee2a66f7b2015-05-13 14:21:19 -07001293 if (callId != null && isServiceValid("onCallAudioStateChanged")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001294 try {
Yorke Lee2a66f7b2015-05-13 14:21:19 -07001295 logOutgoing("onCallAudioStateChanged %s %s", callId, audioState);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001296 mServiceInterface.onCallAudioStateChanged(callId, audioState,
1297 Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001298 } catch (RemoteException e) {
1299 }
1300 }
1301 }
1302
Brad Ebingerb78b0232016-10-24 16:40:33 -07001303 /** @see IConnectionService#disconnect(String, Session.Info) */
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001304 void disconnect(Call call) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001305 final String callId = mCallIdMapper.getCallId(call);
1306 if (callId != null && isServiceValid("disconnect")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001307 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001308 logOutgoing("disconnect %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001309 mServiceInterface.disconnect(callId, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001310 } catch (RemoteException e) {
1311 }
1312 }
1313 }
1314
Brad Ebingerb78b0232016-10-24 16:40:33 -07001315 /** @see IConnectionService#answer(String, Session.Info) */
Andrew Lee38931d02014-07-16 10:17:36 -07001316 void answer(Call call, int videoState) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001317 final String callId = mCallIdMapper.getCallId(call);
1318 if (callId != null && isServiceValid("answer")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001319 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001320 logOutgoing("answer %s %d", callId, videoState);
Tyler Gunn467b64f2015-06-09 13:48:47 -07001321 if (VideoProfile.isAudioOnly(videoState)) {
Brad Ebingerb78b0232016-10-24 16:40:33 -07001322 mServiceInterface.answer(callId, Log.getExternalSession());
Tyler Gunn041eff62014-08-25 13:52:52 -07001323 } else {
Brad Ebingerb78b0232016-10-24 16:40:33 -07001324 mServiceInterface.answerVideo(callId, videoState, Log.getExternalSession());
Tyler Gunn041eff62014-08-25 13:52:52 -07001325 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001326 } catch (RemoteException e) {
1327 }
1328 }
1329 }
1330
Pooja Jainad4ebc02017-12-28 14:23:13 +05301331 /** @see IConnectionService#deflect(String, Uri , Session.Info) */
1332 void deflect(Call call, Uri address) {
1333 final String callId = mCallIdMapper.getCallId(call);
1334 if (callId != null && isServiceValid("deflect")) {
1335 try {
1336 logOutgoing("deflect %s", callId);
1337 mServiceInterface.deflect(callId, address, Log.getExternalSession());
1338 } catch (RemoteException e) {
1339 }
1340 }
1341 }
1342
Brad Ebingerb78b0232016-10-24 16:40:33 -07001343 /** @see IConnectionService#reject(String, Session.Info) */
Bryce Leeddd966e2015-08-28 16:33:50 -07001344 void reject(Call call, boolean rejectWithMessage, String message) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001345 final String callId = mCallIdMapper.getCallId(call);
1346 if (callId != null && isServiceValid("reject")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001347 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001348 logOutgoing("reject %s", callId);
Bryce Leeddd966e2015-08-28 16:33:50 -07001349
1350 if (rejectWithMessage && call.can(
Hall Liu4b1617a2016-03-14 16:36:08 -07001351 Connection.CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) {
Brad Ebingerb78b0232016-10-24 16:40:33 -07001352 mServiceInterface.rejectWithMessage(callId, message, Log.getExternalSession());
Bryce Leeddd966e2015-08-28 16:33:50 -07001353 } else {
Brad Ebingerb78b0232016-10-24 16:40:33 -07001354 mServiceInterface.reject(callId, Log.getExternalSession());
Bryce Leeddd966e2015-08-28 16:33:50 -07001355 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001356 } catch (RemoteException e) {
1357 }
1358 }
1359 }
1360
Brad Ebingerb78b0232016-10-24 16:40:33 -07001361 /** @see IConnectionService#playDtmfTone(String, char, Session.Info) */
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001362 void playDtmfTone(Call call, char digit) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001363 final String callId = mCallIdMapper.getCallId(call);
1364 if (callId != null && isServiceValid("playDtmfTone")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001365 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001366 logOutgoing("playDtmfTone %s %c", callId, digit);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001367 mServiceInterface.playDtmfTone(callId, digit, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001368 } catch (RemoteException e) {
1369 }
1370 }
1371 }
1372
Brad Ebingerb78b0232016-10-24 16:40:33 -07001373 /** @see IConnectionService#stopDtmfTone(String, Session.Info) */
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001374 void stopDtmfTone(Call call) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001375 final String callId = mCallIdMapper.getCallId(call);
1376 if (callId != null && isServiceValid("stopDtmfTone")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001377 try {
Brad Ebinger11623a32015-11-25 13:52:02 -08001378 logOutgoing("stopDtmfTone %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001379 mServiceInterface.stopDtmfTone(callId, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001380 } catch (RemoteException e) {
1381 }
1382 }
1383 }
1384
1385 void addCall(Call call) {
1386 if (mCallIdMapper.getCallId(call) == null) {
1387 mCallIdMapper.addCall(call);
1388 }
1389 }
1390
1391 /**
1392 * Associates newCall with this connection service by replacing callToReplace.
1393 */
1394 void replaceCall(Call newCall, Call callToReplace) {
1395 Preconditions.checkState(callToReplace.getConnectionService() == this);
1396 mCallIdMapper.replaceCall(newCall, callToReplace);
1397 }
1398
1399 void removeCall(Call call) {
Andrew Lee701dc002014-09-11 21:29:12 -07001400 removeCall(call, new DisconnectCause(DisconnectCause.ERROR));
Santos Cordonfd6ca442014-07-24 15:34:01 -07001401 }
1402
Andrew Lee701dc002014-09-11 21:29:12 -07001403 void removeCall(String callId, DisconnectCause disconnectCause) {
Ihab Awadfb5560d2014-08-18 09:32:51 -07001404 CreateConnectionResponse response = mPendingResponses.remove(callId);
1405 if (response != null) {
Andrew Lee701dc002014-09-11 21:29:12 -07001406 response.handleCreateConnectionFailure(disconnectCause);
Ihab Awadfb5560d2014-08-18 09:32:51 -07001407 }
1408
1409 mCallIdMapper.removeCall(callId);
1410 }
1411
Andrew Lee701dc002014-09-11 21:29:12 -07001412 void removeCall(Call call, DisconnectCause disconnectCause) {
Sailesh Nepal664837f2014-07-14 16:31:51 -07001413 CreateConnectionResponse response = mPendingResponses.remove(mCallIdMapper.getCallId(call));
1414 if (response != null) {
Andrew Lee701dc002014-09-11 21:29:12 -07001415 response.handleCreateConnectionFailure(disconnectCause);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001416 }
1417
1418 mCallIdMapper.removeCall(call);
1419 }
1420
1421 void onPostDialContinue(Call call, boolean proceed) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001422 final String callId = mCallIdMapper.getCallId(call);
1423 if (callId != null && isServiceValid("onPostDialContinue")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001424 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001425 logOutgoing("onPostDialContinue %s %b", callId, proceed);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001426 mServiceInterface.onPostDialContinue(callId, proceed, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001427 } catch (RemoteException ignored) {
1428 }
1429 }
1430 }
1431
Santos Cordon0fbe6322014-08-14 04:04:25 -07001432 void conference(final Call call, Call otherCall) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001433 final String callId = mCallIdMapper.getCallId(call);
Santos Cordon0fbe6322014-08-14 04:04:25 -07001434 final String otherCallId = mCallIdMapper.getCallId(otherCall);
1435 if (callId != null && otherCallId != null && isServiceValid("conference")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001436 try {
Santos Cordon0fbe6322014-08-14 04:04:25 -07001437 logOutgoing("conference %s %s", callId, otherCallId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001438 mServiceInterface.conference(callId, otherCallId, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001439 } catch (RemoteException ignored) {
1440 }
1441 }
1442 }
1443
1444 void splitFromConference(Call call) {
Jay Shrauner969755a2014-08-11 20:34:43 -07001445 final String callId = mCallIdMapper.getCallId(call);
1446 if (callId != null && isServiceValid("splitFromConference")) {
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001447 try {
Jay Shrauner969755a2014-08-11 20:34:43 -07001448 logOutgoing("splitFromConference %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001449 mServiceInterface.splitFromConference(callId, Log.getExternalSession());
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001450 } catch (RemoteException ignored) {
1451 }
1452 }
1453 }
1454
Santos Cordon68059232014-09-04 20:09:42 -07001455 void mergeConference(Call call) {
1456 final String callId = mCallIdMapper.getCallId(call);
1457 if (callId != null && isServiceValid("mergeConference")) {
1458 try {
1459 logOutgoing("mergeConference %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001460 mServiceInterface.mergeConference(callId, Log.getExternalSession());
Santos Cordon68059232014-09-04 20:09:42 -07001461 } catch (RemoteException ignored) {
1462 }
1463 }
1464 }
1465
1466 void swapConference(Call call) {
1467 final String callId = mCallIdMapper.getCallId(call);
1468 if (callId != null && isServiceValid("swapConference")) {
1469 try {
1470 logOutgoing("swapConference %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001471 mServiceInterface.swapConference(callId, Log.getExternalSession());
Santos Cordon68059232014-09-04 20:09:42 -07001472 } catch (RemoteException ignored) {
1473 }
1474 }
1475 }
1476
Tyler Gunnd45e6d92016-03-10 20:15:39 -08001477 void pullExternalCall(Call call) {
1478 final String callId = mCallIdMapper.getCallId(call);
1479 if (callId != null && isServiceValid("pullExternalCall")) {
1480 try {
1481 logOutgoing("pullExternalCall %s", callId);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001482 mServiceInterface.pullExternalCall(callId, Log.getExternalSession());
Tyler Gunnd45e6d92016-03-10 20:15:39 -08001483 } catch (RemoteException ignored) {
1484 }
1485 }
1486 }
1487
1488 void sendCallEvent(Call call, String event, Bundle extras) {
1489 final String callId = mCallIdMapper.getCallId(call);
1490 if (callId != null && isServiceValid("sendCallEvent")) {
1491 try {
1492 logOutgoing("sendCallEvent %s %s", callId, event);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001493 mServiceInterface.sendCallEvent(callId, event, extras, Log.getExternalSession());
Tyler Gunnd45e6d92016-03-10 20:15:39 -08001494 } catch (RemoteException ignored) {
1495 }
1496 }
1497 }
1498
Tyler Gunn961694a2016-03-21 16:01:40 -07001499 void onExtrasChanged(Call call, Bundle extras) {
1500 final String callId = mCallIdMapper.getCallId(call);
1501 if (callId != null && isServiceValid("onExtrasChanged")) {
1502 try {
1503 logOutgoing("onExtrasChanged %s %s", callId, extras);
Brad Ebingerb78b0232016-10-24 16:40:33 -07001504 mServiceInterface.onExtrasChanged(callId, extras, Log.getExternalSession());
Tyler Gunn961694a2016-03-21 16:01:40 -07001505 } catch (RemoteException ignored) {
1506 }
1507 }
1508 }
1509
Hall Liuaeece4e2017-02-14 16:42:12 -08001510 void startRtt(Call call, ParcelFileDescriptor fromInCall, ParcelFileDescriptor toInCall) {
1511 final String callId = mCallIdMapper.getCallId(call);
1512 if (callId != null && isServiceValid("startRtt")) {
1513 try {
1514 logOutgoing("startRtt: %s %s %s", callId, fromInCall, toInCall);
1515 mServiceInterface.startRtt(callId, fromInCall, toInCall, Log.getExternalSession());
1516 } catch (RemoteException ignored) {
1517 }
1518 }
1519 }
1520
1521 void stopRtt(Call call) {
1522 final String callId = mCallIdMapper.getCallId(call);
1523 if (callId != null && isServiceValid("stopRtt")) {
1524 try {
1525 logOutgoing("stopRtt: %s", callId);
1526 mServiceInterface.stopRtt(callId, Log.getExternalSession());
1527 } catch (RemoteException ignored) {
1528 }
1529 }
1530 }
1531
1532 void respondToRttRequest(
1533 Call call, ParcelFileDescriptor fromInCall, ParcelFileDescriptor toInCall) {
1534 final String callId = mCallIdMapper.getCallId(call);
1535 if (callId != null && isServiceValid("respondToRttRequest")) {
1536 try {
1537 logOutgoing("respondToRttRequest: %s %s %s", callId, fromInCall, toInCall);
1538 mServiceInterface.respondToRttUpgradeRequest(
1539 callId, fromInCall, toInCall, Log.getExternalSession());
1540 } catch (RemoteException ignored) {
1541 }
1542 }
1543 }
1544
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001545 /** {@inheritDoc} */
1546 @Override
1547 protected void setServiceInterface(IBinder binder) {
Brad Ebinger6e8f3d72016-06-20 11:35:42 -07001548 mServiceInterface = IConnectionService.Stub.asInterface(binder);
1549 Log.v(this, "Adding Connection Service Adapter.");
1550 addConnectionServiceAdapter(mAdapter);
1551 }
1552
1553 /** {@inheritDoc} */
1554 @Override
1555 protected void removeServiceInterface() {
1556 Log.v(this, "Removing Connection Service Adapter.");
1557 removeConnectionServiceAdapter(mAdapter);
1558 // We have lost our service connection. Notify the world that this service is done.
1559 // We must notify the adapter before CallsManager. The adapter will force any pending
1560 // outgoing calls to try the next service. This needs to happen before CallsManager
1561 // tries to clean up any calls still associated with this service.
1562 handleConnectionServiceDeath();
1563 mCallsManager.handleConnectionServiceDeath(this);
1564 mServiceInterface = null;
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001565 }
1566
Pengquan Mengd7f92cf2017-11-21 17:52:42 -08001567 @Override
1568 public void connectionServiceFocusLost() {
1569 // Immediately response to the Telecom that it has released the call resources.
1570 // TODO(mpq): Change back to the default implementation once b/69651192 done.
1571 if (mConnSvrFocusListener != null) {
Pengquan Meng4832f202017-12-20 16:13:04 -08001572 mConnSvrFocusListener.onConnectionServiceReleased(ConnectionServiceWrapper.this);
Pengquan Mengd7f92cf2017-11-21 17:52:42 -08001573 }
Pengquan Meng4832f202017-12-20 16:13:04 -08001574 BindCallback callback = new BindCallback() {
1575 @Override
1576 public void onSuccess() {
1577 try {
1578 mServiceInterface.connectionServiceFocusLost(Log.getExternalSession());
1579 } catch (RemoteException ignored) {
1580 Log.d(this, "failed to inform the focus lost event");
1581 }
1582 }
1583
1584 @Override
1585 public void onFailure() {}
1586 };
1587 mBinder.bind(callback, null /* null call */);
Pengquan Mengd7f92cf2017-11-21 17:52:42 -08001588 }
1589
1590 @Override
Pengquan Meng4832f202017-12-20 16:13:04 -08001591 public void connectionServiceFocusGained() {
1592 BindCallback callback = new BindCallback() {
1593 @Override
1594 public void onSuccess() {
1595 try {
1596 mServiceInterface.connectionServiceFocusGained(Log.getExternalSession());
1597 } catch (RemoteException ignored) {
1598 Log.d(this, "failed to inform the focus gained event");
1599 }
1600 }
1601
1602 @Override
1603 public void onFailure() {}
1604 };
1605 mBinder.bind(callback, null /* null call */);
1606 }
Pengquan Mengd7f92cf2017-11-21 17:52:42 -08001607
1608 @Override
1609 public void setConnectionServiceFocusListener(
1610 ConnectionServiceFocusManager.ConnectionServiceFocusListener listener) {
1611 mConnSvrFocusListener = listener;
1612 }
1613
Ihab Awadfb5560d2014-08-18 09:32:51 -07001614 private void handleCreateConnectionComplete(
1615 String callId,
1616 ConnectionRequest request,
1617 ParcelableConnection connection) {
1618 // TODO: Note we are not using parameter "request", which is a side effect of our tacit
1619 // assumption that we have at most one outgoing connection attempt per ConnectionService.
1620 // This may not continue to be the case.
1621 if (connection.getState() == Connection.STATE_DISCONNECTED) {
1622 // A connection that begins in the DISCONNECTED state is an indication of
1623 // failure to connect; we handle all failures uniformly
Andrew Lee701dc002014-09-11 21:29:12 -07001624 removeCall(callId, connection.getDisconnectCause());
Ihab Awadfb5560d2014-08-18 09:32:51 -07001625 } else {
1626 // Successful connection
1627 if (mPendingResponses.containsKey(callId)) {
Ihab Awad80008452014-08-23 20:35:44 -07001628 mPendingResponses.remove(callId)
1629 .handleCreateConnectionSuccess(mCallIdMapper, connection);
Ihab Awadfb5560d2014-08-18 09:32:51 -07001630 }
1631 }
1632 }
1633
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001634 /**
1635 * Called when the associated connection service dies.
1636 */
1637 private void handleConnectionServiceDeath() {
Sailesh Nepal664837f2014-07-14 16:31:51 -07001638 if (!mPendingResponses.isEmpty()) {
1639 CreateConnectionResponse[] responses = mPendingResponses.values().toArray(
1640 new CreateConnectionResponse[mPendingResponses.values().size()]);
1641 mPendingResponses.clear();
1642 for (int i = 0; i < responses.length; i++) {
Andrew Lee701dc002014-09-11 21:29:12 -07001643 responses[i].handleCreateConnectionFailure(
Tyler Gunn1a97fb22017-06-21 19:55:54 -07001644 new DisconnectCause(DisconnectCause.ERROR, "CS_DEATH"));
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001645 }
1646 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001647 mCallIdMapper.clear();
Pengquan Mengd7f92cf2017-11-21 17:52:42 -08001648
1649 if (mConnSvrFocusListener != null) {
1650 mConnSvrFocusListener.onConnectionServiceDeath(this);
1651 }
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001652 }
1653
1654 private void logIncoming(String msg, Object... params) {
Tyler Gunn9b618b82016-10-17 15:54:35 -07001655 Log.d(this, "ConnectionService -> Telecom[" + mComponentName.flattenToShortString() + "]: "
Tyler Gunn46bc3fd2017-04-03 18:53:38 +00001656 + msg, params);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001657 }
1658
1659 private void logOutgoing(String msg, Object... params) {
Tyler Gunn9b618b82016-10-17 15:54:35 -07001660 Log.d(this, "Telecom -> ConnectionService[" + mComponentName.flattenToShortString() + "]: "
Tyler Gunn46bc3fd2017-04-03 18:53:38 +00001661 + msg, params);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001662 }
1663
Tony Mak240656f2015-12-04 11:36:22 +00001664 private void queryRemoteConnectionServices(final UserHandle userHandle,
1665 final RemoteServiceCallback callback) {
Ihab Awadb78b2762014-07-25 15:16:23 -07001666 // Only give remote connection services to this connection service if it is listed as
1667 // the connection manager.
Tony Mak240656f2015-12-04 11:36:22 +00001668 PhoneAccountHandle simCallManager = mPhoneAccountRegistrar.getSimCallManager(userHandle);
Ihab Awadc17294c2014-08-04 19:23:37 -07001669 Log.d(this, "queryRemoteConnectionServices finds simCallManager = %s", simCallManager);
Ihab Awadb78b2762014-07-25 15:16:23 -07001670 if (simCallManager == null ||
1671 !simCallManager.getComponentName().equals(getComponentName())) {
1672 noRemoteServices(callback);
1673 return;
1674 }
Sailesh Nepal664837f2014-07-14 16:31:51 -07001675
Ihab Awadb78b2762014-07-25 15:16:23 -07001676 // Make a list of ConnectionServices that are listed as being associated with SIM accounts
Jay Shraunera82c8f72014-08-14 15:49:16 -07001677 final Set<ConnectionServiceWrapper> simServices = Collections.newSetFromMap(
1678 new ConcurrentHashMap<ConnectionServiceWrapper, Boolean>(8, 0.9f, 1));
Tony Mak240656f2015-12-04 11:36:22 +00001679 for (PhoneAccountHandle handle : mPhoneAccountRegistrar.getSimPhoneAccounts(userHandle)) {
Santos Cordon6a212642015-05-08 16:35:23 -07001680 ConnectionServiceWrapper service = mConnectionServiceRepository.getService(
1681 handle.getComponentName(), handle.getUserHandle());
1682 if (service != null) {
1683 simServices.add(service);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001684 }
Sailesh Nepal905dfba2014-07-14 08:20:41 -07001685 }
Ihab Awadb78b2762014-07-25 15:16:23 -07001686
1687 final List<ComponentName> simServiceComponentNames = new ArrayList<>();
1688 final List<IBinder> simServiceBinders = new ArrayList<>();
1689
1690 Log.v(this, "queryRemoteConnectionServices, simServices = %s", simServices);
1691
1692 for (ConnectionServiceWrapper simService : simServices) {
1693 if (simService == this) {
1694 // Only happens in the unlikely case that a SIM service is also a SIM call manager
1695 continue;
1696 }
1697
1698 final ConnectionServiceWrapper currentSimService = simService;
1699
1700 currentSimService.mBinder.bind(new BindCallback() {
1701 @Override
1702 public void onSuccess() {
1703 Log.d(this, "Adding simService %s", currentSimService.getComponentName());
Tyler Gunn5983dc12018-03-08 23:22:31 +00001704 if (currentSimService.mServiceInterface == null) {
1705 // The remote ConnectionService died, so do not add it.
1706 // We will still perform maybeComplete() and notify the caller with an empty
1707 // list of sim services via maybeComplete().
1708 Log.w(this, "queryRemoteConnectionServices: simService %s died - Skipping.",
1709 currentSimService.getComponentName());
1710 } else {
1711 simServiceComponentNames.add(currentSimService.getComponentName());
1712 simServiceBinders.add(currentSimService.mServiceInterface.asBinder());
1713 }
Ihab Awadb78b2762014-07-25 15:16:23 -07001714 maybeComplete();
1715 }
1716
1717 @Override
1718 public void onFailure() {
1719 Log.d(this, "Failed simService %s", currentSimService.getComponentName());
1720 // We know maybeComplete() will always be a no-op from now on, so go ahead and
1721 // signal failure of the entire request
1722 noRemoteServices(callback);
1723 }
1724
1725 private void maybeComplete() {
1726 if (simServiceComponentNames.size() == simServices.size()) {
1727 setRemoteServices(callback, simServiceComponentNames, simServiceBinders);
1728 }
1729 }
Santos Cordon165c1ce2015-07-10 16:07:59 -07001730 }, null);
Ihab Awadb78b2762014-07-25 15:16:23 -07001731 }
1732 }
1733
1734 private void setRemoteServices(
1735 RemoteServiceCallback callback,
1736 List<ComponentName> componentNames,
1737 List<IBinder> binders) {
1738 try {
1739 callback.onResult(componentNames, binders);
1740 } catch (RemoteException e) {
1741 Log.e(this, e, "Contacting ConnectionService %s",
1742 ConnectionServiceWrapper.this.getComponentName());
1743 }
1744 }
1745
1746 private void noRemoteServices(RemoteServiceCallback callback) {
Ihab Awad8de76912015-02-17 12:25:52 -08001747 setRemoteServices(callback, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
Sailesh Nepalc92c4362014-07-04 18:33:21 -07001748 }
1749}