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 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 92 | } finally { |
| 93 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 94 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 95 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 98 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 99 | public void setActive(String callId, Session.Info sessionInfo) { |
| 100 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ACTIVE); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 101 | long token = Binder.clearCallingIdentity(); |
| 102 | try { |
| 103 | synchronized (mLock) { |
| 104 | logIncoming("setActive %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 105 | Call call = mCallIdMapper.getCall(callId); |
| 106 | if (call != null) { |
| 107 | mCallsManager.markCallAsActive(call); |
| 108 | } else { |
| 109 | // Log.w(this, "setActive, unknown call id: %s", msg.obj); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 110 | } |
| 111 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 112 | } finally { |
| 113 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 114 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 115 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 118 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 119 | public void setRinging(String callId, Session.Info sessionInfo) { |
| 120 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_RINGING); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 121 | long token = Binder.clearCallingIdentity(); |
| 122 | try { |
| 123 | synchronized (mLock) { |
| 124 | logIncoming("setRinging %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 125 | Call call = mCallIdMapper.getCall(callId); |
| 126 | if (call != null) { |
| 127 | mCallsManager.markCallAsRinging(call); |
| 128 | } else { |
| 129 | // Log.w(this, "setRinging, unknown call id: %s", msg.obj); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 130 | } |
| 131 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 132 | } finally { |
| 133 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 134 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 135 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 138 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 139 | public void setVideoProvider(String callId, IVideoProvider videoProvider, |
| 140 | Session.Info sessionInfo) { |
| 141 | Log.startSession(sessionInfo, "CSW.sVP"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 142 | long token = Binder.clearCallingIdentity(); |
| 143 | try { |
| 144 | synchronized (mLock) { |
| 145 | logIncoming("setVideoProvider %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 146 | Call call = mCallIdMapper.getCall(callId); |
| 147 | if (call != null) { |
| 148 | call.setVideoProvider(videoProvider); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 149 | } |
| 150 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 151 | } finally { |
| 152 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 153 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 154 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 157 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 158 | public void setDialing(String callId, Session.Info sessionInfo) { |
| 159 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DIALING); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 160 | long token = Binder.clearCallingIdentity(); |
| 161 | try { |
| 162 | synchronized (mLock) { |
| 163 | logIncoming("setDialing %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 164 | Call call = mCallIdMapper.getCall(callId); |
| 165 | if (call != null) { |
| 166 | mCallsManager.markCallAsDialing(call); |
| 167 | } else { |
| 168 | // Log.w(this, "setDialing, unknown call id: %s", msg.obj); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 169 | } |
| 170 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 171 | } finally { |
| 172 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 173 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 174 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 177 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 178 | public void setPulling(String callId, Session.Info sessionInfo) { |
| 179 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_PULLING); |
Tyler Gunn | 1e37be5 | 2016-07-11 08:54:23 -0700 | [diff] [blame] | 180 | long token = Binder.clearCallingIdentity(); |
| 181 | try { |
| 182 | synchronized (mLock) { |
| 183 | logIncoming("setPulling %s", callId); |
| 184 | Call call = mCallIdMapper.getCall(callId); |
| 185 | if (call != null) { |
| 186 | mCallsManager.markCallAsPulling(call); |
| 187 | } |
| 188 | } |
| 189 | } finally { |
| 190 | Binder.restoreCallingIdentity(token); |
| 191 | Log.endSession(); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 196 | public void setDisconnected(String callId, DisconnectCause disconnectCause, |
| 197 | Session.Info sessionInfo) { |
| 198 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_DISCONNECTED); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 199 | long token = Binder.clearCallingIdentity(); |
| 200 | try { |
| 201 | synchronized (mLock) { |
| 202 | logIncoming("setDisconnected %s %s", callId, disconnectCause); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 203 | Call call = mCallIdMapper.getCall(callId); |
| 204 | Log.d(this, "disconnect call %s %s", disconnectCause, call); |
| 205 | if (call != null) { |
| 206 | mCallsManager.markCallAsDisconnected(call, disconnectCause); |
| 207 | } else { |
| 208 | // Log.w(this, "setDisconnected, unknown call id: %s", args.arg1); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 211 | } finally { |
| 212 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 213 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 214 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 217 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 218 | public void setOnHold(String callId, Session.Info sessionInfo) { |
| 219 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_ON_HOLD); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 220 | long token = Binder.clearCallingIdentity(); |
| 221 | try { |
| 222 | synchronized (mLock) { |
| 223 | logIncoming("setOnHold %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 224 | Call call = mCallIdMapper.getCall(callId); |
| 225 | if (call != null) { |
| 226 | mCallsManager.markCallAsOnHold(call); |
| 227 | } else { |
| 228 | // Log.w(this, "setOnHold, unknown call id: %s", msg.obj); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 229 | } |
| 230 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 231 | } finally { |
| 232 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 233 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 234 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 237 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 238 | public void setRingbackRequested(String callId, boolean ringback, |
| 239 | Session.Info sessionInfo) { |
| 240 | Log.startSession(sessionInfo, "CSW.SRR"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 241 | long token = Binder.clearCallingIdentity(); |
| 242 | try { |
| 243 | synchronized (mLock) { |
| 244 | logIncoming("setRingbackRequested %s %b", callId, ringback); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 245 | Call call = mCallIdMapper.getCall(callId); |
| 246 | if (call != null) { |
| 247 | call.setRingbackRequested(ringback); |
| 248 | } else { |
| 249 | // Log.w(this, "setRingback, unknown call id: %s", args.arg1); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 250 | } |
| 251 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 252 | } finally { |
| 253 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 254 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 255 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 258 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 259 | public void removeCall(String callId, Session.Info sessionInfo) { |
| 260 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_REMOVE_CALL); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 261 | long token = Binder.clearCallingIdentity(); |
| 262 | try { |
| 263 | synchronized (mLock) { |
| 264 | logIncoming("removeCall %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 265 | Call call = mCallIdMapper.getCall(callId); |
| 266 | if (call != null) { |
| 267 | if (call.isAlive()) { |
| 268 | mCallsManager.markCallAsDisconnected( |
| 269 | call, new DisconnectCause(DisconnectCause.REMOTE)); |
| 270 | } else { |
| 271 | mCallsManager.markCallAsRemoved(call); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 275 | } finally { |
| 276 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 277 | Log.endSession(); |
Ihab Awad | a02bef5 | 2014-08-13 18:18:42 -0700 | [diff] [blame] | 278 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 281 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 282 | public void setConnectionCapabilities(String callId, int connectionCapabilities, |
| 283 | Session.Info sessionInfo) { |
| 284 | Log.startSession(sessionInfo, "CSW.sCC"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 285 | long token = Binder.clearCallingIdentity(); |
| 286 | try { |
| 287 | synchronized (mLock) { |
| 288 | logIncoming("setConnectionCapabilities %s %d", callId, connectionCapabilities); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 289 | Call call = mCallIdMapper.getCall(callId); |
| 290 | if (call != null) { |
| 291 | call.setConnectionCapabilities(connectionCapabilities); |
| 292 | } else { |
| 293 | // Log.w(ConnectionServiceWrapper.this, |
| 294 | // "setConnectionCapabilities, unknown call id: %s", msg.obj); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 295 | } |
| 296 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 297 | } finally { |
| 298 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 299 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 300 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 303 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 304 | public void setConnectionProperties(String callId, int connectionProperties, |
| 305 | Session.Info sessionInfo) { |
Tyler Gunn | 571d5e6 | 2016-03-15 15:55:18 -0700 | [diff] [blame] | 306 | Log.startSession("CSW.sCP"); |
| 307 | long token = Binder.clearCallingIdentity(); |
| 308 | try { |
| 309 | synchronized (mLock) { |
| 310 | logIncoming("setConnectionProperties %s %d", callId, connectionProperties); |
| 311 | Call call = mCallIdMapper.getCall(callId); |
| 312 | if (call != null) { |
| 313 | call.setConnectionProperties(connectionProperties); |
| 314 | } |
| 315 | } |
| 316 | } finally { |
| 317 | Binder.restoreCallingIdentity(token); |
| 318 | Log.endSession(); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 323 | public void setIsConferenced(String callId, String conferenceCallId, |
| 324 | Session.Info sessionInfo) { |
| 325 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_SET_IS_CONFERENCED); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 326 | long token = Binder.clearCallingIdentity(); |
| 327 | try { |
| 328 | synchronized (mLock) { |
| 329 | logIncoming("setIsConferenced %s %s", callId, conferenceCallId); |
| 330 | Call childCall = mCallIdMapper.getCall(callId); |
| 331 | if (childCall != null) { |
| 332 | if (conferenceCallId == null) { |
| 333 | Log.d(this, "unsetting parent: %s", conferenceCallId); |
Tyler Gunn | 7658171 | 2017-05-09 14:39:42 -0700 | [diff] [blame] | 334 | childCall.setParentAndChildCall(null); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 335 | } else { |
| 336 | Call conferenceCall = mCallIdMapper.getCall(conferenceCallId); |
Tyler Gunn | 7658171 | 2017-05-09 14:39:42 -0700 | [diff] [blame] | 337 | childCall.setParentAndChildCall(conferenceCall); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 338 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 339 | } else { |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 340 | // Log.w(this, "setIsConferenced, unknown call id: %s", args.arg1); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 341 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 342 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 343 | } finally { |
| 344 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 345 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 346 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 349 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 350 | public void setConferenceMergeFailed(String callId, Session.Info sessionInfo) { |
| 351 | Log.startSession(sessionInfo, "CSW.sCMF"); |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 352 | long token = Binder.clearCallingIdentity(); |
| 353 | try { |
| 354 | synchronized (mLock) { |
| 355 | logIncoming("setConferenceMergeFailed %s", callId); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 356 | // TODO: we should move the UI for indication a merge failure here |
| 357 | // from CallNotifier.onSuppServiceFailed(). This way the InCallUI can |
| 358 | // deliver the message anyway that they want. b/20530631. |
| 359 | Call call = mCallIdMapper.getCall(callId); |
| 360 | if (call != null) { |
Brad Ebinger | 0d40255 | 2016-05-27 16:02:53 -0700 | [diff] [blame] | 361 | call.onConnectionEvent(Connection.EVENT_CALL_MERGE_FAILED, null); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 362 | } else { |
| 363 | Log.w(this, "setConferenceMergeFailed, unknown call id: %s", callId); |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 364 | } |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 365 | } |
| 366 | } finally { |
| 367 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 368 | Log.endSession(); |
Anthony Lee | ce75aa1 | 2015-04-24 15:36:26 -0700 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | |
| 372 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 373 | public void addConferenceCall(String callId, ParcelableConference parcelableConference, |
| 374 | Session.Info sessionInfo) { |
| 375 | Log.startSession(sessionInfo, LogUtils.Sessions.CSW_ADD_CONFERENCE_CALL); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 376 | long token = Binder.clearCallingIdentity(); |
| 377 | try { |
| 378 | synchronized (mLock) { |
| 379 | if (mCallIdMapper.getCall(callId) != null) { |
| 380 | Log.w(this, "Attempting to add a conference call using an existing " + |
| 381 | "call id %s", callId); |
| 382 | return; |
| 383 | } |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 384 | logIncoming("addConferenceCall %s %s [%s]", callId, parcelableConference, |
| 385 | parcelableConference.getConnectionIds()); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 386 | |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 387 | // Make sure that there's at least one valid call. For remote connections |
| 388 | // we'll get a add conference msg from both the remote connection service |
| 389 | // and from the real connection service. |
| 390 | boolean hasValidCalls = false; |
| 391 | for (String connId : parcelableConference.getConnectionIds()) { |
| 392 | if (mCallIdMapper.getCall(connId) != null) { |
| 393 | hasValidCalls = true; |
| 394 | } |
| 395 | } |
| 396 | // But don't bail out if the connection count is 0, because that is a valid |
| 397 | // IMS conference state. |
| 398 | if (!hasValidCalls && parcelableConference.getConnectionIds().size() > 0) { |
| 399 | Log.d(this, "Attempting to add a conference with no valid calls"); |
| 400 | return; |
| 401 | } |
| 402 | |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 403 | PhoneAccountHandle phAcc = null; |
| 404 | if (parcelableConference != null && |
| 405 | parcelableConference.getPhoneAccount() != null) { |
| 406 | phAcc = parcelableConference.getPhoneAccount(); |
| 407 | } |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 408 | |
| 409 | Bundle connectionExtras = parcelableConference.getExtras(); |
| 410 | |
| 411 | String connectIdToCheck = null; |
| 412 | if (connectionExtras != null && connectionExtras |
| 413 | .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) { |
| 414 | // Conference was added via a connection manager, see if its original id is |
| 415 | // known. |
| 416 | connectIdToCheck = connectionExtras |
| 417 | .getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID); |
| 418 | } else { |
| 419 | connectIdToCheck = callId; |
| 420 | } |
| 421 | |
| 422 | Call conferenceCall; |
| 423 | // Check to see if this conference has already been added. |
| 424 | Call alreadyAddedConnection = mCallsManager |
| 425 | .getAlreadyAddedConnection(connectIdToCheck); |
| 426 | if (alreadyAddedConnection != null && mCallIdMapper.getCall(callId) == null) { |
| 427 | // We are currently attempting to add the conference via a connection mgr, |
| 428 | // and the originating ConnectionService has already added it. Instead of |
| 429 | // making a new Telecom call, we will simply add it to the ID mapper here, |
| 430 | // and replace the ConnectionService on the call. |
| 431 | mCallIdMapper.addCall(alreadyAddedConnection, callId); |
| 432 | alreadyAddedConnection.replaceConnectionService( |
| 433 | ConnectionServiceWrapper.this); |
| 434 | conferenceCall = alreadyAddedConnection; |
| 435 | } else { |
| 436 | // need to create a new Call |
| 437 | Call newConferenceCall = mCallsManager.createConferenceCall(callId, |
| 438 | phAcc, parcelableConference); |
| 439 | mCallIdMapper.addCall(newConferenceCall, callId); |
| 440 | newConferenceCall.setConnectionService(ConnectionServiceWrapper.this); |
| 441 | conferenceCall = newConferenceCall; |
| 442 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 443 | |
| 444 | Log.d(this, "adding children to conference %s phAcc %s", |
| 445 | parcelableConference.getConnectionIds(), phAcc); |
| 446 | for (String connId : parcelableConference.getConnectionIds()) { |
| 447 | Call childCall = mCallIdMapper.getCall(connId); |
| 448 | Log.d(this, "found child: %s", connId); |
| 449 | if (childCall != null) { |
Tyler Gunn | 7658171 | 2017-05-09 14:39:42 -0700 | [diff] [blame] | 450 | childCall.setParentAndChildCall(conferenceCall); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 451 | } |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 452 | } |
| 453 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 454 | } finally { |
| 455 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 456 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 457 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 461 | public void onPostDialWait(String callId, String remaining, |
| 462 | Session.Info sessionInfo) throws RemoteException { |
| 463 | Log.startSession(sessionInfo, "CSW.oPDW"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 464 | long token = Binder.clearCallingIdentity(); |
| 465 | try { |
| 466 | synchronized (mLock) { |
| 467 | logIncoming("onPostDialWait %s %s", callId, remaining); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 468 | Call call = mCallIdMapper.getCall(callId); |
| 469 | if (call != null) { |
| 470 | call.onPostDialWait(remaining); |
| 471 | } else { |
| 472 | // Log.w(this, "onPostDialWait, unknown call id: %s", args.arg1); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 473 | } |
| 474 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 475 | } finally { |
| 476 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 477 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 478 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 481 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 482 | public void onPostDialChar(String callId, char nextChar, |
| 483 | Session.Info sessionInfo) throws RemoteException { |
| 484 | Log.startSession(sessionInfo, "CSW.oPDC"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 485 | long token = Binder.clearCallingIdentity(); |
| 486 | try { |
| 487 | synchronized (mLock) { |
| 488 | logIncoming("onPostDialChar %s %s", callId, nextChar); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 489 | Call call = mCallIdMapper.getCall(callId); |
| 490 | if (call != null) { |
| 491 | call.onPostDialChar(nextChar); |
| 492 | } else { |
| 493 | // Log.w(this, "onPostDialChar, unknown call id: %s", args.arg1); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 494 | } |
| 495 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 496 | } finally { |
| 497 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 498 | Log.endSession(); |
Nancy Chen | a469f76 | 2014-12-09 18:29:20 -0800 | [diff] [blame] | 499 | } |
| 500 | } |
| 501 | |
| 502 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 503 | public void queryRemoteConnectionServices(RemoteServiceCallback callback, |
| 504 | Session.Info sessionInfo) { |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 505 | final UserHandle callingUserHandle = Binder.getCallingUserHandle(); |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 506 | Log.startSession(sessionInfo, "CSW.qRCS"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 507 | long token = Binder.clearCallingIdentity(); |
| 508 | try { |
| 509 | synchronized (mLock) { |
| 510 | logIncoming("queryRemoteConnectionServices %s", callback); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 511 | ConnectionServiceWrapper.this |
| 512 | .queryRemoteConnectionServices(callingUserHandle, callback); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 513 | } |
| 514 | } finally { |
| 515 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 516 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 517 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 521 | public void setVideoState(String callId, int videoState, Session.Info sessionInfo) { |
| 522 | Log.startSession(sessionInfo, "CSW.sVS"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 523 | long token = Binder.clearCallingIdentity(); |
| 524 | try { |
| 525 | synchronized (mLock) { |
| 526 | logIncoming("setVideoState %s %d", callId, videoState); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 527 | Call call = mCallIdMapper.getCall(callId); |
| 528 | if (call != null) { |
| 529 | call.setVideoState(videoState); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 532 | } finally { |
| 533 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 534 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 535 | } |
Tyler Gunn | 0a388fc | 2014-07-17 12:21:17 -0700 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 539 | public void setIsVoipAudioMode(String callId, boolean isVoip, Session.Info sessionInfo) { |
| 540 | Log.startSession(sessionInfo, "CSW.sIVAM"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 541 | long token = Binder.clearCallingIdentity(); |
| 542 | try { |
| 543 | synchronized (mLock) { |
| 544 | logIncoming("setIsVoipAudioMode %s %b", callId, isVoip); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 545 | Call call = mCallIdMapper.getCall(callId); |
| 546 | if (call != null) { |
| 547 | call.setIsVoipAudioMode(isVoip); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 548 | } |
| 549 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 550 | } finally { |
| 551 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 552 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 553 | } |
Sailesh Nepal | 7e66957 | 2014-07-08 21:29:12 -0700 | [diff] [blame] | 554 | } |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 555 | |
| 556 | @Override |
Hall Liu | 9086fb1 | 2017-11-07 18:01:53 -0800 | [diff] [blame] | 557 | public void setAudioRoute(String callId, int audioRoute, |
| 558 | String bluetoothAddress, Session.Info sessionInfo) { |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 559 | Log.startSession(sessionInfo, "CSW.sAR"); |
| 560 | long token = Binder.clearCallingIdentity(); |
| 561 | try { |
| 562 | synchronized (mLock) { |
| 563 | logIncoming("setAudioRoute %s %s", callId, |
| 564 | CallAudioState.audioRouteToString(audioRoute)); |
Hall Liu | 9086fb1 | 2017-11-07 18:01:53 -0800 | [diff] [blame] | 565 | mCallsManager.setAudioRoute(audioRoute, bluetoothAddress); |
Tyler Gunn | acb3bc8 | 2017-01-09 09:43:56 -0800 | [diff] [blame] | 566 | } |
| 567 | } finally { |
| 568 | Binder.restoreCallingIdentity(token); |
| 569 | Log.endSession(); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 574 | public void setStatusHints(String callId, StatusHints statusHints, |
| 575 | Session.Info sessionInfo) { |
| 576 | Log.startSession(sessionInfo, "CSW.sSH"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 577 | long token = Binder.clearCallingIdentity(); |
| 578 | try { |
| 579 | synchronized (mLock) { |
| 580 | logIncoming("setStatusHints %s %s", callId, statusHints); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 581 | Call call = mCallIdMapper.getCall(callId); |
| 582 | if (call != null) { |
| 583 | call.setStatusHints(statusHints); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 586 | } finally { |
| 587 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 588 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 589 | } |
Sailesh Nepal | 35faf8c | 2014-07-08 22:02:34 -0700 | [diff] [blame] | 590 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 591 | |
| 592 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 593 | public void putExtras(String callId, Bundle extras, Session.Info sessionInfo) { |
| 594 | Log.startSession(sessionInfo, "CSW.pE"); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 595 | long token = Binder.clearCallingIdentity(); |
| 596 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 597 | synchronized (mLock) { |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 598 | Bundle.setDefusable(extras, true); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 599 | Call call = mCallIdMapper.getCall(callId); |
| 600 | if (call != null) { |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 601 | call.putExtras(Call.SOURCE_CONNECTION_SERVICE, extras); |
| 602 | } |
| 603 | } |
| 604 | } finally { |
| 605 | Binder.restoreCallingIdentity(token); |
| 606 | Log.endSession(); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 611 | public void removeExtras(String callId, List<String> keys, Session.Info sessionInfo) { |
| 612 | Log.startSession(sessionInfo, "CSW.rE"); |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 613 | long token = Binder.clearCallingIdentity(); |
| 614 | try { |
| 615 | synchronized (mLock) { |
| 616 | logIncoming("removeExtra %s %s", callId, keys); |
| 617 | Call call = mCallIdMapper.getCall(callId); |
| 618 | if (call != null) { |
| 619 | call.removeExtras(Call.SOURCE_CONNECTION_SERVICE, keys); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | } finally { |
| 623 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 624 | Log.endSession(); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 629 | public void setAddress(String callId, Uri address, int presentation, |
| 630 | Session.Info sessionInfo) { |
| 631 | Log.startSession(sessionInfo, "CSW.sA"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 632 | long token = Binder.clearCallingIdentity(); |
| 633 | try { |
| 634 | synchronized (mLock) { |
| 635 | logIncoming("setAddress %s %s %d", callId, address, presentation); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 636 | Call call = mCallIdMapper.getCall(callId); |
| 637 | if (call != null) { |
| 638 | call.setHandle(address, presentation); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 639 | } |
| 640 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 641 | } finally { |
| 642 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 643 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 644 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 648 | public void setCallerDisplayName(String callId, String callerDisplayName, int presentation, |
| 649 | Session.Info sessionInfo) { |
| 650 | Log.startSession(sessionInfo, "CSW.sCDN"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 651 | long token = Binder.clearCallingIdentity(); |
| 652 | try { |
| 653 | synchronized (mLock) { |
| 654 | logIncoming("setCallerDisplayName %s %s %d", callId, callerDisplayName, |
| 655 | presentation); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 656 | Call call = mCallIdMapper.getCall(callId); |
| 657 | if (call != null) { |
| 658 | call.setCallerDisplayName(callerDisplayName, presentation); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 659 | } |
| 660 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 661 | } finally { |
| 662 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 663 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 664 | } |
Sailesh Nepal | e8ecb98 | 2014-07-11 17:19:42 -0700 | [diff] [blame] | 665 | } |
Sailesh Nepal | 9d58de5 | 2014-07-18 14:53:19 -0700 | [diff] [blame] | 666 | |
| 667 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 668 | public void setConferenceableConnections(String callId, List<String> conferenceableCallIds, |
| 669 | Session.Info sessionInfo) { |
| 670 | Log.startSession(sessionInfo, "CSW.sCC"); |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 671 | long token = Binder.clearCallingIdentity(); |
| 672 | try { |
| 673 | synchronized (mLock) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 674 | |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 675 | Call call = mCallIdMapper.getCall(callId); |
| 676 | if (call != null) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 677 | logIncoming("setConferenceableConnections %s %s", callId, |
| 678 | conferenceableCallIds); |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 679 | List<Call> conferenceableCalls = |
| 680 | new ArrayList<>(conferenceableCallIds.size()); |
| 681 | for (String otherId : conferenceableCallIds) { |
| 682 | Call otherCall = mCallIdMapper.getCall(otherId); |
| 683 | if (otherCall != null && otherCall != call) { |
| 684 | conferenceableCalls.add(otherCall); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 685 | } |
| 686 | } |
Tyler Gunn | 8452be0 | 2015-09-17 09:57:02 -0700 | [diff] [blame] | 687 | call.setConferenceableCalls(conferenceableCalls); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 688 | } |
| 689 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 690 | } finally { |
| 691 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 692 | Log.endSession(); |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 693 | } |
Santos Cordon | 12d6182 | 2014-07-29 16:02:20 -0700 | [diff] [blame] | 694 | } |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 695 | |
| 696 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 697 | public void addExistingConnection(String callId, ParcelableConnection connection, |
| 698 | Session.Info sessionInfo) { |
| 699 | Log.startSession(sessionInfo, "CSW.aEC"); |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 700 | UserHandle userHandle = Binder.getCallingUserHandle(); |
| 701 | // Check that the Calling Package matches PhoneAccountHandle's Component Package |
| 702 | PhoneAccountHandle callingPhoneAccountHandle = connection.getPhoneAccount(); |
| 703 | if (callingPhoneAccountHandle != null) { |
| 704 | mAppOpsManager.checkPackage(Binder.getCallingUid(), |
| 705 | callingPhoneAccountHandle.getComponentName().getPackageName()); |
| 706 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 707 | long token = Binder.clearCallingIdentity(); |
| 708 | try { |
| 709 | synchronized (mLock) { |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 710 | // Make sure that the PhoneAccount associated with the incoming |
| 711 | // ParcelableConnection is in fact registered to Telecom and is being called |
| 712 | // from the correct user. |
| 713 | List<PhoneAccountHandle> accountHandles = |
| 714 | mPhoneAccountRegistrar.getCallCapablePhoneAccounts(null /*uriScheme*/, |
| 715 | false /*includeDisabledAccounts*/, userHandle); |
| 716 | PhoneAccountHandle phoneAccountHandle = null; |
| 717 | for (PhoneAccountHandle accountHandle : accountHandles) { |
| 718 | if(accountHandle.equals(callingPhoneAccountHandle)) { |
| 719 | phoneAccountHandle = accountHandle; |
| 720 | } |
| 721 | } |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 722 | // Allow the Sim call manager account as well, even if its disabled. |
| 723 | if (phoneAccountHandle == null && callingPhoneAccountHandle != null) { |
| 724 | if (callingPhoneAccountHandle.equals( |
| 725 | mPhoneAccountRegistrar.getSimCallManager(userHandle))) { |
| 726 | phoneAccountHandle = callingPhoneAccountHandle; |
| 727 | } |
| 728 | } |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 729 | if (phoneAccountHandle != null) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 730 | logIncoming("addExistingConnection %s %s", callId, connection); |
| 731 | |
| 732 | Bundle connectionExtras = connection.getExtras(); |
| 733 | String connectIdToCheck = null; |
| 734 | if (connectionExtras != null && connectionExtras |
| 735 | .containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) { |
| 736 | connectIdToCheck = connectionExtras |
| 737 | .getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID); |
| 738 | } else { |
| 739 | connectIdToCheck = callId; |
| 740 | } |
| 741 | // Check to see if this Connection has already been added. |
| 742 | Call alreadyAddedConnection = mCallsManager |
| 743 | .getAlreadyAddedConnection(connectIdToCheck); |
| 744 | |
| 745 | if (alreadyAddedConnection != null |
| 746 | && mCallIdMapper.getCall(callId) == null) { |
| 747 | mCallIdMapper.addCall(alreadyAddedConnection, callId); |
| 748 | alreadyAddedConnection |
| 749 | .replaceConnectionService(ConnectionServiceWrapper.this); |
| 750 | return; |
| 751 | } |
| 752 | |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 753 | Call existingCall = mCallsManager |
| 754 | .createCallForExistingConnection(callId, connection); |
| 755 | mCallIdMapper.addCall(existingCall, callId); |
| 756 | existingCall.setConnectionService(ConnectionServiceWrapper.this); |
| 757 | } else { |
| 758 | Log.e(this, new RemoteException("The PhoneAccount being used is not " + |
| 759 | "currently registered with Telecom."), "Unable to " + |
| 760 | "addExistingConnection."); |
| 761 | } |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 762 | } |
| 763 | } finally { |
| 764 | Binder.restoreCallingIdentity(token); |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 765 | Log.endSession(); |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 766 | } |
Tyler Gunn | 6e2b94e | 2014-10-30 11:05:22 -0700 | [diff] [blame] | 767 | } |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 768 | |
| 769 | @Override |
Brad Ebinger | 6591275 | 2016-10-28 12:32:06 -0700 | [diff] [blame] | 770 | public void onConnectionEvent(String callId, String event, Bundle extras, |
| 771 | Session.Info sessionInfo) { |
| 772 | Log.startSession(sessionInfo, "CSW.oCE"); |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 773 | long token = Binder.clearCallingIdentity(); |
| 774 | try { |
| 775 | synchronized (mLock) { |
Jeff Sharkey | e2e4cdf | 2016-03-18 12:19:02 -0600 | [diff] [blame] | 776 | Bundle.setDefusable(extras, true); |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 777 | Call call = mCallIdMapper.getCall(callId); |
| 778 | if (call != null) { |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 779 | call.onConnectionEvent(event, extras); |
Tyler Gunn | db82191 | 2016-02-16 14:35:25 -0800 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | } finally { |
| 783 | Binder.restoreCallingIdentity(token); |
| 784 | Log.endSession(); |
| 785 | } |
| 786 | } |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 787 | |
| 788 | @Override |
| 789 | public void onRttInitiationSuccess(String callId, Session.Info sessionInfo) |
| 790 | throws RemoteException { |
| 791 | |
| 792 | } |
| 793 | |
| 794 | @Override |
| 795 | public void onRttInitiationFailure(String callId, int reason, Session.Info sessionInfo) |
| 796 | throws RemoteException { |
| 797 | Log.startSession(sessionInfo, "CSW.oRIF"); |
| 798 | long token = Binder.clearCallingIdentity(); |
| 799 | try { |
| 800 | synchronized (mLock) { |
| 801 | Call call = mCallIdMapper.getCall(callId); |
| 802 | if (call != null) { |
| 803 | call.onRttConnectionFailure(reason); |
| 804 | } |
| 805 | } |
| 806 | } finally { |
| 807 | Binder.restoreCallingIdentity(token); |
| 808 | Log.endSession(); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | @Override |
| 813 | public void onRttSessionRemotelyTerminated(String callId, Session.Info sessionInfo) |
| 814 | throws RemoteException { |
| 815 | |
| 816 | } |
| 817 | |
| 818 | @Override |
| 819 | public void onRemoteRttRequest(String callId, Session.Info sessionInfo) |
| 820 | throws RemoteException { |
| 821 | Log.startSession(sessionInfo, "CSW.oRRR"); |
| 822 | long token = Binder.clearCallingIdentity(); |
| 823 | try { |
| 824 | synchronized (mLock) { |
| 825 | Call call = mCallIdMapper.getCall(callId); |
| 826 | if (call != null) { |
| 827 | call.onRemoteRttRequest(); |
| 828 | } |
| 829 | } |
| 830 | } finally { |
| 831 | Binder.restoreCallingIdentity(token); |
| 832 | Log.endSession(); |
| 833 | } |
| 834 | } |
Srikanth Chintala | 1c586c6 | 2017-05-04 20:55:01 +0530 | [diff] [blame] | 835 | |
| 836 | @Override |
| 837 | public void onPhoneAccountChanged(String callId, PhoneAccountHandle pHandle, |
| 838 | Session.Info sessionInfo) throws RemoteException { |
Brad Ebinger | 702f8f5 | 2017-08-18 13:09:06 -0700 | [diff] [blame] | 839 | // Check that the Calling Package matches PhoneAccountHandle's Component Package |
| 840 | if (pHandle != null) { |
| 841 | mAppOpsManager.checkPackage(Binder.getCallingUid(), |
| 842 | pHandle.getComponentName().getPackageName()); |
| 843 | } |
Srikanth Chintala | 1c586c6 | 2017-05-04 20:55:01 +0530 | [diff] [blame] | 844 | Log.startSession(sessionInfo, "CSW.oPAC"); |
| 845 | long token = Binder.clearCallingIdentity(); |
| 846 | try { |
| 847 | synchronized (mLock) { |
| 848 | Call call = mCallIdMapper.getCall(callId); |
| 849 | if (call != null) { |
| 850 | call.setTargetPhoneAccount(pHandle); |
| 851 | } |
| 852 | } |
| 853 | } finally { |
| 854 | Binder.restoreCallingIdentity(token); |
| 855 | Log.endSession(); |
| 856 | } |
| 857 | } |
Pengquan Meng | 4845c9b | 2017-12-01 12:03:28 -0800 | [diff] [blame] | 858 | |
| 859 | @Override |
| 860 | public void onConnectionServiceFocusReleased(Session.Info sessionInfo) |
| 861 | throws RemoteException { |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 862 | Log.startSession(sessionInfo, "CSW.oCSFR"); |
| 863 | long token = Binder.clearCallingIdentity(); |
| 864 | try { |
| 865 | synchronized (mLock) { |
| 866 | mConnSvrFocusListener.onConnectionServiceReleased( |
| 867 | ConnectionServiceWrapper.this); |
| 868 | } |
| 869 | } finally { |
| 870 | Binder.restoreCallingIdentity(token); |
| 871 | Log.endSession(); |
| 872 | } |
Pengquan Meng | 4845c9b | 2017-12-01 12:03:28 -0800 | [diff] [blame] | 873 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | private final Adapter mAdapter = new Adapter(); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 877 | private final CallIdMapper mCallIdMapper = new CallIdMapper(Call::getConnectionId); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 878 | private final Map<String, CreateConnectionResponse> mPendingResponses = new HashMap<>(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 879 | |
Ihab Awad | 512d635 | 2015-03-26 13:43:22 -0700 | [diff] [blame] | 880 | private Binder2 mBinder = new Binder2(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 881 | private IConnectionService mServiceInterface; |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 882 | private final ConnectionServiceRepository mConnectionServiceRepository; |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 883 | private final PhoneAccountRegistrar mPhoneAccountRegistrar; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 884 | private final CallsManager mCallsManager; |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 885 | private final AppOpsManager mAppOpsManager; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 886 | |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 887 | private ConnectionServiceFocusManager.ConnectionServiceFocusListener mConnSvrFocusListener; |
| 888 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 889 | /** |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 890 | * Creates a connection service. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 891 | * |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 892 | * @param componentName The component name of the service with which to bind. |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 893 | * @param connectionServiceRepository Connection service repository. |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 894 | * @param phoneAccountRegistrar Phone account registrar |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 895 | * @param callsManager Calls manager |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 896 | * @param context The context. |
Evan Charlton | 105d977 | 2014-11-25 14:08:53 -0800 | [diff] [blame] | 897 | * @param userHandle The {@link UserHandle} to use when binding. |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 898 | */ |
| 899 | ConnectionServiceWrapper( |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 900 | ComponentName componentName, |
| 901 | ConnectionServiceRepository connectionServiceRepository, |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 902 | PhoneAccountRegistrar phoneAccountRegistrar, |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 903 | CallsManager callsManager, |
Evan Charlton | 105d977 | 2014-11-25 14:08:53 -0800 | [diff] [blame] | 904 | Context context, |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 905 | TelecomSystem.SyncRoot lock, |
Evan Charlton | 105d977 | 2014-11-25 14:08:53 -0800 | [diff] [blame] | 906 | UserHandle userHandle) { |
Ihab Awad | 8d5d9dd | 2015-03-12 11:11:06 -0700 | [diff] [blame] | 907 | super(ConnectionService.SERVICE_INTERFACE, componentName, context, lock, userHandle); |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 908 | mConnectionServiceRepository = connectionServiceRepository; |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 909 | phoneAccountRegistrar.addListener(new PhoneAccountRegistrar.Listener() { |
| 910 | // TODO -- Upon changes to PhoneAccountRegistrar, need to re-wire connections |
| 911 | // To do this, we must proxy remote ConnectionService objects |
| 912 | }); |
Tyler Gunn | 91d43cf | 2014-09-17 12:19:39 -0700 | [diff] [blame] | 913 | mPhoneAccountRegistrar = phoneAccountRegistrar; |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 914 | mCallsManager = callsManager; |
Brad Ebinger | 9135095 | 2016-06-29 17:27:08 -0700 | [diff] [blame] | 915 | mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | /** See {@link IConnectionService#addConnectionServiceAdapter}. */ |
| 919 | private void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 920 | if (isServiceValid("addConnectionServiceAdapter")) { |
| 921 | try { |
Sailesh Nepal | 3fe8b72 | 2014-07-08 10:07:26 -0700 | [diff] [blame] | 922 | logOutgoing("addConnectionServiceAdapter %s", adapter); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 923 | mServiceInterface.addConnectionServiceAdapter(adapter, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 924 | } catch (RemoteException e) { |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 929 | /** See {@link IConnectionService#removeConnectionServiceAdapter}. */ |
| 930 | private void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 931 | if (isServiceValid("removeConnectionServiceAdapter")) { |
| 932 | try { |
| 933 | logOutgoing("removeConnectionServiceAdapter %s", adapter); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 934 | mServiceInterface.removeConnectionServiceAdapter(adapter, Log.getExternalSession()); |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 935 | } catch (RemoteException e) { |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 940 | /** |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 941 | * 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] | 942 | */ |
Brad Ebinger | f190007 | 2015-11-12 17:25:06 -0800 | [diff] [blame] | 943 | @VisibleForTesting |
| 944 | public void createConnection(final Call call, final CreateConnectionResponse response) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 945 | Log.d(this, "createConnection(%s) via %s.", call, getComponentName()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 946 | BindCallback callback = new BindCallback() { |
| 947 | @Override |
| 948 | public void onSuccess() { |
| 949 | String callId = mCallIdMapper.getCallId(call); |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 950 | mPendingResponses.put(callId, response); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 951 | |
| 952 | GatewayInfo gatewayInfo = call.getGatewayInfo(); |
Santos Cordon | b3907b3 | 2015-05-27 17:39:59 -0700 | [diff] [blame] | 953 | Bundle extras = call.getIntentExtras(); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 954 | if (gatewayInfo != null && gatewayInfo.getGatewayProviderPackageName() != null && |
Nancy Chen | 201b437 | 2014-09-08 14:18:24 -0700 | [diff] [blame] | 955 | gatewayInfo.getOriginalAddress() != null) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 956 | extras = (Bundle) extras.clone(); |
| 957 | extras.putString( |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 958 | TelecomManager.GATEWAY_PROVIDER_PACKAGE, |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 959 | gatewayInfo.getGatewayProviderPackageName()); |
| 960 | extras.putParcelable( |
Tyler Gunn | 7cc70b4 | 2014-09-12 22:17:27 -0700 | [diff] [blame] | 961 | TelecomManager.GATEWAY_ORIGINAL_ADDRESS, |
Nancy Chen | 201b437 | 2014-09-08 14:18:24 -0700 | [diff] [blame] | 962 | gatewayInfo.getOriginalAddress()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 963 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 964 | |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 965 | if (call.isIncoming() && mCallsManager.getEmergencyCallHelper() |
| 966 | .getLastEmergencyCallTimeMillis() > 0) { |
mike dooley | a2b067e | 2017-02-13 19:41:10 -0800 | [diff] [blame] | 967 | // Add the last emergency call time to the connection request for incoming calls |
| 968 | if (extras == call.getIntentExtras()) { |
| 969 | extras = (Bundle) extras.clone(); |
| 970 | } |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 971 | extras.putLong(android.telecom.Call.EXTRA_LAST_EMERGENCY_CALLBACK_TIME_MILLIS, |
| 972 | mCallsManager.getEmergencyCallHelper().getLastEmergencyCallTimeMillis()); |
mike dooley | 66f26d1 | 2016-12-19 13:25:47 -0800 | [diff] [blame] | 973 | } |
| 974 | |
Tyler Gunn | 6f6f1c5 | 2017-04-17 18:22:04 -0700 | [diff] [blame] | 975 | // Call is incoming and added because we're handing over from another; tell CS |
| 976 | // that its expected to handover. |
Tyler Gunn | 141ef58 | 2017-05-26 13:38:13 -0700 | [diff] [blame] | 977 | if (call.isIncoming() && call.getHandoverSourceCall() != null) { |
Tyler Gunn | 6f6f1c5 | 2017-04-17 18:22:04 -0700 | [diff] [blame] | 978 | extras.putBoolean(TelecomManager.EXTRA_IS_HANDOVER, true); |
Tyler Gunn | 141ef58 | 2017-05-26 13:38:13 -0700 | [diff] [blame] | 979 | extras.putParcelable(TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT, |
| 980 | call.getHandoverSourceCall().getTargetPhoneAccount()); |
Tyler Gunn | 6f6f1c5 | 2017-04-17 18:22:04 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 983 | Log.addEvent(call, LogUtils.Events.START_CONNECTION, |
| 984 | Log.piiHandle(call.getHandle())); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 985 | |
Hall Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 986 | ConnectionRequest connectionRequest = new ConnectionRequest.Builder() |
| 987 | .setAccountHandle(call.getTargetPhoneAccount()) |
| 988 | .setAddress(call.getHandle()) |
Brad Ebinger | 6b0b603 | 2017-02-23 17:03:01 -0800 | [diff] [blame] | 989 | .setExtras(extras) |
Hall Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 990 | .setVideoState(call.getVideoState()) |
| 991 | .setTelecomCallId(callId) |
Tyler Gunn | 2b17f23 | 2017-03-08 08:51:00 -0800 | [diff] [blame] | 992 | // For self-managed incoming calls, if there is another ongoing call Telecom |
| 993 | // is responsible for showing a UI to ask the user if they'd like to answer |
| 994 | // this new incoming call. |
| 995 | .setShouldShowIncomingCallUi( |
| 996 | !mCallsManager.shouldShowSystemIncomingCallUi(call)) |
Hall Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 997 | .setRttPipeFromInCall(call.getInCallToCsRttPipeForCs()) |
| 998 | .setRttPipeToInCall(call.getCsToInCallRttPipeForCs()) |
| 999 | .build(); |
| 1000 | |
| 1001 | try { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1002 | mServiceInterface.createConnection( |
| 1003 | call.getConnectionManagerPhoneAccount(), |
Ihab Awad | 6fb37c8 | 2014-08-07 19:48:57 -0700 | [diff] [blame] | 1004 | callId, |
Hall Liu | dd68bc3 | 2017-01-25 17:14:23 -0800 | [diff] [blame] | 1005 | connectionRequest, |
Hall Liu | 3258720 | 2015-11-18 11:10:08 -0800 | [diff] [blame] | 1006 | call.shouldAttachToExistingConnection(), |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1007 | call.isUnknown(), |
| 1008 | Log.getExternalSession()); |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1009 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1010 | } catch (RemoteException e) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1011 | Log.e(this, e, "Failure to createConnection -- %s", getComponentName()); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1012 | mPendingResponses.remove(callId).handleCreateConnectionFailure( |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1013 | new DisconnectCause(DisconnectCause.ERROR, e.toString())); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public void onFailure() { |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 1019 | Log.e(this, new Exception(), "Failure to call %s", getComponentName()); |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1020 | response.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.ERROR)); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1021 | } |
| 1022 | }; |
| 1023 | |
Santos Cordon | 165c1ce | 2015-07-10 16:07:59 -0700 | [diff] [blame] | 1024 | mBinder.bind(callback, call); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1027 | /** |
| 1028 | * Notifies the {@link ConnectionService} associated with a {@link Call} that the request to |
| 1029 | * create a connection has been denied or failed. |
| 1030 | * @param call The call. |
| 1031 | */ |
| 1032 | void createConnectionFailed(final Call call) { |
| 1033 | Log.d(this, "createConnectionFailed(%s) via %s.", call, getComponentName()); |
| 1034 | BindCallback callback = new BindCallback() { |
| 1035 | @Override |
| 1036 | public void onSuccess() { |
| 1037 | final String callId = mCallIdMapper.getCallId(call); |
| 1038 | // If still bound, tell the connection service create connection has failed. |
| 1039 | if (callId != null && isServiceValid("createConnectionFailed")) { |
| 1040 | Log.addEvent(call, LogUtils.Events.CREATE_CONNECTION_FAILED, |
| 1041 | Log.piiHandle(call.getHandle())); |
| 1042 | try { |
| 1043 | logOutgoing("createConnectionFailed %s", callId); |
Tyler Gunn | 115c06e | 2017-03-02 09:29:07 -0800 | [diff] [blame] | 1044 | mServiceInterface.createConnectionFailed( |
| 1045 | call.getConnectionManagerPhoneAccount(), |
| 1046 | callId, |
Tyler Gunn | a90ba73 | 2017-01-26 07:24:08 -0800 | [diff] [blame] | 1047 | new ConnectionRequest( |
| 1048 | call.getTargetPhoneAccount(), |
| 1049 | call.getHandle(), |
| 1050 | call.getIntentExtras(), |
| 1051 | call.getVideoState(), |
| 1052 | callId, |
| 1053 | false), |
| 1054 | call.isIncoming(), |
| 1055 | Log.getExternalSession()); |
| 1056 | call.setDisconnectCause(new DisconnectCause(DisconnectCause.CANCELED)); |
| 1057 | call.disconnect(); |
| 1058 | } catch (RemoteException e) { |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | @Override |
| 1064 | public void onFailure() { |
| 1065 | // Binding failed. Oh no. |
| 1066 | Log.w(this, "onFailure - could not bind to CS for call %s", call.getId()); |
| 1067 | } |
| 1068 | }; |
| 1069 | |
| 1070 | mBinder.bind(callback, call); |
| 1071 | } |
| 1072 | |
Sanket Padawe | 29411c9 | 2017-11-30 16:51:08 -0800 | [diff] [blame] | 1073 | void handoverFailed(final Call call, final int reason) { |
| 1074 | Log.d(this, "handoverFailed(%s) via %s.", call, getComponentName()); |
| 1075 | BindCallback callback = new BindCallback() { |
| 1076 | @Override |
| 1077 | public void onSuccess() { |
| 1078 | final String callId = mCallIdMapper.getCallId(call); |
| 1079 | // If still bound, tell the connection service create connection has failed. |
| 1080 | if (callId != null && isServiceValid("handoverFailed")) { |
| 1081 | Log.addEvent(call, LogUtils.Events.HANDOVER_FAILED, |
| 1082 | Log.piiHandle(call.getHandle())); |
| 1083 | try { |
| 1084 | mServiceInterface.handoverFailed( |
| 1085 | callId, |
| 1086 | new ConnectionRequest( |
| 1087 | call.getTargetPhoneAccount(), |
| 1088 | call.getHandle(), |
| 1089 | call.getIntentExtras(), |
| 1090 | call.getVideoState(), |
| 1091 | callId, |
| 1092 | false), reason, Log.getExternalSession()); |
| 1093 | } catch (RemoteException e) { |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | @Override |
| 1099 | public void onFailure() { |
| 1100 | // Binding failed. |
| 1101 | Log.w(this, "onFailure - could not bind to CS for call %s", |
| 1102 | call.getId()); |
| 1103 | } |
| 1104 | }; |
| 1105 | |
| 1106 | mBinder.bind(callback, call); |
| 1107 | } |
| 1108 | |
Tyler Gunn | 7c031f2 | 2018-01-18 15:00:41 -0800 | [diff] [blame] | 1109 | void handoverComplete(final Call call) { |
| 1110 | Log.d(this, "handoverComplete(%s) via %s.", call, getComponentName()); |
| 1111 | BindCallback callback = new BindCallback() { |
| 1112 | @Override |
| 1113 | public void onSuccess() { |
| 1114 | final String callId = mCallIdMapper.getCallId(call); |
| 1115 | // If still bound, tell the connection service create connection has failed. |
| 1116 | if (callId != null && isServiceValid("handoverComplete")) { |
| 1117 | try { |
| 1118 | mServiceInterface.handoverComplete( |
| 1119 | callId, |
| 1120 | Log.getExternalSession()); |
| 1121 | } catch (RemoteException e) { |
| 1122 | } |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | @Override |
| 1127 | public void onFailure() { |
| 1128 | // Binding failed. |
| 1129 | Log.w(this, "onFailure - could not bind to CS for call %s", |
| 1130 | call.getId()); |
| 1131 | } |
| 1132 | }; |
| 1133 | |
| 1134 | mBinder.bind(callback, call); |
| 1135 | } |
| 1136 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1137 | /** @see IConnectionService#abort(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1138 | void abort(Call call) { |
| 1139 | // Clear out any pending outgoing call data |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1140 | final String callId = mCallIdMapper.getCallId(call); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1141 | |
| 1142 | // If still bound, tell the connection service to abort. |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1143 | if (callId != null && isServiceValid("abort")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1144 | try { |
| 1145 | logOutgoing("abort %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1146 | mServiceInterface.abort(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1147 | } catch (RemoteException e) { |
| 1148 | } |
| 1149 | } |
| 1150 | |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1151 | removeCall(call, new DisconnectCause(DisconnectCause.LOCAL)); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1154 | /** @see IConnectionService#silence(String, Session.Info) */ |
Bryce Lee | 6d96252 | 2015-11-30 10:28:37 -0800 | [diff] [blame] | 1155 | void silence(Call call) { |
| 1156 | final String callId = mCallIdMapper.getCallId(call); |
| 1157 | if (callId != null && isServiceValid("silence")) { |
| 1158 | try { |
| 1159 | logOutgoing("silence %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1160 | mServiceInterface.silence(callId, Log.getExternalSession()); |
Bryce Lee | 6d96252 | 2015-11-30 10:28:37 -0800 | [diff] [blame] | 1161 | } catch (RemoteException e) { |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1166 | /** @see IConnectionService#hold(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1167 | void hold(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1168 | final String callId = mCallIdMapper.getCallId(call); |
| 1169 | if (callId != null && isServiceValid("hold")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1170 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1171 | logOutgoing("hold %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1172 | mServiceInterface.hold(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1173 | } catch (RemoteException e) { |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1178 | /** @see IConnectionService#unhold(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1179 | void unhold(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1180 | final String callId = mCallIdMapper.getCallId(call); |
| 1181 | if (callId != null && isServiceValid("unhold")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1182 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1183 | logOutgoing("unhold %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1184 | mServiceInterface.unhold(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1185 | } catch (RemoteException e) { |
| 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1190 | /** @see IConnectionService#onCallAudioStateChanged(String, CallAudioState, Session.Info) */ |
Hall Liu | f62630a | 2015-10-27 14:53:39 -0700 | [diff] [blame] | 1191 | @VisibleForTesting |
| 1192 | public void onCallAudioStateChanged(Call activeCall, CallAudioState audioState) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1193 | final String callId = mCallIdMapper.getCallId(activeCall); |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1194 | if (callId != null && isServiceValid("onCallAudioStateChanged")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1195 | try { |
Yorke Lee | 2a66f7b | 2015-05-13 14:21:19 -0700 | [diff] [blame] | 1196 | logOutgoing("onCallAudioStateChanged %s %s", callId, audioState); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1197 | mServiceInterface.onCallAudioStateChanged(callId, audioState, |
| 1198 | Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1199 | } catch (RemoteException e) { |
| 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1204 | /** @see IConnectionService#disconnect(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1205 | void disconnect(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1206 | final String callId = mCallIdMapper.getCallId(call); |
| 1207 | if (callId != null && isServiceValid("disconnect")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1208 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1209 | logOutgoing("disconnect %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1210 | mServiceInterface.disconnect(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1211 | } catch (RemoteException e) { |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1216 | /** @see IConnectionService#answer(String, Session.Info) */ |
Andrew Lee | 38931d0 | 2014-07-16 10:17:36 -0700 | [diff] [blame] | 1217 | void answer(Call call, int videoState) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1218 | final String callId = mCallIdMapper.getCallId(call); |
| 1219 | if (callId != null && isServiceValid("answer")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1220 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1221 | logOutgoing("answer %s %d", callId, videoState); |
Tyler Gunn | 467b64f | 2015-06-09 13:48:47 -0700 | [diff] [blame] | 1222 | if (VideoProfile.isAudioOnly(videoState)) { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1223 | mServiceInterface.answer(callId, Log.getExternalSession()); |
Tyler Gunn | 041eff6 | 2014-08-25 13:52:52 -0700 | [diff] [blame] | 1224 | } else { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1225 | mServiceInterface.answerVideo(callId, videoState, Log.getExternalSession()); |
Tyler Gunn | 041eff6 | 2014-08-25 13:52:52 -0700 | [diff] [blame] | 1226 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1227 | } catch (RemoteException e) { |
| 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
Pooja Jain | ad4ebc0 | 2017-12-28 14:23:13 +0530 | [diff] [blame] | 1232 | /** @see IConnectionService#deflect(String, Uri , Session.Info) */ |
| 1233 | void deflect(Call call, Uri address) { |
| 1234 | final String callId = mCallIdMapper.getCallId(call); |
| 1235 | if (callId != null && isServiceValid("deflect")) { |
| 1236 | try { |
| 1237 | logOutgoing("deflect %s", callId); |
| 1238 | mServiceInterface.deflect(callId, address, Log.getExternalSession()); |
| 1239 | } catch (RemoteException e) { |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1244 | /** @see IConnectionService#reject(String, Session.Info) */ |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1245 | void reject(Call call, boolean rejectWithMessage, String message) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1246 | final String callId = mCallIdMapper.getCallId(call); |
| 1247 | if (callId != null && isServiceValid("reject")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1248 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1249 | logOutgoing("reject %s", callId); |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1250 | |
| 1251 | if (rejectWithMessage && call.can( |
Hall Liu | 4b1617a | 2016-03-14 16:36:08 -0700 | [diff] [blame] | 1252 | Connection.CAPABILITY_CAN_SEND_RESPONSE_VIA_CONNECTION)) { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1253 | mServiceInterface.rejectWithMessage(callId, message, Log.getExternalSession()); |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1254 | } else { |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1255 | mServiceInterface.reject(callId, Log.getExternalSession()); |
Bryce Lee | ddd966e | 2015-08-28 16:33:50 -0700 | [diff] [blame] | 1256 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1257 | } catch (RemoteException e) { |
| 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1262 | /** @see IConnectionService#playDtmfTone(String, char, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1263 | void playDtmfTone(Call call, char digit) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1264 | final String callId = mCallIdMapper.getCallId(call); |
| 1265 | if (callId != null && isServiceValid("playDtmfTone")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1266 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1267 | logOutgoing("playDtmfTone %s %c", callId, digit); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1268 | mServiceInterface.playDtmfTone(callId, digit, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1269 | } catch (RemoteException e) { |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1274 | /** @see IConnectionService#stopDtmfTone(String, Session.Info) */ |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1275 | void stopDtmfTone(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1276 | final String callId = mCallIdMapper.getCallId(call); |
| 1277 | if (callId != null && isServiceValid("stopDtmfTone")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1278 | try { |
Brad Ebinger | 11623a3 | 2015-11-25 13:52:02 -0800 | [diff] [blame] | 1279 | logOutgoing("stopDtmfTone %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1280 | mServiceInterface.stopDtmfTone(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1281 | } catch (RemoteException e) { |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | void addCall(Call call) { |
| 1287 | if (mCallIdMapper.getCallId(call) == null) { |
| 1288 | mCallIdMapper.addCall(call); |
| 1289 | } |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * Associates newCall with this connection service by replacing callToReplace. |
| 1294 | */ |
| 1295 | void replaceCall(Call newCall, Call callToReplace) { |
| 1296 | Preconditions.checkState(callToReplace.getConnectionService() == this); |
| 1297 | mCallIdMapper.replaceCall(newCall, callToReplace); |
| 1298 | } |
| 1299 | |
| 1300 | void removeCall(Call call) { |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1301 | removeCall(call, new DisconnectCause(DisconnectCause.ERROR)); |
Santos Cordon | fd6ca44 | 2014-07-24 15:34:01 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1304 | void removeCall(String callId, DisconnectCause disconnectCause) { |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1305 | CreateConnectionResponse response = mPendingResponses.remove(callId); |
| 1306 | if (response != null) { |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1307 | response.handleCreateConnectionFailure(disconnectCause); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | mCallIdMapper.removeCall(callId); |
| 1311 | } |
| 1312 | |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1313 | void removeCall(Call call, DisconnectCause disconnectCause) { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1314 | CreateConnectionResponse response = mPendingResponses.remove(mCallIdMapper.getCallId(call)); |
| 1315 | if (response != null) { |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1316 | response.handleCreateConnectionFailure(disconnectCause); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | mCallIdMapper.removeCall(call); |
| 1320 | } |
| 1321 | |
| 1322 | void onPostDialContinue(Call call, boolean proceed) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1323 | final String callId = mCallIdMapper.getCallId(call); |
| 1324 | if (callId != null && isServiceValid("onPostDialContinue")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1325 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1326 | logOutgoing("onPostDialContinue %s %b", callId, proceed); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1327 | mServiceInterface.onPostDialContinue(callId, proceed, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1328 | } catch (RemoteException ignored) { |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1333 | void conference(final Call call, Call otherCall) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1334 | final String callId = mCallIdMapper.getCallId(call); |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1335 | final String otherCallId = mCallIdMapper.getCallId(otherCall); |
| 1336 | if (callId != null && otherCallId != null && isServiceValid("conference")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1337 | try { |
Santos Cordon | 0fbe632 | 2014-08-14 04:04:25 -0700 | [diff] [blame] | 1338 | logOutgoing("conference %s %s", callId, otherCallId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1339 | mServiceInterface.conference(callId, otherCallId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1340 | } catch (RemoteException ignored) { |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | void splitFromConference(Call call) { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1346 | final String callId = mCallIdMapper.getCallId(call); |
| 1347 | if (callId != null && isServiceValid("splitFromConference")) { |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1348 | try { |
Jay Shrauner | 969755a | 2014-08-11 20:34:43 -0700 | [diff] [blame] | 1349 | logOutgoing("splitFromConference %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1350 | mServiceInterface.splitFromConference(callId, Log.getExternalSession()); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1351 | } catch (RemoteException ignored) { |
| 1352 | } |
| 1353 | } |
| 1354 | } |
| 1355 | |
Santos Cordon | 6805923 | 2014-09-04 20:09:42 -0700 | [diff] [blame] | 1356 | void mergeConference(Call call) { |
| 1357 | final String callId = mCallIdMapper.getCallId(call); |
| 1358 | if (callId != null && isServiceValid("mergeConference")) { |
| 1359 | try { |
| 1360 | logOutgoing("mergeConference %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1361 | mServiceInterface.mergeConference(callId, Log.getExternalSession()); |
Santos Cordon | 6805923 | 2014-09-04 20:09:42 -0700 | [diff] [blame] | 1362 | } catch (RemoteException ignored) { |
| 1363 | } |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | void swapConference(Call call) { |
| 1368 | final String callId = mCallIdMapper.getCallId(call); |
| 1369 | if (callId != null && isServiceValid("swapConference")) { |
| 1370 | try { |
| 1371 | logOutgoing("swapConference %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1372 | mServiceInterface.swapConference(callId, Log.getExternalSession()); |
Santos Cordon | 6805923 | 2014-09-04 20:09:42 -0700 | [diff] [blame] | 1373 | } catch (RemoteException ignored) { |
| 1374 | } |
| 1375 | } |
| 1376 | } |
| 1377 | |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 1378 | void pullExternalCall(Call call) { |
| 1379 | final String callId = mCallIdMapper.getCallId(call); |
| 1380 | if (callId != null && isServiceValid("pullExternalCall")) { |
| 1381 | try { |
| 1382 | logOutgoing("pullExternalCall %s", callId); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1383 | mServiceInterface.pullExternalCall(callId, Log.getExternalSession()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 1384 | } catch (RemoteException ignored) { |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | void sendCallEvent(Call call, String event, Bundle extras) { |
| 1390 | final String callId = mCallIdMapper.getCallId(call); |
| 1391 | if (callId != null && isServiceValid("sendCallEvent")) { |
| 1392 | try { |
| 1393 | logOutgoing("sendCallEvent %s %s", callId, event); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1394 | mServiceInterface.sendCallEvent(callId, event, extras, Log.getExternalSession()); |
Tyler Gunn | d45e6d9 | 2016-03-10 20:15:39 -0800 | [diff] [blame] | 1395 | } catch (RemoteException ignored) { |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 1400 | void onExtrasChanged(Call call, Bundle extras) { |
| 1401 | final String callId = mCallIdMapper.getCallId(call); |
| 1402 | if (callId != null && isServiceValid("onExtrasChanged")) { |
| 1403 | try { |
| 1404 | logOutgoing("onExtrasChanged %s %s", callId, extras); |
Brad Ebinger | b78b023 | 2016-10-24 16:40:33 -0700 | [diff] [blame] | 1405 | mServiceInterface.onExtrasChanged(callId, extras, Log.getExternalSession()); |
Tyler Gunn | 961694a | 2016-03-21 16:01:40 -0700 | [diff] [blame] | 1406 | } catch (RemoteException ignored) { |
| 1407 | } |
| 1408 | } |
| 1409 | } |
| 1410 | |
Hall Liu | aeece4e | 2017-02-14 16:42:12 -0800 | [diff] [blame] | 1411 | void startRtt(Call call, ParcelFileDescriptor fromInCall, ParcelFileDescriptor toInCall) { |
| 1412 | final String callId = mCallIdMapper.getCallId(call); |
| 1413 | if (callId != null && isServiceValid("startRtt")) { |
| 1414 | try { |
| 1415 | logOutgoing("startRtt: %s %s %s", callId, fromInCall, toInCall); |
| 1416 | mServiceInterface.startRtt(callId, fromInCall, toInCall, Log.getExternalSession()); |
| 1417 | } catch (RemoteException ignored) { |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | void stopRtt(Call call) { |
| 1423 | final String callId = mCallIdMapper.getCallId(call); |
| 1424 | if (callId != null && isServiceValid("stopRtt")) { |
| 1425 | try { |
| 1426 | logOutgoing("stopRtt: %s", callId); |
| 1427 | mServiceInterface.stopRtt(callId, Log.getExternalSession()); |
| 1428 | } catch (RemoteException ignored) { |
| 1429 | } |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | void respondToRttRequest( |
| 1434 | Call call, ParcelFileDescriptor fromInCall, ParcelFileDescriptor toInCall) { |
| 1435 | final String callId = mCallIdMapper.getCallId(call); |
| 1436 | if (callId != null && isServiceValid("respondToRttRequest")) { |
| 1437 | try { |
| 1438 | logOutgoing("respondToRttRequest: %s %s %s", callId, fromInCall, toInCall); |
| 1439 | mServiceInterface.respondToRttUpgradeRequest( |
| 1440 | callId, fromInCall, toInCall, Log.getExternalSession()); |
| 1441 | } catch (RemoteException ignored) { |
| 1442 | } |
| 1443 | } |
| 1444 | } |
| 1445 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1446 | /** {@inheritDoc} */ |
| 1447 | @Override |
| 1448 | protected void setServiceInterface(IBinder binder) { |
Brad Ebinger | 6e8f3d7 | 2016-06-20 11:35:42 -0700 | [diff] [blame] | 1449 | mServiceInterface = IConnectionService.Stub.asInterface(binder); |
| 1450 | Log.v(this, "Adding Connection Service Adapter."); |
| 1451 | addConnectionServiceAdapter(mAdapter); |
| 1452 | } |
| 1453 | |
| 1454 | /** {@inheritDoc} */ |
| 1455 | @Override |
| 1456 | protected void removeServiceInterface() { |
| 1457 | Log.v(this, "Removing Connection Service Adapter."); |
| 1458 | removeConnectionServiceAdapter(mAdapter); |
| 1459 | // We have lost our service connection. Notify the world that this service is done. |
| 1460 | // We must notify the adapter before CallsManager. The adapter will force any pending |
| 1461 | // outgoing calls to try the next service. This needs to happen before CallsManager |
| 1462 | // tries to clean up any calls still associated with this service. |
| 1463 | handleConnectionServiceDeath(); |
| 1464 | mCallsManager.handleConnectionServiceDeath(this); |
| 1465 | mServiceInterface = null; |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1468 | @Override |
| 1469 | public void connectionServiceFocusLost() { |
| 1470 | // Immediately response to the Telecom that it has released the call resources. |
| 1471 | // TODO(mpq): Change back to the default implementation once b/69651192 done. |
| 1472 | if (mConnSvrFocusListener != null) { |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 1473 | mConnSvrFocusListener.onConnectionServiceReleased(ConnectionServiceWrapper.this); |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1474 | } |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 1475 | BindCallback callback = new BindCallback() { |
| 1476 | @Override |
| 1477 | public void onSuccess() { |
| 1478 | try { |
| 1479 | mServiceInterface.connectionServiceFocusLost(Log.getExternalSession()); |
| 1480 | } catch (RemoteException ignored) { |
| 1481 | Log.d(this, "failed to inform the focus lost event"); |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | @Override |
| 1486 | public void onFailure() {} |
| 1487 | }; |
| 1488 | mBinder.bind(callback, null /* null call */); |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | @Override |
Pengquan Meng | 4832f20 | 2017-12-20 16:13:04 -0800 | [diff] [blame] | 1492 | public void connectionServiceFocusGained() { |
| 1493 | BindCallback callback = new BindCallback() { |
| 1494 | @Override |
| 1495 | public void onSuccess() { |
| 1496 | try { |
| 1497 | mServiceInterface.connectionServiceFocusGained(Log.getExternalSession()); |
| 1498 | } catch (RemoteException ignored) { |
| 1499 | Log.d(this, "failed to inform the focus gained event"); |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | @Override |
| 1504 | public void onFailure() {} |
| 1505 | }; |
| 1506 | mBinder.bind(callback, null /* null call */); |
| 1507 | } |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1508 | |
| 1509 | @Override |
| 1510 | public void setConnectionServiceFocusListener( |
| 1511 | ConnectionServiceFocusManager.ConnectionServiceFocusListener listener) { |
| 1512 | mConnSvrFocusListener = listener; |
| 1513 | } |
| 1514 | |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1515 | private void handleCreateConnectionComplete( |
| 1516 | String callId, |
| 1517 | ConnectionRequest request, |
| 1518 | ParcelableConnection connection) { |
| 1519 | // TODO: Note we are not using parameter "request", which is a side effect of our tacit |
| 1520 | // assumption that we have at most one outgoing connection attempt per ConnectionService. |
| 1521 | // This may not continue to be the case. |
| 1522 | if (connection.getState() == Connection.STATE_DISCONNECTED) { |
| 1523 | // A connection that begins in the DISCONNECTED state is an indication of |
| 1524 | // failure to connect; we handle all failures uniformly |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1525 | removeCall(callId, connection.getDisconnectCause()); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1526 | } else { |
| 1527 | // Successful connection |
| 1528 | if (mPendingResponses.containsKey(callId)) { |
Ihab Awad | 8000845 | 2014-08-23 20:35:44 -0700 | [diff] [blame] | 1529 | mPendingResponses.remove(callId) |
| 1530 | .handleCreateConnectionSuccess(mCallIdMapper, connection); |
Ihab Awad | fb5560d | 2014-08-18 09:32:51 -0700 | [diff] [blame] | 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1535 | /** |
| 1536 | * Called when the associated connection service dies. |
| 1537 | */ |
| 1538 | private void handleConnectionServiceDeath() { |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1539 | if (!mPendingResponses.isEmpty()) { |
| 1540 | CreateConnectionResponse[] responses = mPendingResponses.values().toArray( |
| 1541 | new CreateConnectionResponse[mPendingResponses.values().size()]); |
| 1542 | mPendingResponses.clear(); |
| 1543 | for (int i = 0; i < responses.length; i++) { |
Andrew Lee | 701dc00 | 2014-09-11 21:29:12 -0700 | [diff] [blame] | 1544 | responses[i].handleCreateConnectionFailure( |
Tyler Gunn | 1a97fb2 | 2017-06-21 19:55:54 -0700 | [diff] [blame] | 1545 | new DisconnectCause(DisconnectCause.ERROR, "CS_DEATH")); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1546 | } |
| 1547 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1548 | mCallIdMapper.clear(); |
Pengquan Meng | d7f92cf | 2017-11-21 17:52:42 -0800 | [diff] [blame] | 1549 | |
| 1550 | if (mConnSvrFocusListener != null) { |
| 1551 | mConnSvrFocusListener.onConnectionServiceDeath(this); |
| 1552 | } |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | private void logIncoming(String msg, Object... params) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 1556 | Log.d(this, "ConnectionService -> Telecom[" + mComponentName.flattenToShortString() + "]: " |
Tyler Gunn | 46bc3fd | 2017-04-03 18:53:38 +0000 | [diff] [blame] | 1557 | + msg, params); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | private void logOutgoing(String msg, Object... params) { |
Tyler Gunn | 9b618b8 | 2016-10-17 15:54:35 -0700 | [diff] [blame] | 1561 | Log.d(this, "Telecom -> ConnectionService[" + mComponentName.flattenToShortString() + "]: " |
Tyler Gunn | 46bc3fd | 2017-04-03 18:53:38 +0000 | [diff] [blame] | 1562 | + msg, params); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1565 | private void queryRemoteConnectionServices(final UserHandle userHandle, |
| 1566 | final RemoteServiceCallback callback) { |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1567 | // Only give remote connection services to this connection service if it is listed as |
| 1568 | // the connection manager. |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1569 | PhoneAccountHandle simCallManager = mPhoneAccountRegistrar.getSimCallManager(userHandle); |
Ihab Awad | c17294c | 2014-08-04 19:23:37 -0700 | [diff] [blame] | 1570 | Log.d(this, "queryRemoteConnectionServices finds simCallManager = %s", simCallManager); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1571 | if (simCallManager == null || |
| 1572 | !simCallManager.getComponentName().equals(getComponentName())) { |
| 1573 | noRemoteServices(callback); |
| 1574 | return; |
| 1575 | } |
Sailesh Nepal | 664837f | 2014-07-14 16:31:51 -0700 | [diff] [blame] | 1576 | |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1577 | // 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] | 1578 | final Set<ConnectionServiceWrapper> simServices = Collections.newSetFromMap( |
| 1579 | new ConcurrentHashMap<ConnectionServiceWrapper, Boolean>(8, 0.9f, 1)); |
Tony Mak | 240656f | 2015-12-04 11:36:22 +0000 | [diff] [blame] | 1580 | for (PhoneAccountHandle handle : mPhoneAccountRegistrar.getSimPhoneAccounts(userHandle)) { |
Santos Cordon | 6a21264 | 2015-05-08 16:35:23 -0700 | [diff] [blame] | 1581 | ConnectionServiceWrapper service = mConnectionServiceRepository.getService( |
| 1582 | handle.getComponentName(), handle.getUserHandle()); |
| 1583 | if (service != null) { |
| 1584 | simServices.add(service); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1585 | } |
Sailesh Nepal | 905dfba | 2014-07-14 08:20:41 -0700 | [diff] [blame] | 1586 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1587 | |
| 1588 | final List<ComponentName> simServiceComponentNames = new ArrayList<>(); |
| 1589 | final List<IBinder> simServiceBinders = new ArrayList<>(); |
| 1590 | |
| 1591 | Log.v(this, "queryRemoteConnectionServices, simServices = %s", simServices); |
| 1592 | |
| 1593 | for (ConnectionServiceWrapper simService : simServices) { |
| 1594 | if (simService == this) { |
| 1595 | // Only happens in the unlikely case that a SIM service is also a SIM call manager |
| 1596 | continue; |
| 1597 | } |
| 1598 | |
| 1599 | final ConnectionServiceWrapper currentSimService = simService; |
| 1600 | |
| 1601 | currentSimService.mBinder.bind(new BindCallback() { |
| 1602 | @Override |
| 1603 | public void onSuccess() { |
| 1604 | Log.d(this, "Adding simService %s", currentSimService.getComponentName()); |
Tyler Gunn | 5983dc1 | 2018-03-08 23:22:31 +0000 | [diff] [blame] | 1605 | if (currentSimService.mServiceInterface == null) { |
| 1606 | // The remote ConnectionService died, so do not add it. |
| 1607 | // We will still perform maybeComplete() and notify the caller with an empty |
| 1608 | // list of sim services via maybeComplete(). |
| 1609 | Log.w(this, "queryRemoteConnectionServices: simService %s died - Skipping.", |
| 1610 | currentSimService.getComponentName()); |
| 1611 | } else { |
| 1612 | simServiceComponentNames.add(currentSimService.getComponentName()); |
| 1613 | simServiceBinders.add(currentSimService.mServiceInterface.asBinder()); |
| 1614 | } |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1615 | maybeComplete(); |
| 1616 | } |
| 1617 | |
| 1618 | @Override |
| 1619 | public void onFailure() { |
| 1620 | Log.d(this, "Failed simService %s", currentSimService.getComponentName()); |
| 1621 | // We know maybeComplete() will always be a no-op from now on, so go ahead and |
| 1622 | // signal failure of the entire request |
| 1623 | noRemoteServices(callback); |
| 1624 | } |
| 1625 | |
| 1626 | private void maybeComplete() { |
| 1627 | if (simServiceComponentNames.size() == simServices.size()) { |
| 1628 | setRemoteServices(callback, simServiceComponentNames, simServiceBinders); |
| 1629 | } |
| 1630 | } |
Santos Cordon | 165c1ce | 2015-07-10 16:07:59 -0700 | [diff] [blame] | 1631 | }, null); |
Ihab Awad | b78b276 | 2014-07-25 15:16:23 -0700 | [diff] [blame] | 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | private void setRemoteServices( |
| 1636 | RemoteServiceCallback callback, |
| 1637 | List<ComponentName> componentNames, |
| 1638 | List<IBinder> binders) { |
| 1639 | try { |
| 1640 | callback.onResult(componentNames, binders); |
| 1641 | } catch (RemoteException e) { |
| 1642 | Log.e(this, e, "Contacting ConnectionService %s", |
| 1643 | ConnectionServiceWrapper.this.getComponentName()); |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | private void noRemoteServices(RemoteServiceCallback callback) { |
Ihab Awad | 8de7691 | 2015-02-17 12:25:52 -0800 | [diff] [blame] | 1648 | setRemoteServices(callback, Collections.EMPTY_LIST, Collections.EMPTY_LIST); |
Sailesh Nepal | c92c436 | 2014-07-04 18:33:21 -0700 | [diff] [blame] | 1649 | } |
| 1650 | } |