Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -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 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.telecomm; |
| 18 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 19 | import android.app.Service; |
| 20 | import android.content.Intent; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 21 | import android.content.ComponentName; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 22 | import android.net.Uri; |
| 23 | import android.os.Bundle; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 24 | import android.os.Handler; |
| 25 | import android.os.IBinder; |
| 26 | import android.os.Looper; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 27 | import android.os.Message; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 28 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 29 | import com.android.internal.os.SomeArgs; |
| 30 | import com.android.internal.telecomm.IConnectionService; |
| 31 | import com.android.internal.telecomm.IConnectionServiceAdapter; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 32 | import com.android.internal.telecomm.RemoteServiceCallback; |
| 33 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 34 | import java.util.Collection; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 35 | import java.util.HashMap; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 36 | import java.util.List; |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 37 | import java.util.Map; |
| 38 | |
| 39 | /** |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 40 | * A {@link android.app.Service} that provides telephone connections to processes running on an |
| 41 | * Android device. |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 42 | */ |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 43 | public abstract class ConnectionService extends Service { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 44 | // Flag controlling whether PII is emitted into the logs |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 45 | private static final boolean PII_DEBUG = Log.isLoggable(android.util.Log.DEBUG); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 46 | private static final Connection NULL_CONNECTION = new Connection() {}; |
| 47 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 48 | private static final int MSG_ADD_CALL_SERVICE_ADAPTER = 1; |
| 49 | private static final int MSG_CALL = 2; |
| 50 | private static final int MSG_ABORT = 3; |
| 51 | private static final int MSG_CREATE_INCOMING_CALL = 4; |
| 52 | private static final int MSG_ANSWER = 5; |
| 53 | private static final int MSG_REJECT = 6; |
| 54 | private static final int MSG_DISCONNECT = 7; |
| 55 | private static final int MSG_HOLD = 8; |
| 56 | private static final int MSG_UNHOLD = 9; |
| 57 | private static final int MSG_ON_AUDIO_STATE_CHANGED = 10; |
| 58 | private static final int MSG_PLAY_DTMF_TONE = 11; |
| 59 | private static final int MSG_STOP_DTMF_TONE = 12; |
| 60 | private static final int MSG_CONFERENCE = 13; |
| 61 | private static final int MSG_SPLIT_FROM_CONFERENCE = 14; |
| 62 | private static final int MSG_ON_POST_DIAL_CONTINUE = 15; |
| 63 | private static final int MSG_ON_PHONE_ACCOUNT_CLICKED = 16; |
| 64 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 65 | private final Map<String, Connection> mConnectionById = new HashMap<>(); |
| 66 | private final Map<Connection, String> mIdByConnection = new HashMap<>(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 67 | private final RemoteConnectionManager mRemoteConnectionManager = new RemoteConnectionManager(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 68 | |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 69 | private SimpleResponse<Uri, List<PhoneAccount>> mAccountLookupResponse; |
| 70 | private Uri mAccountLookupHandle; |
| 71 | private boolean mAreAccountsInitialized = false; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 72 | private final ConnectionServiceAdapter mAdapter = new ConnectionServiceAdapter(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 73 | |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 74 | /** |
| 75 | * A callback for providing the resuilt of creating a connection. |
| 76 | */ |
| 77 | public interface OutgoingCallResponse<CONNECTION> { |
| 78 | /** |
| 79 | * Tells Telecomm that an attempt to place the specified outgoing call succeeded. |
| 80 | * |
| 81 | * @param request The original request. |
| 82 | * @param connection The connection. |
| 83 | */ |
| 84 | void onSuccess(ConnectionRequest request, CONNECTION connection); |
| 85 | |
| 86 | /** |
| 87 | * Tells Telecomm that an attempt to place the specified outgoing call failed. |
| 88 | * |
| 89 | * @param request The original request. |
| 90 | * @param code An integer code indicating the reason for failure. |
| 91 | * @param msg A message explaining the reason for failure. |
| 92 | */ |
| 93 | void onFailure(ConnectionRequest request, int code, String msg); |
| 94 | |
| 95 | /** |
| 96 | * Tells Telecomm to cancel the call. |
| 97 | * |
| 98 | * @param request The original request. |
| 99 | */ |
| 100 | void onCancel(ConnectionRequest request); |
| 101 | } |
| 102 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 103 | private final IBinder mBinder = new IConnectionService.Stub() { |
| 104 | @Override |
| 105 | public void addConnectionServiceAdapter(IConnectionServiceAdapter adapter) { |
| 106 | mHandler.obtainMessage(MSG_ADD_CALL_SERVICE_ADAPTER, adapter).sendToTarget(); |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void call(ConnectionRequest request) { |
| 111 | mHandler.obtainMessage(MSG_CALL, request).sendToTarget(); |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void abort(String callId) { |
| 116 | mHandler.obtainMessage(MSG_ABORT, callId).sendToTarget(); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void createIncomingCall(ConnectionRequest request) { |
| 121 | mHandler.obtainMessage(MSG_CREATE_INCOMING_CALL, request).sendToTarget(); |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public void answer(String callId) { |
| 126 | mHandler.obtainMessage(MSG_ANSWER, callId).sendToTarget(); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void reject(String callId) { |
| 131 | mHandler.obtainMessage(MSG_REJECT, callId).sendToTarget(); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void disconnect(String callId) { |
| 136 | mHandler.obtainMessage(MSG_DISCONNECT, callId).sendToTarget(); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public void hold(String callId) { |
| 141 | mHandler.obtainMessage(MSG_HOLD, callId).sendToTarget(); |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public void unhold(String callId) { |
| 146 | mHandler.obtainMessage(MSG_UNHOLD, callId).sendToTarget(); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void onAudioStateChanged(String callId, CallAudioState audioState) { |
| 151 | SomeArgs args = SomeArgs.obtain(); |
| 152 | args.arg1 = callId; |
| 153 | args.arg2 = audioState; |
| 154 | mHandler.obtainMessage(MSG_ON_AUDIO_STATE_CHANGED, args).sendToTarget(); |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public void playDtmfTone(String callId, char digit) { |
| 159 | mHandler.obtainMessage(MSG_PLAY_DTMF_TONE, digit, 0, callId).sendToTarget(); |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public void stopDtmfTone(String callId) { |
| 164 | mHandler.obtainMessage(MSG_STOP_DTMF_TONE, callId).sendToTarget(); |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public void conference(String conferenceCallId, String callId) { |
| 169 | SomeArgs args = SomeArgs.obtain(); |
| 170 | args.arg1 = conferenceCallId; |
| 171 | args.arg2 = callId; |
| 172 | mHandler.obtainMessage(MSG_CONFERENCE, args).sendToTarget(); |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void splitFromConference(String callId) { |
| 177 | mHandler.obtainMessage(MSG_SPLIT_FROM_CONFERENCE, callId).sendToTarget(); |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public void onPostDialContinue(String callId, boolean proceed) { |
| 182 | SomeArgs args = SomeArgs.obtain(); |
| 183 | args.arg1 = callId; |
| 184 | args.argi1 = proceed ? 1 : 0; |
| 185 | mHandler.obtainMessage(MSG_ON_POST_DIAL_CONTINUE, args).sendToTarget(); |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public void onPhoneAccountClicked(String callId) { |
| 190 | mHandler.obtainMessage(MSG_ON_PHONE_ACCOUNT_CLICKED, callId).sendToTarget(); |
| 191 | } |
| 192 | }; |
| 193 | |
| 194 | private final Handler mHandler = new Handler(Looper.getMainLooper()) { |
| 195 | @Override |
| 196 | public void handleMessage(Message msg) { |
| 197 | switch (msg.what) { |
| 198 | case MSG_ADD_CALL_SERVICE_ADAPTER: |
| 199 | mAdapter.addAdapter((IConnectionServiceAdapter) msg.obj); |
| 200 | onAdapterAttached(); |
| 201 | break; |
| 202 | case MSG_CALL: |
| 203 | call((ConnectionRequest) msg.obj); |
| 204 | break; |
| 205 | case MSG_ABORT: |
| 206 | abort((String) msg.obj); |
| 207 | break; |
| 208 | case MSG_CREATE_INCOMING_CALL: |
| 209 | createIncomingCall((ConnectionRequest) msg.obj); |
| 210 | break; |
| 211 | case MSG_ANSWER: |
| 212 | answer((String) msg.obj); |
| 213 | break; |
| 214 | case MSG_REJECT: |
| 215 | reject((String) msg.obj); |
| 216 | break; |
| 217 | case MSG_DISCONNECT: |
| 218 | disconnect((String) msg.obj); |
| 219 | break; |
| 220 | case MSG_HOLD: |
| 221 | hold((String) msg.obj); |
| 222 | break; |
| 223 | case MSG_UNHOLD: |
| 224 | unhold((String) msg.obj); |
| 225 | break; |
| 226 | case MSG_ON_AUDIO_STATE_CHANGED: { |
| 227 | SomeArgs args = (SomeArgs) msg.obj; |
| 228 | try { |
| 229 | String callId = (String) args.arg1; |
| 230 | CallAudioState audioState = (CallAudioState) args.arg2; |
| 231 | onAudioStateChanged(callId, audioState); |
| 232 | } finally { |
| 233 | args.recycle(); |
| 234 | } |
| 235 | break; |
| 236 | } |
| 237 | case MSG_PLAY_DTMF_TONE: |
| 238 | playDtmfTone((String) msg.obj, (char) msg.arg1); |
| 239 | break; |
| 240 | case MSG_STOP_DTMF_TONE: |
| 241 | stopDtmfTone((String) msg.obj); |
| 242 | break; |
| 243 | case MSG_CONFERENCE: { |
| 244 | SomeArgs args = (SomeArgs) msg.obj; |
| 245 | try { |
| 246 | String conferenceCallId = (String) args.arg1; |
| 247 | String callId = (String) args.arg2; |
| 248 | conference(conferenceCallId, callId); |
| 249 | } finally { |
| 250 | args.recycle(); |
| 251 | } |
| 252 | break; |
| 253 | } |
| 254 | case MSG_SPLIT_FROM_CONFERENCE: |
| 255 | splitFromConference((String) msg.obj); |
| 256 | break; |
| 257 | case MSG_ON_POST_DIAL_CONTINUE: { |
| 258 | SomeArgs args = (SomeArgs) msg.obj; |
| 259 | try { |
| 260 | String callId = (String) args.arg1; |
| 261 | boolean proceed = (args.argi1 == 1); |
| 262 | onPostDialContinue(callId, proceed); |
| 263 | } finally { |
| 264 | args.recycle(); |
| 265 | } |
| 266 | break; |
| 267 | } |
| 268 | case MSG_ON_PHONE_ACCOUNT_CLICKED: |
| 269 | onPhoneAccountClicked((String) msg.obj); |
| 270 | break; |
| 271 | default: |
| 272 | break; |
| 273 | } |
| 274 | } |
| 275 | }; |
| 276 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 277 | private final Connection.Listener mConnectionListener = new Connection.Listener() { |
| 278 | @Override |
| 279 | public void onStateChanged(Connection c, int state) { |
| 280 | String id = mIdByConnection.get(c); |
Ihab Awad | 42b30e1 | 2014-05-22 09:49:34 -0700 | [diff] [blame] | 281 | Log.d(this, "Adapter set state %s %s", id, Connection.stateToString(state)); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 282 | switch (state) { |
| 283 | case Connection.State.ACTIVE: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 284 | mAdapter.setActive(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 285 | break; |
| 286 | case Connection.State.DIALING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 287 | mAdapter.setDialing(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 288 | break; |
| 289 | case Connection.State.DISCONNECTED: |
| 290 | // Handled in onDisconnected() |
| 291 | break; |
| 292 | case Connection.State.HOLDING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 293 | mAdapter.setOnHold(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 294 | break; |
| 295 | case Connection.State.NEW: |
| 296 | // Nothing to tell Telecomm |
| 297 | break; |
| 298 | case Connection.State.RINGING: |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 299 | mAdapter.setRinging(id); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 300 | break; |
| 301 | } |
| 302 | } |
| 303 | |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 304 | /** {@inheritDoc} */ |
| 305 | @Override |
| 306 | public void onFeaturesChanged(Connection c, int features) { |
| 307 | String id = mIdByConnection.get(c); |
| 308 | Log.d(this, "Adapter set features %d", features); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 309 | mAdapter.setFeatures(id, features); |
Tyler Gunn | 8d83fa9 | 2014-07-01 11:31:21 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 312 | @Override |
| 313 | public void onDisconnected(Connection c, int cause, String message) { |
| 314 | String id = mIdByConnection.get(c); |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 315 | Log.d(this, "Adapter set disconnected %d %s", cause, message); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 316 | mAdapter.setDisconnected(id, cause, message); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | @Override |
| 320 | public void onHandleChanged(Connection c, Uri newHandle) { |
| 321 | // TODO: Unsupported yet |
| 322 | } |
| 323 | |
| 324 | @Override |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 325 | public void onSignalChanged(Connection c, Bundle details) { |
| 326 | // TODO: Unsupported yet |
| 327 | } |
| 328 | |
| 329 | @Override |
| 330 | public void onDestroyed(Connection c) { |
| 331 | removeConnection(c); |
| 332 | } |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 333 | |
| 334 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 335 | public void onPostDialWait(Connection c, String remaining) { |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 336 | String id = mIdByConnection.get(c); |
| 337 | Log.d(this, "Adapter onPostDialWait %s, %s", c, remaining); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 338 | mAdapter.onPostDialWait(id, remaining); |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | @Override |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 342 | public void onRequestingRingback(Connection c, boolean ringback) { |
| 343 | String id = mIdByConnection.get(c); |
| 344 | Log.d(this, "Adapter onRingback %b", ringback); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 345 | mAdapter.setRequestingRingback(id, ringback); |
Ihab Awad | f835897 | 2014-05-28 16:46:42 -0700 | [diff] [blame] | 346 | } |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 347 | |
| 348 | @Override |
| 349 | public void onConferenceCapableChanged(Connection c, boolean isConferenceCapable) { |
| 350 | String id = mIdByConnection.get(c); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 351 | mAdapter.setCanConference(id, isConferenceCapable); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | /** ${inheritDoc} */ |
| 355 | @Override |
| 356 | public void onParentConnectionChanged(Connection c, Connection parent) { |
| 357 | String id = mIdByConnection.get(c); |
| 358 | String parentId = parent == null ? null : mIdByConnection.get(parent); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 359 | mAdapter.setIsConferenced(id, parentId); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 360 | } |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 361 | |
| 362 | @Override |
| 363 | public void onSetCallVideoProvider(Connection c, CallVideoProvider callVideoProvider) { |
| 364 | String id = mIdByConnection.get(c); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 365 | mAdapter.setCallVideoProvider(id, callVideoProvider); |
Andrew Lee | 5ffbe8b | 2014-06-20 16:29:33 -0700 | [diff] [blame] | 366 | } |
Sailesh Nepal | 33aaae4 | 2014-07-07 22:49:44 -0700 | [diff] [blame] | 367 | |
| 368 | @Override |
| 369 | public void onSetAudioModeIsVoip(Connection c, boolean isVoip) { |
| 370 | String id = mIdByConnection.get(c); |
| 371 | mAdapter.setAudioModeIsVoip(id, isVoip); |
| 372 | } |
Sailesh Nepal | e7ef59a | 2014-07-08 21:48:22 -0700 | [diff] [blame^] | 373 | |
| 374 | @Override |
| 375 | public void onSetStatusHints(Connection c, StatusHints statusHints) { |
| 376 | String id = mIdByConnection.get(c); |
| 377 | mAdapter.setStatusHints(id, statusHints); |
| 378 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 379 | }; |
| 380 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 381 | /** {@inheritDoc} */ |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 382 | @Override |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 383 | public final IBinder onBind(Intent intent) { |
| 384 | return mBinder; |
| 385 | } |
| 386 | |
| 387 | private void call(final ConnectionRequest originalRequest) { |
| 388 | Log.d(this, "call %s", originalRequest); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 389 | onCreateConnections( |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 390 | originalRequest, |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 391 | new OutgoingCallResponse<Connection>() { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 392 | @Override |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 393 | public void onSuccess(ConnectionRequest request, Connection connection) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 394 | Log.d(this, "adapter handleSuccessfulOutgoingCall %s", request.getCallId()); |
| 395 | mAdapter.handleSuccessfulOutgoingCall(request); |
| 396 | addConnection(request.getCallId(), connection); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | @Override |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 400 | public void onFailure(ConnectionRequest request, int code, String msg) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 401 | mAdapter.handleFailedOutgoingCall(request, code, msg); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 402 | } |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 403 | |
| 404 | @Override |
| 405 | public void onCancel(ConnectionRequest request) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 406 | mAdapter.cancelOutgoingCall(request); |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 407 | } |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 408 | } |
| 409 | ); |
| 410 | } |
| 411 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 412 | private void abort(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 413 | Log.d(this, "abort %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 414 | findConnectionForAction(callId, "abort").onAbort(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 417 | private void createIncomingCall(ConnectionRequest originalRequest) { |
| 418 | Log.d(this, "createIncomingCall %s", originalRequest); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 419 | onCreateIncomingConnection( |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 420 | originalRequest, |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 421 | new Response<ConnectionRequest, Connection>() { |
| 422 | @Override |
| 423 | public void onResult(ConnectionRequest request, Connection... result) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 424 | if (result != null && result.length != 1) { |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 425 | for (Connection c : result) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 426 | c.onAbort(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 427 | } |
| 428 | } else { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 429 | addConnection(request.getCallId(), result[0]); |
| 430 | Log.d(this, "adapter notifyIncomingCall %s", request); |
| 431 | mAdapter.notifyIncomingCall(request); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | |
| 435 | @Override |
Ihab Awad | fc91b7d | 2014-06-03 18:40:45 -0700 | [diff] [blame] | 436 | public void onError(ConnectionRequest request, int code, String msg) { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 437 | Log.d(this, "adapter failed createIncomingCall %s %d %s", |
Ihab Awad | fc91b7d | 2014-06-03 18:40:45 -0700 | [diff] [blame] | 438 | request, code, msg); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | ); |
| 442 | } |
| 443 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 444 | private void answer(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 445 | Log.d(this, "answer %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 446 | findConnectionForAction(callId, "answer").onAnswer(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 449 | private void reject(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 450 | Log.d(this, "reject %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 451 | findConnectionForAction(callId, "reject").onReject(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 454 | private void disconnect(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 455 | Log.d(this, "disconnect %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 456 | findConnectionForAction(callId, "disconnect").onDisconnect(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 459 | private void hold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 460 | Log.d(this, "hold %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 461 | findConnectionForAction(callId, "hold").onHold(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 464 | private void unhold(String callId) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 465 | Log.d(this, "unhold %s", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 466 | findConnectionForAction(callId, "unhold").onUnhold(); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 469 | private void onAudioStateChanged(String callId, CallAudioState audioState) { |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 470 | Log.d(this, "onAudioStateChanged %s %s", callId, audioState); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 471 | findConnectionForAction(callId, "onAudioStateChanged").setAudioState(audioState); |
| 472 | } |
| 473 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 474 | private void playDtmfTone(String callId, char digit) { |
| 475 | Log.d(this, "playDtmfTone %s %c", callId, digit); |
| 476 | findConnectionForAction(callId, "playDtmfTone").onPlayDtmfTone(digit); |
| 477 | } |
| 478 | |
| 479 | private void stopDtmfTone(String callId) { |
| 480 | Log.d(this, "stopDtmfTone %s", callId); |
| 481 | findConnectionForAction(callId, "stopDtmfTone").onStopDtmfTone(); |
| 482 | } |
| 483 | |
| 484 | private void conference(final String conferenceCallId, String callId) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 485 | Log.d(this, "conference %s, %s", conferenceCallId, callId); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 486 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 487 | Connection connection = findConnectionForAction(callId, "conference"); |
| 488 | if (connection == NULL_CONNECTION) { |
| 489 | Log.w(this, "Connection missing in conference request %s.", callId); |
| 490 | return; |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 493 | onCreateConferenceConnection(conferenceCallId, connection, |
| 494 | new Response<String, Connection>() { |
| 495 | /** ${inheritDoc} */ |
| 496 | @Override |
| 497 | public void onResult(String ignored, Connection... result) { |
| 498 | Log.d(this, "onCreateConference.Response %s", (Object[]) result); |
| 499 | if (result != null && result.length == 1) { |
| 500 | Connection conferenceConnection = result[0]; |
| 501 | if (!mIdByConnection.containsKey(conferenceConnection)) { |
| 502 | Log.v(this, "sending new conference call %s", conferenceCallId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 503 | mAdapter.addConferenceCall(conferenceCallId); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 504 | addConnection(conferenceCallId, conferenceConnection); |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | /** ${inheritDoc} */ |
| 510 | @Override |
| 511 | public void onError(String request, int code, String reason) { |
| 512 | // no-op |
| 513 | } |
| 514 | }); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 517 | private void splitFromConference(String callId) { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 518 | Log.d(this, "splitFromConference(%s)", callId); |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 519 | |
| 520 | Connection connection = findConnectionForAction(callId, "splitFromConference"); |
| 521 | if (connection == NULL_CONNECTION) { |
| 522 | Log.w(this, "Connection missing in conference request %s.", callId); |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | // TODO(santoscordon): Find existing conference call and invoke split(connection). |
| 527 | } |
| 528 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 529 | private void onPostDialContinue(String callId, boolean proceed) { |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 530 | Log.d(this, "onPostDialContinue(%s)", callId); |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 531 | findConnectionForAction(callId, "stopDtmfTone").onPostDialContinue(proceed); |
Evan Charlton | 6dea4ac | 2014-06-03 14:07:13 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 534 | private void onPhoneAccountClicked(String callId) { |
Sailesh Nepal | 2bed956 | 2014-07-02 21:26:12 -0700 | [diff] [blame] | 535 | Log.d(this, "onPhoneAccountClicked %s", callId); |
| 536 | findConnectionForAction(callId, "onPhoneAccountClicked").onPhoneAccountClicked(); |
| 537 | } |
| 538 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 539 | private void onAdapterAttached() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 540 | if (mAreAccountsInitialized) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 541 | // No need to query again if we already did it. |
| 542 | return; |
| 543 | } |
| 544 | |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 545 | mAdapter.queryRemoteConnectionServices(new RemoteServiceCallback.Stub() { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 546 | @Override |
| 547 | public void onResult( |
| 548 | final List<ComponentName> componentNames, |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 549 | final List<IBinder> services) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 550 | mHandler.post(new Runnable() { |
| 551 | @Override public void run() { |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 552 | for (int i = 0; i < componentNames.size() && i < services.size(); i++) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 553 | mRemoteConnectionManager.addConnectionService( |
| 554 | componentNames.get(i), |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 555 | IConnectionService.Stub.asInterface(services.get(i))); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 556 | } |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 557 | mAreAccountsInitialized = true; |
Sailesh Nepal | 2a46b90 | 2014-07-04 17:21:07 -0700 | [diff] [blame] | 558 | Log.d(this, "remote call services found: " + services); |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 559 | maybeRespondToAccountLookup(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 560 | } |
| 561 | }); |
| 562 | } |
| 563 | |
| 564 | @Override |
| 565 | public void onError() { |
| 566 | mHandler.post(new Runnable() { |
| 567 | @Override public void run() { |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 568 | mAreAccountsInitialized = true; |
| 569 | maybeRespondToAccountLookup(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 570 | } |
| 571 | }); |
| 572 | } |
| 573 | }); |
| 574 | } |
| 575 | |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 576 | public final void lookupRemoteAccounts( |
| 577 | Uri handle, SimpleResponse<Uri, List<PhoneAccount>> response) { |
| 578 | mAccountLookupResponse = response; |
| 579 | mAccountLookupHandle = handle; |
| 580 | maybeRespondToAccountLookup(); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 583 | public final void maybeRespondToAccountLookup() { |
| 584 | if (mAreAccountsInitialized && mAccountLookupResponse != null) { |
| 585 | mAccountLookupResponse.onResult( |
| 586 | mAccountLookupHandle, |
| 587 | mRemoteConnectionManager.getAccounts(mAccountLookupHandle)); |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 588 | |
Ihab Awad | 9c3f188 | 2014-06-30 21:17:13 -0700 | [diff] [blame] | 589 | mAccountLookupHandle = null; |
| 590 | mAccountLookupResponse = null; |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 594 | public final void createRemoteOutgoingConnection( |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 595 | ConnectionRequest request, |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 596 | OutgoingCallResponse<RemoteConnection> response) { |
Santos Cordon | 52d8a15 | 2014-06-17 19:08:45 -0700 | [diff] [blame] | 597 | mRemoteConnectionManager.createOutgoingConnection(request, response); |
| 598 | } |
| 599 | |
| 600 | /** |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 601 | * Returns all connections currently associated with this connection service. |
| 602 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 603 | public final Collection<Connection> getAllConnections() { |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 604 | return mConnectionById.values(); |
| 605 | } |
| 606 | |
| 607 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 608 | * Create a Connection given a request. |
| 609 | * |
| 610 | * @param request Data encapsulating details of the desired Connection. |
| 611 | * @param callback A callback for providing the result. |
| 612 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 613 | protected void onCreateConnections( |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 614 | ConnectionRequest request, |
Sailesh Nepal | 506e386 | 2014-06-25 13:35:14 -0700 | [diff] [blame] | 615 | OutgoingCallResponse<Connection> callback) {} |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 616 | |
| 617 | /** |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 618 | * Returns a new or existing conference connection when the the user elects to convert the |
| 619 | * specified connection into a conference call. The specified connection can be any connection |
| 620 | * which had previously specified itself as conference-capable including both simple connections |
| 621 | * and connections previously returned from this method. |
| 622 | * |
| 623 | * @param connection The connection from which the user opted to start a conference call. |
| 624 | * @param token The token to be passed into the response callback. |
| 625 | * @param callback The callback for providing the potentially-new conference connection. |
| 626 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 627 | protected void onCreateConferenceConnection( |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 628 | String token, |
| 629 | Connection connection, |
| 630 | Response<String, Connection> callback) {} |
| 631 | |
| 632 | /** |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 633 | * Create a Connection to match an incoming connection notification. |
| 634 | * |
Ihab Awad | c067754 | 2014-06-10 13:29:47 -0700 | [diff] [blame] | 635 | * IMPORTANT: If the incoming connection has a phone number (or other handle) that the user |
| 636 | * is not supposed to be able to see (e.g. it is PRESENTATION_RESTRICTED), then a compliant |
| 637 | * ConnectionService implementation MUST NOT reveal this phone number as part of the Intent |
| 638 | * it sends to notify Telecomm of an incoming connection. |
| 639 | * |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 640 | * @param request Data encapsulating details of the desired Connection. |
| 641 | * @param callback A callback for providing the result. |
| 642 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 643 | protected void onCreateIncomingConnection( |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 644 | ConnectionRequest request, |
| 645 | Response<ConnectionRequest, Connection> callback) {} |
| 646 | |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 647 | /** |
| 648 | * Notifies that a connection has been added to this connection service and sent to Telecomm. |
| 649 | * |
| 650 | * @param connection The connection which was added. |
| 651 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 652 | protected void onConnectionAdded(Connection connection) {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 653 | |
| 654 | /** |
| 655 | * Notified that a connection has been removed from this connection service. |
| 656 | * |
| 657 | * @param connection The connection which was removed. |
| 658 | */ |
Sailesh Nepal | 091768c | 2014-06-30 15:15:23 -0700 | [diff] [blame] | 659 | protected void onConnectionRemoved(Connection connection) {} |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 660 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 661 | static String toLogSafePhoneNumber(String number) { |
| 662 | // For unknown number, log empty string. |
| 663 | if (number == null) { |
| 664 | return ""; |
| 665 | } |
| 666 | |
| 667 | if (PII_DEBUG) { |
| 668 | // When PII_DEBUG is true we emit PII. |
| 669 | return number; |
| 670 | } |
| 671 | |
| 672 | // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare |
| 673 | // sanitized phone numbers. |
| 674 | StringBuilder builder = new StringBuilder(); |
| 675 | for (int i = 0; i < number.length(); i++) { |
| 676 | char c = number.charAt(i); |
| 677 | if (c == '-' || c == '@' || c == '.') { |
| 678 | builder.append(c); |
| 679 | } else { |
| 680 | builder.append('x'); |
| 681 | } |
| 682 | } |
| 683 | return builder.toString(); |
| 684 | } |
| 685 | |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 686 | private void addConnection(String callId, Connection connection) { |
| 687 | mConnectionById.put(callId, connection); |
| 688 | mIdByConnection.put(connection, callId); |
| 689 | connection.addConnectionListener(mConnectionListener); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 690 | onConnectionAdded(connection); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | private void removeConnection(Connection connection) { |
| 694 | connection.removeConnectionListener(mConnectionListener); |
| 695 | mConnectionById.remove(mIdByConnection.get(connection)); |
| 696 | mIdByConnection.remove(connection); |
Santos Cordon | b693998 | 2014-06-04 20:20:58 -0700 | [diff] [blame] | 697 | onConnectionRemoved(connection); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | private Connection findConnectionForAction(String callId, String action) { |
| 701 | if (mConnectionById.containsKey(callId)) { |
| 702 | return mConnectionById.get(callId); |
| 703 | } |
Ihab Awad | 60ac30b | 2014-05-20 22:32:12 -0700 | [diff] [blame] | 704 | Log.w(this, "%s - Cannot find Connection %s", action, callId); |
Ihab Awad | 542e0ea | 2014-05-16 10:22:16 -0700 | [diff] [blame] | 705 | return NULL_CONNECTION; |
| 706 | } |
Santos Cordon | 980acb9 | 2014-05-31 10:31:19 -0700 | [diff] [blame] | 707 | } |