Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1 | /* |
| 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 Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 17 | package com.android.server.telecom; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 18 | |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 19 | import android.app.AppOpsManager; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 23 | import android.os.Binder; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 25 | import android.os.IBinder; |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 26 | import android.os.ParcelFileDescriptor; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 27 | import android.os.RemoteException; |
Evan Charlton | 105d977 | 2014-11-25 14:08:53 -0800 | [diff] [blame] | 28 | import android.os.UserHandle; |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 29 | import android.telecom.CallAudioState; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 30 | import android.telecom.Connection; |
| 31 | import android.telecom.ConnectionRequest; |
| 32 | import android.telecom.ConnectionService; |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 33 | import android.telecom.DisconnectCause; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 34 | import android.telecom.GatewayInfo; |
Brad Ebinger | 953e1af | 2016-10-05 15:45:22 -0700 | [diff] [blame] | 35 | import android.telecom.Log; |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 36 | import android.telecom.Logging.Session; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 37 | import android.telecom.ParcelableConference; |
| 38 | import android.telecom.ParcelableConnection; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 39 | import android.telecom.PhoneAccountHandle; |
| 40 | import android.telecom.StatusHints; |
| 41 | import android.telecom.TelecomManager; |
| 42 | import android.telecom.VideoProfile; |
Srikanth Chintala | 1c586c6 | 2017-05-04 20:55:01 +0530 | [diff] [blame] | 43 | import android.telephony.TelephonyManager; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 44 | |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 45 | import com.android.internal.annotations.VisibleForTesting; |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 46 | import com.android.internal.telecom.IConnectionService; |
| 47 | import com.android.internal.telecom.IConnectionServiceAdapter; |
| 48 | import com.android.internal.telecom.IVideoProvider; |
| 49 | import com.android.internal.telecom.RemoteServiceCallback; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 50 | import com.android.internal.util.Preconditions; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 51 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 52 | import java.util.ArrayList; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 53 | import java.util.Collections; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 54 | import java.util.HashMap; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 55 | import java.util.List; |
| 56 | import java.util.Map; |
| 57 | import java.util.Set; |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 58 | import java.util.concurrent.ConcurrentHashMap; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 59 | |
| 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 Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 66 | @VisibleForTesting |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 67 | public class ConnectionServiceWrapper extends ServiceBinder implements |
| 68 | ConnectionServiceFocusManager.ConnectionServiceFocus { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 69 | |
| 70 | private final class Adapter extends IConnectionServiceAdapter.Stub { |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 71 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 72 | @Override |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 73 | public void handleCreateConnectionComplete(String callId, ConnectionRequest request, |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 74 | ParcelableConnection connection, Session.Info sessionInfo) { |
| 75 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_HANDLE_CREATE_CONNECTION_COMPLETE); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 76 | long token = Binder.clearCallingIdentity(); |
| 77 | try { |
| 78 | synchronized (mLock) { |
| 79 | logIncoming("handleCreateConnectionComplete %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 80 | ConnectionServiceWrapper.this |
| 81 | .handleCreateConnectionComplete(callId, request, connection); |
Tyler Gunn | ddb03e1 | 2017-05-12 11:54:41 -0700 | [diff] [blame] | 82 | |
| 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 91 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 92 | } catch (Throwable t) { |
| 93 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 94 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 95 | } finally { |
| 96 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 97 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 98 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 101 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 102 | public void setActive(String callId, Session.Info sessionInfo) { |
| 103 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ACTIVE); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 104 | long token = Binder.clearCallingIdentity(); |
| 105 | try { |
| 106 | synchronized (mLock) { |
| 107 | logIncoming("setActive %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 108 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 115 | } catch (Throwable t) { |
| 116 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 117 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 118 | } finally { |
| 119 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 120 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 121 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 124 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 125 | public void setRinging(String callId, Session.Info sessionInfo) { |
| 126 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_RINGING); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 127 | long token = Binder.clearCallingIdentity(); |
| 128 | try { |
| 129 | synchronized (mLock) { |
| 130 | logIncoming("setRinging %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 131 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 138 | } catch (Throwable t) { |
| 139 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 140 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 141 | } finally { |
| 142 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 143 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 144 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 147 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 148 | public void setVideoProvider(String callId, IVideoProvider videoProvider, |
| 149 | Session.Info sessionInfo) { |
| 150 | Log.startSession(sessionInfo, "CSW.sVP"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 151 | long token = Binder.clearCallingIdentity(); |
| 152 | try { |
| 153 | synchronized (mLock) { |
| 154 | logIncoming("setVideoProvider %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 155 | Call call = mCallIdMapper.getCall(callId); |
| 156 | if (call != null) { |
| 157 | call.setVideoProvider(videoProvider); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 158 | } |
| 159 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 160 | } catch (Throwable t) { |
| 161 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 162 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 163 | } finally { |
| 164 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 165 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 166 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 169 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 170 | public void setDialing(String callId, Session.Info sessionInfo) { |
| 171 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DIALING); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 172 | long token = Binder.clearCallingIdentity(); |
| 173 | try { |
| 174 | synchronized (mLock) { |
| 175 | logIncoming("setDialing %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 176 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 183 | } catch (Throwable t) { |
| 184 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 185 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 186 | } finally { |
| 187 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 188 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 189 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 192 | @Override |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 193 | public void setPulling(String callId, Session.Info sessionInfo) { |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 194 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_PULLING); |
Tyler Gunn | 1e37be5 | 2016-07-11 08:54:23 -0700 | [diff] [blame] | 195 | 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 Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 204 | } catch (Throwable t) { |
| 205 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 206 | throw t; |
Tyler Gunn | 1e37be5 | 2016-07-11 08:54:23 -0700 | [diff] [blame] | 207 | } finally { |
| 208 | Binder.restoreCallingIdentity(token); |
| 209 | Log.endSession(); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 214 | public void setDisconnected(String callId, DisconnectCause disconnectCause, |
| 215 | Session.Info sessionInfo) { |
| 216 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DISCONNECTED); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 217 | long token = Binder.clearCallingIdentity(); |
| 218 | try { |
| 219 | synchronized (mLock) { |
| 220 | logIncoming("setDisconnected %s %s", callId, disconnectCause); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 221 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 229 | } catch (Throwable t) { |
| 230 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 231 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 232 | } finally { |
| 233 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 234 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 235 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 238 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 239 | public void setOnHold(String callId, Session.Info sessionInfo) { |
| 240 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ON_HOLD); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 241 | long token = Binder.clearCallingIdentity(); |
| 242 | try { |
| 243 | synchronized (mLock) { |
| 244 | logIncoming("setOnHold %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 245 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 252 | } catch (Throwable t) { |
| 253 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 254 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 255 | } finally { |
| 256 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 257 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 258 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 261 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 262 | public void setRingbackRequested(String callId, boolean ringback, |
| 263 | Session.Info sessionInfo) { |
| 264 | Log.startSession(sessionInfo, "CSW.SRR"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 265 | long token = Binder.clearCallingIdentity(); |
| 266 | try { |
| 267 | synchronized (mLock) { |
| 268 | logIncoming("setRingbackRequested %s %b", callId, ringback); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 269 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 276 | } catch (Throwable t) { |
| 277 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 278 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 279 | } finally { |
| 280 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 281 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 282 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 285 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 286 | public void removeCall(String callId, Session.Info sessionInfo) { |
| 287 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_REMOVE_CALL); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 288 | long token = Binder.clearCallingIdentity(); |
| 289 | try { |
| 290 | synchronized (mLock) { |
| 291 | logIncoming("removeCall %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 292 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 302 | } catch (Throwable t) { |
| 303 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 304 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 305 | } finally { |
| 306 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 307 | Log.endSession(); |
Ihab Awad | a02bef5 | 2014-08-13 18:18:42 -0700 | [diff] [blame] | 308 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 311 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 312 | public void setConnectionCapabilities(String callId, int connectionCapabilities, |
| 313 | Session.Info sessionInfo) { |
| 314 | Log.startSession(sessionInfo, "CSW.sCC"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 315 | long token = Binder.clearCallingIdentity(); |
| 316 | try { |
| 317 | synchronized (mLock) { |
| 318 | logIncoming("setConnectionCapabilities %s %d", callId, connectionCapabilities); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 319 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 325 | } |
| 326 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 327 | } catch (Throwable t) { |
| 328 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 329 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 330 | } finally { |
| 331 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 332 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 333 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 336 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 337 | public void setConnectionProperties(String callId, int connectionProperties, |
| 338 | Session.Info sessionInfo) { |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 339 | 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 Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 349 | } catch (Throwable t) { |
| 350 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 351 | throw t; |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 352 | } finally { |
| 353 | Binder.restoreCallingIdentity(token); |
| 354 | Log.endSession(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 359 | public void setIsConferenced(String callId, String conferenceCallId, |
| 360 | Session.Info sessionInfo) { |
| 361 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_IS_CONFERENCED); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 362 | 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 Gunn | 7658171 | 2017-05-09 14:39:42 -0700 | [diff] [blame] | 370 | childCall.setParentAndChildCall(null); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 371 | } else { |
| 372 | Call conferenceCall = mCallIdMapper.getCall(conferenceCallId); |
Tyler Gunn | 7658171 | 2017-05-09 14:39:42 -0700 | [diff] [blame] | 373 | childCall.setParentAndChildCall(conferenceCall); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 374 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 375 | } else { |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 376 | // Log.w(this, "setIsConferenced, unknown call id: %s", args.arg1); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 377 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 378 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 379 | } catch (Throwable t) { |
| 380 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 381 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 382 | } finally { |
| 383 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 384 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 385 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 388 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 389 | public void setConferenceMergeFailed(String callId, Session.Info sessionInfo) { |
| 390 | Log.startSession(sessionInfo, "CSW.sCMF"); |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 391 | long token = Binder.clearCallingIdentity(); |
| 392 | try { |
| 393 | synchronized (mLock) { |
| 394 | logIncoming("setConferenceMergeFailed %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 395 | // 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 Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 400 | call.onConnectionEvent(Connection.EVENT_CALL_MERGE_FAILED, null); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 401 | } else { |
| 402 | Log.w(this, "setConferenceMergeFailed, unknown call id: %s", callId); |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 403 | } |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 404 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 405 | } catch (Throwable t) { |
| 406 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 407 | throw t; |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 408 | } finally { |
| 409 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 410 | Log.endSession(); |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 411 | } |
| 412 | } |
| 413 | |
| 414 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 415 | public void addConferenceCall(String callId, ParcelableConference parcelableConference, |
| 416 | Session.Info sessionInfo) { |
| 417 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_ADD_CONFERENCE_CALL); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 418 | 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 Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 426 | logIncoming("addConferenceCall %s %s [%s]", callId, parcelableConference, |
| 427 | parcelableConference.getConnectionIds()); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 428 | |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 429 | // 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 Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 445 | PhoneAccountHandle phAcc = null; |
| 446 | if (parcelableConference != null && |
| 447 | parcelableConference.getPhoneAccount() != null) { |
| 448 | phAcc = parcelableConference.getPhoneAccount(); |
| 449 | } |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 450 | |
| 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 Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 485 | |
| 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 Gunn | 7658171 | 2017-05-09 14:39:42 -0700 | [diff] [blame] | 492 | childCall.setParentAndChildCall(conferenceCall); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 493 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 496 | } catch (Throwable t) { |
| 497 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 498 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 499 | } finally { |
| 500 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 501 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 502 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 506 | public void onPostDialWait(String callId, String remaining, |
| 507 | Session.Info sessionInfo) throws RemoteException { |
| 508 | Log.startSession(sessionInfo, "CSW.oPDW"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 509 | long token = Binder.clearCallingIdentity(); |
| 510 | try { |
| 511 | synchronized (mLock) { |
| 512 | logIncoming("onPostDialWait %s %s", callId, remaining); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 513 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 520 | } catch (Throwable t) { |
| 521 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 522 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 523 | } finally { |
| 524 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 525 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 526 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 529 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 530 | public void onPostDialChar(String callId, char nextChar, |
| 531 | Session.Info sessionInfo) throws RemoteException { |
| 532 | Log.startSession(sessionInfo, "CSW.oPDC"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 533 | long token = Binder.clearCallingIdentity(); |
| 534 | try { |
| 535 | synchronized (mLock) { |
| 536 | logIncoming("onPostDialChar %s %s", callId, nextChar); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 537 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 544 | } catch (Throwable t) { |
| 545 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 546 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 547 | } finally { |
| 548 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 549 | Log.endSession(); |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
| 553 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 554 | public void queryRemoteConnectionServices(RemoteServiceCallback callback, |
| 555 | Session.Info sessionInfo) { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 556 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 557 | Log.startSession(sessionInfo, "CSW.qRCS"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 558 | long token = Binder.clearCallingIdentity(); |
| 559 | try { |
| 560 | synchronized (mLock) { |
| 561 | logIncoming("queryRemoteConnectionServices %s", callback); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 562 | ConnectionServiceWrapper.this |
| 563 | .queryRemoteConnectionServices(callingUserHandle, callback); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 564 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 565 | } catch (Throwable t) { |
| 566 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 567 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 568 | } finally { |
| 569 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 570 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 571 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 575 | public void setVideoState(String callId, int videoState, Session.Info sessionInfo) { |
| 576 | Log.startSession(sessionInfo, "CSW.sVS"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 577 | long token = Binder.clearCallingIdentity(); |
| 578 | try { |
| 579 | synchronized (mLock) { |
| 580 | logIncoming("setVideoState %s %d", callId, videoState); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 581 | Call call = mCallIdMapper.getCall(callId); |
| 582 | if (call != null) { |
| 583 | call.setVideoState(videoState); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 586 | } catch (Throwable t) { |
| 587 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 588 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 589 | } finally { |
| 590 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 591 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 592 | } |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 596 | public void setIsVoipAudioMode(String callId, boolean isVoip, Session.Info sessionInfo) { |
| 597 | Log.startSession(sessionInfo, "CSW.sIVAM"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 598 | long token = Binder.clearCallingIdentity(); |
| 599 | try { |
| 600 | synchronized (mLock) { |
| 601 | logIncoming("setIsVoipAudioMode %s %b", callId, isVoip); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 602 | Call call = mCallIdMapper.getCall(callId); |
| 603 | if (call != null) { |
| 604 | call.setIsVoipAudioMode(isVoip); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 605 | } |
| 606 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 607 | } catch (Throwable t) { |
| 608 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 609 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 610 | } finally { |
| 611 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 612 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 613 | } |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 614 | } |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 615 | |
| 616 | @Override |
Hall Liu | 9086fb1 | 2017-11-07 18:01:53 -0800 | [diff] [blame] | 617 | public void setAudioRoute(String callId, int audioRoute, |
| 618 | String bluetoothAddress, Session.Info sessionInfo) { |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 619 | 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 Liu | 9086fb1 | 2017-11-07 18:01:53 -0800 | [diff] [blame] | 625 | mCallsManager.setAudioRoute(audioRoute, bluetoothAddress); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 626 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 627 | } catch (Throwable t) { |
| 628 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 629 | throw t; |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 630 | } finally { |
| 631 | Binder.restoreCallingIdentity(token); |
| 632 | Log.endSession(); |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 637 | public void setStatusHints(String callId, StatusHints statusHints, |
| 638 | Session.Info sessionInfo) { |
| 639 | Log.startSession(sessionInfo, "CSW.sSH"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 640 | long token = Binder.clearCallingIdentity(); |
| 641 | try { |
| 642 | synchronized (mLock) { |
| 643 | logIncoming("setStatusHints %s %s", callId, statusHints); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 644 | Call call = mCallIdMapper.getCall(callId); |
| 645 | if (call != null) { |
| 646 | call.setStatusHints(statusHints); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 647 | } |
| 648 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 649 | } catch (Throwable t) { |
| 650 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 651 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 652 | } finally { |
| 653 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 654 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 655 | } |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 656 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 657 | |
| 658 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 659 | public void putExtras(String callId, Bundle extras, Session.Info sessionInfo) { |
| 660 | Log.startSession(sessionInfo, "CSW.pE"); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 661 | long token = Binder.clearCallingIdentity(); |
| 662 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 663 | synchronized (mLock) { |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 664 | Bundle.setDefusable(extras, true); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 665 | Call call = mCallIdMapper.getCall(callId); |
| 666 | if (call != null) { |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 667 | call.putExtras(Call.SOURCE_CONNECTION_SERVICE, extras); |
| 668 | } |
| 669 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 670 | } catch (Throwable t) { |
| 671 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 672 | throw t; |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 673 | } finally { |
| 674 | Binder.restoreCallingIdentity(token); |
| 675 | Log.endSession(); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 680 | public void removeExtras(String callId, List<String> keys, Session.Info sessionInfo) { |
| 681 | Log.startSession(sessionInfo, "CSW.rE"); |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 682 | 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 Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 689 | } |
| 690 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 691 | } catch (Throwable t) { |
| 692 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 693 | throw t; |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 694 | } finally { |
| 695 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 696 | Log.endSession(); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
| 700 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 701 | public void setAddress(String callId, Uri address, int presentation, |
| 702 | Session.Info sessionInfo) { |
| 703 | Log.startSession(sessionInfo, "CSW.sA"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 704 | long token = Binder.clearCallingIdentity(); |
| 705 | try { |
| 706 | synchronized (mLock) { |
| 707 | logIncoming("setAddress %s %s %d", callId, address, presentation); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 708 | Call call = mCallIdMapper.getCall(callId); |
| 709 | if (call != null) { |
| 710 | call.setHandle(address, presentation); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 711 | } |
| 712 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 713 | } catch (Throwable t) { |
| 714 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 715 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 716 | } finally { |
| 717 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 718 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 719 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 723 | public void setCallerDisplayName(String callId, String callerDisplayName, int presentation, |
| 724 | Session.Info sessionInfo) { |
| 725 | Log.startSession(sessionInfo, "CSW.sCDN"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 726 | long token = Binder.clearCallingIdentity(); |
| 727 | try { |
| 728 | synchronized (mLock) { |
| 729 | logIncoming("setCallerDisplayName %s %s %d", callId, callerDisplayName, |
| 730 | presentation); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 731 | Call call = mCallIdMapper.getCall(callId); |
| 732 | if (call != null) { |
| 733 | call.setCallerDisplayName(callerDisplayName, presentation); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 734 | } |
| 735 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 736 | } catch (Throwable t) { |
| 737 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 738 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 739 | } finally { |
| 740 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 741 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 742 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 743 | } |
Sailesh Nepal | 9d58de5 | 2014-07-18 14:53:19 -0700 | [diff] [blame] | 744 | |
| 745 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 746 | public void setConferenceableConnections(String callId, List<String> conferenceableCallIds, |
| 747 | Session.Info sessionInfo) { |
| 748 | Log.startSession(sessionInfo, "CSW.sCC"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 749 | long token = Binder.clearCallingIdentity(); |
| 750 | try { |
| 751 | synchronized (mLock) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 752 | |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 753 | Call call = mCallIdMapper.getCall(callId); |
| 754 | if (call != null) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 755 | logIncoming("setConferenceableConnections %s %s", callId, |
| 756 | conferenceableCallIds); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 757 | 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 Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 763 | } |
| 764 | } |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 765 | call.setConferenceableCalls(conferenceableCalls); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 766 | } |
| 767 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 768 | } catch (Throwable t) { |
| 769 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 770 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 771 | } finally { |
| 772 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 773 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 774 | } |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 775 | } |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 776 | |
| 777 | @Override |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 778 | public void addExistingConnection(String callId, ParcelableConnection connection, |
| 779 | Session.Info sessionInfo) { |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 780 | Log.startSession(sessionInfo, "CSW.aEC"); |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 781 | 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 Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 788 | long token = Binder.clearCallingIdentity(); |
| 789 | try { |
| 790 | synchronized (mLock) { |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 791 | // 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 Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 803 | // 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 Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 810 | if (phoneAccountHandle != null) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 811 | 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 Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 834 | 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 Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 843 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 844 | } catch (Throwable t) { |
| 845 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 846 | throw t; |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 847 | } finally { |
| 848 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 849 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 850 | } |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 851 | } |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 852 | |
| 853 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 854 | public void onConnectionEvent(String callId, String event, Bundle extras, |
| 855 | Session.Info sessionInfo) { |
| 856 | Log.startSession(sessionInfo, "CSW.oCE"); |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 857 | long token = Binder.clearCallingIdentity(); |
| 858 | try { |
| 859 | synchronized (mLock) { |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 860 | Bundle.setDefusable(extras, true); |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 861 | Call call = mCallIdMapper.getCall(callId); |
| 862 | if (call != null) { |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 863 | call.onConnectionEvent(event, extras); |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 864 | } |
| 865 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 866 | } catch (Throwable t) { |
| 867 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 868 | throw t; |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 869 | } finally { |
| 870 | Binder.restoreCallingIdentity(token); |
| 871 | Log.endSession(); |
| 872 | } |
| 873 | } |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 874 | |
| 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 Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 893 | } catch (Throwable t) { |
| 894 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 895 | throw t; |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 896 | } 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 Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 920 | } catch (Throwable t) { |
| 921 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 922 | throw t; |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 923 | } finally { |
| 924 | Binder.restoreCallingIdentity(token); |
| 925 | Log.endSession(); |
| 926 | } |
| 927 | } |
Srikanth Chintala | 1c586c6 | 2017-05-04 20:55:01 +0530 | [diff] [blame] | 928 | |
| 929 | @Override |
| 930 | public void onPhoneAccountChanged(String callId, PhoneAccountHandle pHandle, |
| 931 | Session.Info sessionInfo) throws RemoteException { |
Brad Ebinger | 702f8f5 | 2017-08-18 13:09:06 -0700 | [diff] [blame] | 932 | // 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 Chintala | 1c586c6 | 2017-05-04 20:55:01 +0530 | [diff] [blame] | 937 | 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 Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 946 | } catch (Throwable t) { |
| 947 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 948 | throw t; |
Srikanth Chintala | 1c586c6 | 2017-05-04 20:55:01 +0530 | [diff] [blame] | 949 | } finally { |
| 950 | Binder.restoreCallingIdentity(token); |
| 951 | Log.endSession(); |
| 952 | } |
| 953 | } |
Pengquan Meng | 4845c9b | 2017-12-01 12:03:28 -0800 | [diff] [blame] | 954 | |
| 955 | @Override |
| 956 | public void onConnectionServiceFocusReleased(Session.Info sessionInfo) |
| 957 | throws RemoteException { |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 958 | Log.startSession(sessionInfo, "CSW.oCSFR"); |
| 959 | long token = Binder.clearCallingIdentity(); |
| 960 | try { |
| 961 | synchronized (mLock) { |
| 962 | mConnSvrFocusListener.onConnectionServiceReleased( |
| 963 | ConnectionServiceWrapper.this); |
| 964 | } |
Hall Liu | 62630f7 | 2018-05-10 17:48:59 -0700 | [diff] [blame] | 965 | } catch (Throwable t) { |
| 966 | Log.e(ConnectionServiceWrapper.this, t, ""); |
| 967 | throw t; |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 968 | } finally { |
| 969 | Binder.restoreCallingIdentity(token); |
| 970 | Log.endSession(); |
| 971 | } |
Pengquan Meng | 4845c9b | 2017-12-01 12:03:28 -0800 | [diff] [blame] | 972 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | private final Adapter mAdapter = new Adapter(); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 976 | private final CallIdMapper mCallIdMapper = new CallIdMapper(Call::getConnectionId); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 977 | private final Map<String, CreateConnectionResponse> mPendingResponses = new HashMap<>(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 978 | |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 979 | private Binder2 mBinder = new Binder2(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 980 | private IConnectionService mServiceInterface; |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 981 | private final ConnectionServiceRepository mConnectionServiceRepository; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 982 | private final PhoneAccountRegistrar mPhoneAccountRegistrar; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 983 | private final CallsManager mCallsManager; |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 984 | private final AppOpsManager mAppOpsManager; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 985 | |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 986 | private ConnectionServiceFocusManager.ConnectionServiceFocusListener mConnSvrFocusListener; |
| 987 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 988 | /** |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 989 | * Creates a connection service. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 990 | * |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 991 | * @param componentName The component name of the service with which to bind. |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 992 | * @param connectionServiceRepository Connection service repository. |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 993 | * @param phoneAccountRegistrar Phone account registrar |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 994 | * @param callsManager Calls manager |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 995 | * @param context The context. |
Evan Charlton | 105d977 | 2014-11-25 14:08:53 -0800 | [diff] [blame] | 996 | * @param userHandle The {@link UserHandle} to use when binding. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 997 | */ |
| 998 | ConnectionServiceWrapper( |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 999 | ComponentName componentName, |
| 1000 | ConnectionServiceRepository connectionServiceRepository, |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1001 | PhoneAccountRegistrar phoneAccountRegistrar, |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1002 | CallsManager callsManager, |
Evan Charlton | 105d977 | 2014-11-25 14:08:53 -0800 | [diff] [blame] | 1003 | Context context, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1004 | TelecomSystem.SyncRoot lock, |
Evan Charlton | 105d977 | 2014-11-25 14:08:53 -0800 | [diff] [blame] | 1005 | UserHandle userHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 1006 | super(ConnectionService.SERVICE_INTERFACE, componentName, context, lock, userHandle); |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 1007 | mConnectionServiceRepository = connectionServiceRepository; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1008 | 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 Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 1012 | mPhoneAccountRegistrar = phoneAccountRegistrar; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1013 | mCallsManager = callsManager; |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 1014 | mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /** See {@link IConnectionService#addConnectionServiceAdapter}. */ |
| 1018 | private void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 1019 | if (isServiceValid("addConnectionServiceAdapter")) { |
| 1020 | try { |
Sailesh Nepal | 3fe8b72 | 2014-07-08 10:07:26 -0700 | [diff] [blame] | 1021 | logOutgoing("addConnectionServiceAdapter %s", adapter); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1022 | mServiceInterface.addConnectionServiceAdapter(adapter, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1023 | } catch (RemoteException e) { |
| 1024 | } |
| 1025 | } |
| 1026 | } |
| 1027 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 1028 | /** See {@link IConnectionService#removeConnectionServiceAdapter}. */ |
| 1029 | private void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 1030 | if (isServiceValid("removeConnectionServiceAdapter")) { |
| 1031 | try { |
| 1032 | logOutgoing("removeConnectionServiceAdapter %s", adapter); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1033 | mServiceInterface.removeConnectionServiceAdapter(adapter, Log.getExternalSession()); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 1034 | } catch (RemoteException e) { |
| 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1039 | /** |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1040 | * Creates a new connection for a new outgoing call or to attach to an existing incoming call. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1041 | */ |
Brad Ebinger | f190007 | 2015-11-12 17:25:06 -0800 | [diff] [blame] | 1042 | @VisibleForTesting |
| 1043 | public void createConnection(final Call call, final CreateConnectionResponse response) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1044 | Log.d(this, "createConnection(%s) via %s.", call, getComponentName()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1045 | BindCallback callback = new BindCallback() { |
| 1046 | @Override |
| 1047 | public void onSuccess() { |
| 1048 | String callId = mCallIdMapper.getCallId(call); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1049 | mPendingResponses.put(callId, response); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1050 | |
| 1051 | GatewayInfo gatewayInfo = call.getGatewayInfo(); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 1052 | Bundle extras = call.getIntentExtras(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1053 | if (gatewayInfo != null && gatewayInfo.getGatewayProviderPackageName() != null && |
Nancy Chen | 201b437 | 2014-09-08 14:18:24 -0700 | [diff] [blame] | 1054 | gatewayInfo.getOriginalAddress() != null) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1055 | extras = (Bundle) extras.clone(); |
| 1056 | extras.putString( |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 1057 | TelecomManager.GATEWAY_PROVIDER_PACKAGE, |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1058 | gatewayInfo.getGatewayProviderPackageName()); |
| 1059 | extras.putParcelable( |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 1060 | TelecomManager.GATEWAY_ORIGINAL_ADDRESS, |
Nancy Chen | 201b437 | 2014-09-08 14:18:24 -0700 | [diff] [blame] | 1061 | gatewayInfo.getOriginalAddress()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1062 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1063 | |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 1064 | if (call.isIncoming() && mCallsManager.getEmergencyCallHelper() |
| 1065 | .getLastEmergencyCallTimeMillis() > 0) { |
mike dooley | a2b067e | 2017-02-13 19:41:10 -0800 | [diff] [blame] | 1066 | // 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 dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 1070 | extras.putLong(android.telecom.Call.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS, |
| 1071 | mCallsManager.getEmergencyCallHelper().getLastEmergencyCallTimeMillis()); |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
Tyler Gunn | 6f6f1c5 | 2017-04-17 18:22:04 -0700 | [diff] [blame] | 1074 | // Call is incoming and added because we're handing over from another; tell CS |
| 1075 | // that its expected to handover. |
Tyler Gunn | 141ef58 | 2017-05-26 13:38:13 -0700 | [diff] [blame] | 1076 | if (call.isIncoming() && call.getHandoverSourceCall() != null) { |
Tyler Gunn | 6f6f1c5 | 2017-04-17 18:22:04 -0700 | [diff] [blame] | 1077 | extras.putBoolean(TelecomManager.EXTRA_IS_HANDOVER, true); |
Tyler Gunn | 141ef58 | 2017-05-26 13:38:13 -0700 | [diff] [blame] | 1078 | extras.putParcelable(TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT, |
| 1079 | call.getHandoverSourceCall().getTargetPhoneAccount()); |
Tyler Gunn | 6f6f1c5 | 2017-04-17 18:22:04 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 1082 | Log.addEvent(call, LogUtils.Events.START_CONNECTION, |
| 1083 | Log.piiHandle(call.getHandle())); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1084 | |
Hall Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 1085 | ConnectionRequest connectionRequest = new ConnectionRequest.Builder() |
| 1086 | .setAccountHandle(call.getTargetPhoneAccount()) |
| 1087 | .setAddress(call.getHandle()) |
Brad Ebinger | 6b0b603 | 2017-02-23 17:03:01 -0800 | [diff] [blame] | 1088 | .setExtras(extras) |
Hall Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 1089 | .setVideoState(call.getVideoState()) |
| 1090 | .setTelecomCallId(callId) |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 1091 | // 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 Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 1096 | .setRttPipeFromInCall(call.getInCallToCsRttPipeForCs()) |
| 1097 | .setRttPipeToInCall(call.getCsToInCallRttPipeForCs()) |
| 1098 | .build(); |
| 1099 | |
| 1100 | try { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1101 | mServiceInterface.createConnection( |
| 1102 | call.getConnectionManagerPhoneAccount(), |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1103 | callId, |
Hall Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 1104 | connectionRequest, |
Hall Liu | 3258720 | 2015-11-18 11:10:08 -0800 | [diff] [blame] | 1105 | call.shouldAttachToExistingConnection(), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1106 | call.isUnknown(), |
| 1107 | Log.getExternalSession()); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1108 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1109 | } catch (RemoteException e) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1110 | Log.e(this, e, "Failure to createConnection -- %s", getComponentName()); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1111 | mPendingResponses.remove(callId).handleCreateConnectionFailure( |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1112 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | |
| 1116 | @Override |
| 1117 | public void onFailure() { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 1118 | Log.e(this, new Exception(), "Failure to call %s", getComponentName()); |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1119 | response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.ERROR)); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1120 | } |
| 1121 | }; |
| 1122 | |
Santos Cordon | 165c1ce | 2015-07-10 16:07:59 -0700 | [diff] [blame] | 1123 | mBinder.bind(callback, call); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1126 | /** |
| 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 Gunn | 115c06e | 2017-03-02 09:29:07 -0800 | [diff] [blame] | 1143 | mServiceInterface.createConnectionFailed( |
| 1144 | call.getConnectionManagerPhoneAccount(), |
| 1145 | callId, |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1146 | 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 Padawe | 29411c9 | 2017-11-30 16:51:08 -0800 | [diff] [blame] | 1172 | 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 Gunn | 7c031f2 | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1208 | 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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1236 | /** @see IConnectionService#abort(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1237 | void abort(Call call) { |
| 1238 | // Clear out any pending outgoing call data |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1239 | final String callId = mCallIdMapper.getCallId(call); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1240 | |
| 1241 | // If still bound, tell the connection service to abort. |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1242 | if (callId != null && isServiceValid("abort")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1243 | try { |
| 1244 | logOutgoing("abort %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1245 | mServiceInterface.abort(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1246 | } catch (RemoteException e) { |
| 1247 | } |
| 1248 | } |
| 1249 | |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1250 | removeCall(call, new DisconnectCause(DisconnectCause.LOCAL)); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1253 | /** @see IConnectionService#silence(String, Session.Info) */ |
Bryce Lee | 6d96252 | 2015-11-30 10:28:37 -0800 | [diff] [blame] | 1254 | 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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1259 | mServiceInterface.silence(callId, Log.getExternalSession()); |
Bryce Lee | 6d96252 | 2015-11-30 10:28:37 -0800 | [diff] [blame] | 1260 | } catch (RemoteException e) { |
| 1261 | } |
| 1262 | } |
| 1263 | } |
| 1264 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1265 | /** @see IConnectionService#hold(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1266 | void hold(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1267 | final String callId = mCallIdMapper.getCallId(call); |
| 1268 | if (callId != null && isServiceValid("hold")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1269 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1270 | logOutgoing("hold %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1271 | mServiceInterface.hold(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1272 | } catch (RemoteException e) { |
| 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1277 | /** @see IConnectionService#unhold(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1278 | void unhold(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1279 | final String callId = mCallIdMapper.getCallId(call); |
| 1280 | if (callId != null && isServiceValid("unhold")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1281 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1282 | logOutgoing("unhold %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1283 | mServiceInterface.unhold(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1284 | } catch (RemoteException e) { |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1289 | /** @see IConnectionService#onCallAudioStateChanged(String, CallAudioState, Session.Info) */ |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 1290 | @VisibleForTesting |
| 1291 | public void onCallAudioStateChanged(Call activeCall, CallAudioState audioState) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1292 | final String callId = mCallIdMapper.getCallId(activeCall); |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1293 | if (callId != null && isServiceValid("onCallAudioStateChanged")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1294 | try { |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1295 | logOutgoing("onCallAudioStateChanged %s %s", callId, audioState); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1296 | mServiceInterface.onCallAudioStateChanged(callId, audioState, |
| 1297 | Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1298 | } catch (RemoteException e) { |
| 1299 | } |
| 1300 | } |
| 1301 | } |
| 1302 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1303 | /** @see IConnectionService#disconnect(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1304 | void disconnect(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1305 | final String callId = mCallIdMapper.getCallId(call); |
| 1306 | if (callId != null && isServiceValid("disconnect")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1307 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1308 | logOutgoing("disconnect %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1309 | mServiceInterface.disconnect(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1310 | } catch (RemoteException e) { |
| 1311 | } |
| 1312 | } |
| 1313 | } |
| 1314 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1315 | /** @see IConnectionService#answer(String, Session.Info) */ |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 1316 | void answer(Call call, int videoState) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1317 | final String callId = mCallIdMapper.getCallId(call); |
| 1318 | if (callId != null && isServiceValid("answer")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1319 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1320 | logOutgoing("answer %s %d", callId, videoState); |
Tyler Gunn | 467b64f | 2015-06-09 13:48:47 -0700 | [diff] [blame] | 1321 | if (VideoProfile.isAudioOnly(videoState)) { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1322 | mServiceInterface.answer(callId, Log.getExternalSession()); |
Tyler Gunn | 041eff6 | 2014-08-25 13:52:52 -0700 | [diff] [blame] | 1323 | } else { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1324 | mServiceInterface.answerVideo(callId, videoState, Log.getExternalSession()); |
Tyler Gunn | 041eff6 | 2014-08-25 13:52:52 -0700 | [diff] [blame] | 1325 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1326 | } catch (RemoteException e) { |
| 1327 | } |
| 1328 | } |
| 1329 | } |
| 1330 | |
Pooja Jain | ad4ebc0 | 2017-12-28 14:23:13 +0530 | [diff] [blame] | 1331 | /** @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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1343 | /** @see IConnectionService#reject(String, Session.Info) */ |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1344 | void reject(Call call, boolean rejectWithMessage, String message) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1345 | final String callId = mCallIdMapper.getCallId(call); |
| 1346 | if (callId != null && isServiceValid("reject")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1347 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1348 | logOutgoing("reject %s", callId); |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1349 | |
| 1350 | if (rejectWithMessage && call.can( |
Hall Liu | 4b1617a | 2016-03-14 16:36:08 -0700 | [diff] [blame] | 1351 | Connection.CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1352 | mServiceInterface.rejectWithMessage(callId, message, Log.getExternalSession()); |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1353 | } else { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1354 | mServiceInterface.reject(callId, Log.getExternalSession()); |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1355 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1356 | } catch (RemoteException e) { |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1361 | /** @see IConnectionService#playDtmfTone(String, char, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1362 | void playDtmfTone(Call call, char digit) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1363 | final String callId = mCallIdMapper.getCallId(call); |
| 1364 | if (callId != null && isServiceValid("playDtmfTone")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1365 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1366 | logOutgoing("playDtmfTone %s %c", callId, digit); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1367 | mServiceInterface.playDtmfTone(callId, digit, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1368 | } catch (RemoteException e) { |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1373 | /** @see IConnectionService#stopDtmfTone(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1374 | void stopDtmfTone(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1375 | final String callId = mCallIdMapper.getCallId(call); |
| 1376 | if (callId != null && isServiceValid("stopDtmfTone")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1377 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1378 | logOutgoing("stopDtmfTone %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1379 | mServiceInterface.stopDtmfTone(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1380 | } 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 Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1400 | removeCall(call, new DisconnectCause(DisconnectCause.ERROR)); |
Santos Cordon | fd6ca44 | 2014-07-24 15:34:01 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1403 | void removeCall(String callId, DisconnectCause disconnectCause) { |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1404 | CreateConnectionResponse response = mPendingResponses.remove(callId); |
| 1405 | if (response != null) { |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1406 | response.handleCreateConnectionFailure(disconnectCause); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | mCallIdMapper.removeCall(callId); |
| 1410 | } |
| 1411 | |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1412 | void removeCall(Call call, DisconnectCause disconnectCause) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1413 | CreateConnectionResponse response = mPendingResponses.remove(mCallIdMapper.getCallId(call)); |
| 1414 | if (response != null) { |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1415 | response.handleCreateConnectionFailure(disconnectCause); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | mCallIdMapper.removeCall(call); |
| 1419 | } |
| 1420 | |
| 1421 | void onPostDialContinue(Call call, boolean proceed) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1422 | final String callId = mCallIdMapper.getCallId(call); |
| 1423 | if (callId != null && isServiceValid("onPostDialContinue")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1424 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1425 | logOutgoing("onPostDialContinue %s %b", callId, proceed); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1426 | mServiceInterface.onPostDialContinue(callId, proceed, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1427 | } catch (RemoteException ignored) { |
| 1428 | } |
| 1429 | } |
| 1430 | } |
| 1431 | |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1432 | void conference(final Call call, Call otherCall) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1433 | final String callId = mCallIdMapper.getCallId(call); |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1434 | final String otherCallId = mCallIdMapper.getCallId(otherCall); |
| 1435 | if (callId != null && otherCallId != null && isServiceValid("conference")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1436 | try { |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1437 | logOutgoing("conference %s %s", callId, otherCallId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1438 | mServiceInterface.conference(callId, otherCallId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1439 | } catch (RemoteException ignored) { |
| 1440 | } |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | void splitFromConference(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1445 | final String callId = mCallIdMapper.getCallId(call); |
| 1446 | if (callId != null && isServiceValid("splitFromConference")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1447 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1448 | logOutgoing("splitFromConference %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1449 | mServiceInterface.splitFromConference(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1450 | } catch (RemoteException ignored) { |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | |
Santos Cordon | 6805923 | 2014-09-04 20:09:42 -0700 | [diff] [blame] | 1455 | 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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1460 | mServiceInterface.mergeConference(callId, Log.getExternalSession()); |
Santos Cordon | 6805923 | 2014-09-04 20:09:42 -0700 | [diff] [blame] | 1461 | } 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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1471 | mServiceInterface.swapConference(callId, Log.getExternalSession()); |
Santos Cordon | 6805923 | 2014-09-04 20:09:42 -0700 | [diff] [blame] | 1472 | } catch (RemoteException ignored) { |
| 1473 | } |
| 1474 | } |
| 1475 | } |
| 1476 | |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 1477 | 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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1482 | mServiceInterface.pullExternalCall(callId, Log.getExternalSession()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 1483 | } 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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1493 | mServiceInterface.sendCallEvent(callId, event, extras, Log.getExternalSession()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 1494 | } catch (RemoteException ignored) { |
| 1495 | } |
| 1496 | } |
| 1497 | } |
| 1498 | |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 1499 | 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 Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1504 | mServiceInterface.onExtrasChanged(callId, extras, Log.getExternalSession()); |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 1505 | } catch (RemoteException ignored) { |
| 1506 | } |
| 1507 | } |
| 1508 | } |
| 1509 | |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 1510 | 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 Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1545 | /** {@inheritDoc} */ |
| 1546 | @Override |
| 1547 | protected void setServiceInterface(IBinder binder) { |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 1548 | 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 Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1567 | @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 Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 1572 | mConnSvrFocusListener.onConnectionServiceReleased(ConnectionServiceWrapper.this); |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1573 | } |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 1574 | 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 Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | @Override |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 1591 | 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 Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1607 | |
| 1608 | @Override |
| 1609 | public void setConnectionServiceFocusListener( |
| 1610 | ConnectionServiceFocusManager.ConnectionServiceFocusListener listener) { |
| 1611 | mConnSvrFocusListener = listener; |
| 1612 | } |
| 1613 | |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1614 | 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 Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1624 | removeCall(callId, connection.getDisconnectCause()); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1625 | } else { |
| 1626 | // Successful connection |
| 1627 | if (mPendingResponses.containsKey(callId)) { |
Ihab Awad | 8000845 | 2014-08-23 20:35:44 -0700 | [diff] [blame] | 1628 | mPendingResponses.remove(callId) |
| 1629 | .handleCreateConnectionSuccess(mCallIdMapper, connection); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1630 | } |
| 1631 | } |
| 1632 | } |
| 1633 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1634 | /** |
| 1635 | * Called when the associated connection service dies. |
| 1636 | */ |
| 1637 | private void handleConnectionServiceDeath() { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1638 | 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 Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1643 | responses[i].handleCreateConnectionFailure( |
Tyler Gunn | 1a97fb2 | 2017-06-21 19:55:54 -0700 | [diff] [blame] | 1644 | new DisconnectCause(DisconnectCause.ERROR, "CS_DEATH")); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1645 | } |
| 1646 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1647 | mCallIdMapper.clear(); |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1648 | |
| 1649 | if (mConnSvrFocusListener != null) { |
| 1650 | mConnSvrFocusListener.onConnectionServiceDeath(this); |
| 1651 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | private void logIncoming(String msg, Object... params) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 1655 | Log.d(this, "ConnectionService -> Telecom[" + mComponentName.flattenToShortString() + "]: " |
Tyler Gunn | 46bc3fd | 2017-04-03 18:53:38 +0000 | [diff] [blame] | 1656 | + msg, params); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | private void logOutgoing(String msg, Object... params) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 1660 | Log.d(this, "Telecom -> ConnectionService[" + mComponentName.flattenToShortString() + "]: " |
Tyler Gunn | 46bc3fd | 2017-04-03 18:53:38 +0000 | [diff] [blame] | 1661 | + msg, params); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1664 | private void queryRemoteConnectionServices(final UserHandle userHandle, |
| 1665 | final RemoteServiceCallback callback) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1666 | // Only give remote connection services to this connection service if it is listed as |
| 1667 | // the connection manager. |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1668 | PhoneAccountHandle simCallManager = mPhoneAccountRegistrar.getSimCallManager(userHandle); |
Ihab Awad | c17294c | 2014-08-04 19:23:37 -0700 | [diff] [blame] | 1669 | Log.d(this, "queryRemoteConnectionServices finds simCallManager = %s", simCallManager); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1670 | if (simCallManager == null || |
| 1671 | !simCallManager.getComponentName().equals(getComponentName())) { |
| 1672 | noRemoteServices(callback); |
| 1673 | return; |
| 1674 | } |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1675 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1676 | // Make a list of ConnectionServices that are listed as being associated with SIM accounts |
Jay Shrauner | a82c8f7 | 2014-08-14 15:49:16 -0700 | [diff] [blame] | 1677 | final Set<ConnectionServiceWrapper> simServices = Collections.newSetFromMap( |
| 1678 | new ConcurrentHashMap<ConnectionServiceWrapper, Boolean>(8, 0.9f, 1)); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1679 | for (PhoneAccountHandle handle : mPhoneAccountRegistrar.getSimPhoneAccounts(userHandle)) { |
Santos Cordon | 6a21264 | 2015-05-08 16:35:23 -0700 | [diff] [blame] | 1680 | ConnectionServiceWrapper service = mConnectionServiceRepository.getService( |
| 1681 | handle.getComponentName(), handle.getUserHandle()); |
| 1682 | if (service != null) { |
| 1683 | simServices.add(service); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1684 | } |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 1685 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1686 | |
| 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 Gunn | 5983dc1 | 2018-03-08 23:22:31 +0000 | [diff] [blame] | 1704 | 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 Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1714 | 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 Cordon | 165c1ce | 2015-07-10 16:07:59 -0700 | [diff] [blame] | 1730 | }, null); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1731 | } |
| 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 Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1747 | setRemoteServices(callback, Collections.EMPTY_LIST, Collections.EMPTY_LIST); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1748 | } |
| 1749 | } |