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