Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | R* limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.telecomm; |
| 18 | |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame^] | 19 | import android.app.PendingIntent; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| 21 | import android.net.Uri; |
| 22 | import android.os.IBinder.DeathRecipient; |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 23 | import android.os.Handler; |
| 24 | import android.os.Message; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 25 | import android.os.RemoteException; |
| 26 | import android.telephony.DisconnectCause; |
| 27 | |
| 28 | import android.text.TextUtils; |
| 29 | |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 30 | import com.android.internal.os.SomeArgs; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 31 | import com.android.internal.telecomm.IConnectionService; |
| 32 | import com.android.internal.telecomm.IConnectionServiceAdapter; |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 33 | import com.android.internal.telecomm.ICallVideoProvider; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 34 | import com.android.internal.telecomm.RemoteServiceCallback; |
| 35 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 36 | import java.util.LinkedList; |
| 37 | import java.util.List; |
| 38 | import java.util.UUID; |
| 39 | |
| 40 | /** |
| 41 | * Remote connection service which other connection services can use to place calls on their behalf. |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 42 | * |
| 43 | * @hide |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 44 | */ |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 45 | final class RemoteConnectionService implements DeathRecipient { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 46 | private static final int MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL = 1; |
| 47 | private static final int MSG_HANDLE_CREATE_CONNECTION_FAILED = 2; |
| 48 | private static final int MSG_HANDLE_CREATE_CONNECTION_CANCELLED = 3; |
| 49 | private static final int MSG_SET_ACTIVE = 4; |
| 50 | private static final int MSG_SET_RINGING = 5; |
| 51 | private static final int MSG_SET_DIALING = 6; |
| 52 | private static final int MSG_SET_DISCONNECTED = 7; |
| 53 | private static final int MSG_SET_ON_HOLD = 8; |
| 54 | private static final int MSG_SET_REQUESTING_RINGBACK = 9; |
| 55 | private static final int MSG_SET_CALL_CAPABILITIES = 10; |
| 56 | private static final int MSG_SET_IS_CONFERENCED = 11; |
| 57 | private static final int MSG_ADD_CONFERENCE_CALL = 12; |
| 58 | private static final int MSG_REMOVE_CALL = 13; |
| 59 | private static final int MSG_ON_POST_DIAL_WAIT = 14; |
| 60 | private static final int MSG_QUERY_REMOTE_CALL_SERVICES = 15; |
| 61 | private static final int MSG_SET_VIDEO_STATE = 16; |
| 62 | private static final int MSG_SET_CALL_VIDEO_PROVIDER = 17; |
| 63 | private static final int MSG_SET_AUDIO_MODE_IS_VOIP = 18; |
| 64 | private static final int MSG_SET_STATUS_HINTS = 19; |
| 65 | private static final int MSG_SET_HANDLE = 20; |
| 66 | private static final int MSG_SET_CALLER_DISPLAY_NAME = 21; |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame^] | 67 | private static final int MSG_START_ACTIVITY_FROM_IN_CALL = 22; |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 68 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 69 | private final IConnectionService mConnectionService; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 70 | private final ComponentName mComponentName; |
| 71 | |
| 72 | private String mConnectionId; |
| 73 | private ConnectionRequest mPendingRequest; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 74 | private ConnectionService.CreateConnectionResponse<RemoteConnection> mPendingResponse; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 75 | // Remote connection services only support a single connection. |
| 76 | private RemoteConnection mConnection; |
| 77 | |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 78 | private final Handler mHandler = new Handler() { |
| 79 | @Override |
| 80 | public void handleMessage(Message msg) { |
| 81 | switch (msg.what) { |
| 82 | case MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL: { |
| 83 | ConnectionRequest request = (ConnectionRequest) msg.obj; |
| 84 | if (isPendingConnection(request.getCallId())) { |
| 85 | mConnection = new RemoteConnection(mConnectionService, request.getCallId()); |
| 86 | mPendingResponse.onSuccess(request, mConnection); |
| 87 | clearPendingInformation(); |
| 88 | } |
| 89 | break; |
| 90 | } |
| 91 | case MSG_HANDLE_CREATE_CONNECTION_FAILED: { |
| 92 | SomeArgs args = (SomeArgs) msg.obj; |
| 93 | try { |
| 94 | ConnectionRequest request = (ConnectionRequest) args.arg1; |
| 95 | if (isPendingConnection(request.getCallId())) { |
| 96 | mPendingResponse.onFailure(request, args.argi1, (String) args.arg2); |
| 97 | mConnectionId = null; |
| 98 | clearPendingInformation(); |
| 99 | } |
| 100 | } finally { |
| 101 | args.recycle(); |
| 102 | } |
| 103 | break; |
| 104 | } |
| 105 | case MSG_HANDLE_CREATE_CONNECTION_CANCELLED: { |
| 106 | ConnectionRequest request = (ConnectionRequest) msg.obj; |
| 107 | if (isPendingConnection(request.getCallId())) { |
| 108 | mPendingResponse.onCancel(request); |
| 109 | mConnectionId = null; |
| 110 | clearPendingInformation(); |
| 111 | } |
| 112 | break; |
| 113 | } |
| 114 | case MSG_SET_ACTIVE: |
| 115 | if (isCurrentConnection(msg.obj)) { |
| 116 | mConnection.setState(Connection.State.ACTIVE); |
| 117 | } |
| 118 | break; |
| 119 | case MSG_SET_RINGING: |
| 120 | if (isCurrentConnection(msg.obj)) { |
| 121 | mConnection.setState(Connection.State.RINGING); |
| 122 | } |
| 123 | break; |
| 124 | case MSG_SET_DIALING: |
| 125 | if (isCurrentConnection(msg.obj)) { |
| 126 | mConnection.setState(Connection.State.DIALING); |
| 127 | } |
| 128 | break; |
| 129 | case MSG_SET_DISCONNECTED: { |
| 130 | SomeArgs args = (SomeArgs) msg.obj; |
| 131 | try { |
| 132 | if (isCurrentConnection(args.arg1)) { |
| 133 | mConnection.setDisconnected(args.argi1, (String) args.arg2); |
| 134 | } |
| 135 | } finally { |
| 136 | args.recycle(); |
| 137 | } |
| 138 | break; |
| 139 | } |
| 140 | case MSG_SET_ON_HOLD: |
| 141 | if (isCurrentConnection(msg.obj)) { |
| 142 | mConnection.setState(Connection.State.HOLDING); |
| 143 | } |
| 144 | break; |
| 145 | case MSG_SET_REQUESTING_RINGBACK: |
| 146 | if (isCurrentConnection(msg.obj)) { |
| 147 | mConnection.setRequestingRingback(msg.arg1 == 1); |
| 148 | } |
| 149 | break; |
| 150 | case MSG_SET_CALL_CAPABILITIES: |
| 151 | if (isCurrentConnection(msg.obj)) { |
| 152 | mConnection.setCallCapabilities(msg.arg1); |
| 153 | } |
| 154 | break; |
| 155 | case MSG_SET_IS_CONFERENCED: |
| 156 | // not supported for remote connections. |
| 157 | break; |
| 158 | case MSG_ADD_CONFERENCE_CALL: |
| 159 | // not supported for remote connections. |
| 160 | break; |
| 161 | case MSG_REMOVE_CALL: |
| 162 | if (isCurrentConnection(msg.obj)) { |
| 163 | destroyConnection(); |
| 164 | } |
| 165 | break; |
| 166 | case MSG_ON_POST_DIAL_WAIT: { |
| 167 | SomeArgs args = (SomeArgs) msg.obj; |
| 168 | try { |
| 169 | if (isCurrentConnection(args.arg1)) { |
| 170 | mConnection.setPostDialWait((String) args.arg2); |
| 171 | } |
| 172 | } finally { |
| 173 | args.recycle(); |
| 174 | } |
| 175 | break; |
| 176 | } |
| 177 | case MSG_QUERY_REMOTE_CALL_SERVICES: |
| 178 | // Not supported from remote connection service. |
| 179 | break; |
| 180 | case MSG_SET_VIDEO_STATE: |
| 181 | if (isCurrentConnection(msg.obj)) { |
| 182 | mConnection.setVideoState(msg.arg1); |
| 183 | } |
| 184 | break; |
| 185 | case MSG_SET_CALL_VIDEO_PROVIDER: |
| 186 | // not supported for remote connections. |
| 187 | break; |
| 188 | case MSG_SET_AUDIO_MODE_IS_VOIP: |
| 189 | if (isCurrentConnection(msg.obj)) { |
| 190 | mConnection.setAudioModeIsVoip(msg.arg1 == 1); |
| 191 | } |
| 192 | break; |
| 193 | case MSG_SET_STATUS_HINTS: { |
| 194 | SomeArgs args = (SomeArgs) msg.obj; |
| 195 | try { |
| 196 | if (isCurrentConnection(args.arg1)) { |
| 197 | mConnection.setStatusHints((StatusHints) args.arg2); |
| 198 | } |
| 199 | } finally { |
| 200 | args.recycle(); |
| 201 | } |
| 202 | break; |
| 203 | } |
| 204 | case MSG_SET_HANDLE: { |
| 205 | SomeArgs args = (SomeArgs) msg.obj; |
| 206 | try { |
| 207 | if (isCurrentConnection(args.arg1)) { |
| 208 | mConnection.setHandle((Uri) args.arg2, args.argi1); |
| 209 | } |
| 210 | } finally { |
| 211 | args.recycle(); |
| 212 | } |
| 213 | break; |
| 214 | } |
| 215 | case MSG_SET_CALLER_DISPLAY_NAME: { |
| 216 | SomeArgs args = (SomeArgs) msg.obj; |
| 217 | try { |
| 218 | if (isCurrentConnection(msg.arg1)) { |
| 219 | mConnection.setCallerDisplayName((String) args.arg2, args.argi1); |
| 220 | } |
| 221 | } finally { |
| 222 | args.recycle(); |
| 223 | } |
| 224 | break; |
| 225 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame^] | 226 | case MSG_START_ACTIVITY_FROM_IN_CALL: { |
| 227 | SomeArgs args = (SomeArgs) msg.obj; |
| 228 | try { |
| 229 | if (isCurrentConnection(msg.arg1)) { |
| 230 | mConnection.startActivityFromInCall((PendingIntent) args.arg2); |
| 231 | } |
| 232 | } finally { |
| 233 | args.recycle(); |
| 234 | } |
| 235 | break; |
| 236 | } |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame^] | 239 | |
| 240 | |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 241 | }; |
| 242 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 243 | private final IConnectionServiceAdapter mAdapter = new IConnectionServiceAdapter.Stub() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 244 | @Override |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 245 | public void handleCreateConnectionSuccessful(ConnectionRequest request) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 246 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_SUCCESSFUL, request).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 249 | @Override |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 250 | public void handleCreateConnectionFailed( |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 251 | ConnectionRequest request, int errorCode, String errorMessage) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 252 | SomeArgs args = SomeArgs.obtain(); |
| 253 | args.arg1 = request; |
| 254 | args.argi1 = errorCode; |
| 255 | args.arg2 = errorMessage; |
| 256 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_FAILED, args).sendToTarget(); |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 259 | @Override |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 260 | public void handleCreateConnectionCancelled(ConnectionRequest request) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 261 | mHandler.obtainMessage(MSG_HANDLE_CREATE_CONNECTION_CANCELLED, request).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 264 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 265 | public void setActive(String connectionId) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 266 | mHandler.obtainMessage(MSG_SET_ACTIVE, connectionId).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 269 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 270 | public void setRinging(String connectionId) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 271 | mHandler.obtainMessage(MSG_SET_RINGING, connectionId).sendToTarget(); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 274 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 275 | public void setDialing(String connectionId) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 276 | mHandler.obtainMessage(MSG_SET_DIALING, connectionId).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 277 | } |
| 278 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 279 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 280 | public void setDisconnected( |
| 281 | String connectionId, int disconnectCause, String disconnectMessage) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 282 | SomeArgs args = SomeArgs.obtain(); |
| 283 | args.arg1 = connectionId; |
| 284 | args.arg2 = disconnectMessage; |
| 285 | args.argi1 = disconnectCause; |
| 286 | mHandler.obtainMessage(MSG_SET_DISCONNECTED, args).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 289 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 290 | public void setOnHold(String connectionId) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 291 | mHandler.obtainMessage(MSG_SET_ON_HOLD, connectionId).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 294 | @Override |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 295 | public void setRequestingRingback(String connectionId, boolean ringback) { |
| 296 | mHandler.obtainMessage(MSG_SET_REQUESTING_RINGBACK, ringback ? 1 : 0, 0, connectionId) |
| 297 | .sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 300 | @Override |
Sailesh Nepal | 1a7061b | 2014-07-09 21:03:20 -0700 | [diff] [blame] | 301 | public void setCallCapabilities(String connectionId, int callCapabilities) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 302 | mHandler.obtainMessage(MSG_SET_CALL_CAPABILITIES, callCapabilities, 0, connectionId) |
| 303 | .sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 306 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 307 | public void setIsConferenced(String connectionId, String conferenceConnectionId) { |
| 308 | // not supported for remote connections. |
| 309 | } |
| 310 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 311 | @Override |
| 312 | public void addConferenceCall(String connectionId) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 313 | // not supported for remote connections. |
| 314 | } |
| 315 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 316 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 317 | public void removeCall(String connectionId) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 318 | mHandler.obtainMessage(MSG_REMOVE_CALL, connectionId).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 321 | @Override |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 322 | public void onPostDialWait(String connectionId, String remainingDigits) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 323 | SomeArgs args = SomeArgs.obtain(); |
| 324 | args.arg1 = connectionId; |
| 325 | args.arg2 = remainingDigits; |
| 326 | mHandler.obtainMessage(MSG_ON_POST_DIAL_WAIT, args).sendToTarget(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 329 | @Override |
| 330 | public void queryRemoteConnectionServices(RemoteServiceCallback callback) { |
| 331 | try { |
| 332 | // Not supported from remote connection service. |
| 333 | callback.onError(); |
| 334 | } catch (RemoteException e) { |
| 335 | } |
| 336 | } |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 337 | |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 338 | @Override |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 339 | public void setVideoState(String connectionId, int videoState) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 340 | mHandler.obtainMessage(MSG_SET_VIDEO_STATE, videoState, 0, connectionId).sendToTarget(); |
| 341 | } |
| 342 | |
| 343 | @Override |
| 344 | public void setCallVideoProvider( |
| 345 | String connectionId, ICallVideoProvider callVideoProvider) { |
| 346 | // not supported for remote connections. |
Tyler Gunn | aa07df8 | 2014-07-17 07:50:22 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | @Override |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 350 | public final void setAudioModeIsVoip(String connectionId, boolean isVoip) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 351 | mHandler.obtainMessage(MSG_SET_AUDIO_MODE_IS_VOIP, isVoip ? 1 : 0, 0, |
| 352 | connectionId).sendToTarget(); |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 353 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 354 | |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 355 | @Override |
| 356 | public final void setStatusHints(String connectionId, StatusHints statusHints) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 357 | SomeArgs args = SomeArgs.obtain(); |
| 358 | args.arg1 = connectionId; |
| 359 | args.arg2 = statusHints; |
| 360 | mHandler.obtainMessage(MSG_SET_STATUS_HINTS, args).sendToTarget(); |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame] | 361 | } |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 362 | |
| 363 | @Override |
| 364 | public final void setHandle(String connectionId, Uri handle, int presentation) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 365 | SomeArgs args = SomeArgs.obtain(); |
| 366 | args.arg1 = connectionId; |
| 367 | args.arg2 = handle; |
| 368 | args.argi1 = presentation; |
| 369 | mHandler.obtainMessage(MSG_SET_HANDLE, args).sendToTarget(); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public final void setCallerDisplayName( |
| 374 | String connectionId, String callerDisplayName, int presentation) { |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 375 | SomeArgs args = SomeArgs.obtain(); |
| 376 | args.arg1 = connectionId; |
| 377 | args.arg2 = callerDisplayName; |
| 378 | args.argi1 = presentation; |
| 379 | mHandler.obtainMessage(MSG_SET_CALLER_DISPLAY_NAME, args).sendToTarget(); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 380 | } |
Sailesh Nepal | 2ab88cc | 2014-07-18 14:49:18 -0700 | [diff] [blame^] | 381 | |
| 382 | @Override |
| 383 | public final void startActivityFromInCall(String connectionId, PendingIntent intent) { |
| 384 | SomeArgs args = SomeArgs.obtain(); |
| 385 | args.arg1 = connectionId; |
| 386 | args.arg2 = intent; |
| 387 | mHandler.obtainMessage(MSG_START_ACTIVITY_FROM_IN_CALL, args).sendToTarget(); |
| 388 | } |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 389 | }; |
| 390 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 391 | RemoteConnectionService(ComponentName componentName, IConnectionService connectionService) |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 392 | throws RemoteException { |
| 393 | mComponentName = componentName; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 394 | mConnectionService = connectionService; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 395 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 396 | mConnectionService.addConnectionServiceAdapter(mAdapter); |
| 397 | mConnectionService.asBinder().linkToDeath(this, 0); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public String toString() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 402 | return "[RemoteCS - " + mConnectionService.asBinder().toString() + "]"; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /** ${inheritDoc} */ |
| 406 | @Override |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 407 | public final void binderDied() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 408 | if (mConnection != null) { |
| 409 | destroyConnection(); |
| 410 | } |
| 411 | |
| 412 | release(); |
| 413 | } |
| 414 | |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 415 | final void createRemoteConnection( |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 416 | ConnectionRequest request, |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 417 | ConnectionService.CreateConnectionResponse<RemoteConnection> response, |
| 418 | boolean isIncoming) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 419 | |
| 420 | if (mConnectionId == null) { |
| 421 | String id = UUID.randomUUID().toString(); |
Sailesh Nepal | 6120386 | 2014-07-11 14:50:13 -0700 | [diff] [blame] | 422 | ConnectionRequest newRequest = new ConnectionRequest( |
| 423 | request.getAccount(), |
| 424 | id, |
| 425 | request.getHandle(), |
| 426 | request.getHandlePresentation(), |
| 427 | request.getExtras(), |
| 428 | request.getVideoState()); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 429 | try { |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 430 | mConnectionService.createConnection(newRequest, isIncoming); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 431 | mConnectionId = id; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 432 | mPendingResponse = response; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 433 | mPendingRequest = request; |
| 434 | } catch (RemoteException e) { |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 435 | response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, e.toString()); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 436 | } |
| 437 | } else { |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 438 | response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, null); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 442 | final List<PhoneAccount> lookupAccounts(Uri handle) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 443 | // TODO(santoscordon): Update this so that is actually calls into the RemoteConnection |
| 444 | // each time. |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 445 | List<PhoneAccount> accounts = new LinkedList<>(); |
| 446 | accounts.add(new PhoneAccount( |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 447 | mComponentName, |
Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 448 | null /* id */)); |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 449 | return accounts; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Releases the resources associated with this Remote connection service. Should be called when |
| 454 | * the remote service is no longer being used. |
| 455 | */ |
| 456 | void release() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 457 | mConnectionService.asBinder().unlinkToDeath(this, 0); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | private boolean isPendingConnection(String id) { |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 461 | return TextUtils.equals(mConnectionId, id) && mPendingResponse != null; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Sailesh Nepal | 4803159 | 2014-07-18 14:21:23 -0700 | [diff] [blame] | 464 | private boolean isCurrentConnection(Object obj) { |
| 465 | return obj instanceof String && mConnection != null && |
| 466 | TextUtils.equals(mConnectionId, (String) obj); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | private void clearPendingInformation() { |
| 470 | mPendingRequest = null; |
Sailesh Nepal | c5b0157 | 2014-07-14 16:29:44 -0700 | [diff] [blame] | 471 | mPendingResponse = null; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | private void destroyConnection() { |
| 475 | mConnection.setDestroyed(); |
| 476 | mConnection = null; |
| 477 | mConnectionId = null; |
| 478 | } |
| 479 | } |