1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
|
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.telecom;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder.DeathRecipient;
import android.os.RemoteException;
import com.android.internal.telecom.IConnectionServiceAdapter;
import com.android.internal.telecom.RemoteServiceCallback;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
* Provides methods for IConnectionService implementations to interact with the system phone app.
*
* @hide
*/
final class ConnectionServiceAdapter implements DeathRecipient {
/**
* ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
* load factor before resizing, 1 means we only expect a single thread to
* access the map so make only a single shard
*/
private final Set<IConnectionServiceAdapter> mAdapters = Collections.newSetFromMap(
new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(8, 0.9f, 1));
ConnectionServiceAdapter() {
}
void addAdapter(IConnectionServiceAdapter adapter) {
for (IConnectionServiceAdapter it : mAdapters) {
if (it.asBinder() == adapter.asBinder()) {
Log.w(this, "Ignoring duplicate adapter addition.");
return;
}
}
if (mAdapters.add(adapter)) {
try {
adapter.asBinder().linkToDeath(this, 0);
} catch (RemoteException e) {
mAdapters.remove(adapter);
}
}
}
void removeAdapter(IConnectionServiceAdapter adapter) {
if (adapter != null) {
for (IConnectionServiceAdapter it : mAdapters) {
if (it.asBinder() == adapter.asBinder() && mAdapters.remove(it)) {
adapter.asBinder().unlinkToDeath(this, 0);
break;
}
}
}
}
/** ${inheritDoc} */
@Override
public void binderDied() {
Iterator<IConnectionServiceAdapter> it = mAdapters.iterator();
while (it.hasNext()) {
IConnectionServiceAdapter adapter = it.next();
if (!adapter.asBinder().isBinderAlive()) {
it.remove();
adapter.asBinder().unlinkToDeath(this, 0);
}
}
}
void handleCreateConnectionComplete(
String id,
ConnectionRequest request,
ParcelableConnection connection) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.handleCreateConnectionComplete(id, request, connection);
} catch (RemoteException e) {
}
}
}
/**
* Sets a call's state to active (e.g., an ongoing call where two parties can actively
* communicate).
*
* @param callId The unique ID of the call whose state is changing to active.
*/
void setActive(String callId) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setActive(callId);
} catch (RemoteException e) {
}
}
}
/**
* Sets a call's state to ringing (e.g., an inbound ringing call).
*
* @param callId The unique ID of the call whose state is changing to ringing.
*/
void setRinging(String callId) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setRinging(callId);
} catch (RemoteException e) {
}
}
}
/**
* Sets a call's state to dialing (e.g., dialing an outbound call).
*
* @param callId The unique ID of the call whose state is changing to dialing.
*/
void setDialing(String callId) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setDialing(callId);
} catch (RemoteException e) {
}
}
}
/**
* Sets a call's state to disconnected.
*
* @param callId The unique ID of the call whose state is changing to disconnected.
* @param disconnectCause The reason for the disconnection, as described by
* {@link android.telecomm.DisconnectCause}.
*/
void setDisconnected(String callId, DisconnectCause disconnectCause) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setDisconnected(callId, disconnectCause);
} catch (RemoteException e) {
}
}
}
/**
* Sets a call's state to be on hold.
*
* @param callId - The unique ID of the call whose state is changing to be on hold.
*/
void setOnHold(String callId) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setOnHold(callId);
} catch (RemoteException e) {
}
}
}
/**
* Asks Telecom to start or stop a ringback tone for a call.
*
* @param callId The unique ID of the call whose ringback is being changed.
* @param ringback Whether Telecom should start playing a ringback tone.
*/
void setRingbackRequested(String callId, boolean ringback) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setRingbackRequested(callId, ringback);
} catch (RemoteException e) {
}
}
}
void setConnectionCapabilities(String callId, int capabilities) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setConnectionCapabilities(callId, capabilities);
} catch (RemoteException ignored) {
}
}
}
/**
* Indicates whether or not the specified call is currently conferenced into the specified
* conference call.
*
* @param callId The unique ID of the call being conferenced.
* @param conferenceCallId The unique ID of the conference call. Null if call is not
* conferenced.
*/
void setIsConferenced(String callId, String conferenceCallId) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
Log.d(this, "sending connection %s with conference %s", callId, conferenceCallId);
adapter.setIsConferenced(callId, conferenceCallId);
} catch (RemoteException ignored) {
}
}
}
/**
* Indicates that the merge request on this call has failed.
*
* @param callId The unique ID of the call being conferenced.
*/
void onConferenceMergeFailed(String callId) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
Log.d(this, "merge failed for call %s", callId);
adapter.setConferenceMergeFailed(callId);
} catch (RemoteException ignored) {
}
}
}
/**
* Indicates that the call no longer exists. Can be used with either a call or a conference
* call.
*
* @param callId The unique ID of the call.
*/
void removeCall(String callId) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.removeCall(callId);
} catch (RemoteException ignored) {
}
}
}
void onPostDialWait(String callId, String remaining) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.onPostDialWait(callId, remaining);
} catch (RemoteException ignored) {
}
}
}
void onPostDialChar(String callId, char nextChar) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.onPostDialChar(callId, nextChar);
} catch (RemoteException ignored) {
}
}
}
/**
* Indicates that a new conference call has been created.
*
* @param callId The unique ID of the conference call.
*/
void addConferenceCall(String callId, ParcelableConference parcelableConference) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.addConferenceCall(callId, parcelableConference);
} catch (RemoteException ignored) {
}
}
}
/**
* Retrieves a list of remote connection services usable to place calls.
*/
void queryRemoteConnectionServices(RemoteServiceCallback callback) {
// Only supported when there is only one adapter.
if (mAdapters.size() == 1) {
try {
mAdapters.iterator().next().queryRemoteConnectionServices(callback);
} catch (RemoteException e) {
Log.e(this, e, "Exception trying to query for remote CSs");
}
}
}
/**
* Sets the call video provider for a call.
*
* @param callId The unique ID of the call to set with the given call video provider.
* @param videoProvider The call video provider instance to set on the call.
*/
void setVideoProvider(
String callId, Connection.VideoProvider videoProvider) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setVideoProvider(
callId,
videoProvider == null ? null : videoProvider.getInterface());
} catch (RemoteException e) {
}
}
}
/**
* Requests that the framework use VOIP audio mode for this connection.
*
* @param callId The unique ID of the call to set with the given call video provider.
* @param isVoip True if the audio mode is VOIP.
*/
void setIsVoipAudioMode(String callId, boolean isVoip) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setIsVoipAudioMode(callId, isVoip);
} catch (RemoteException e) {
}
}
}
void setStatusHints(String callId, StatusHints statusHints) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setStatusHints(callId, statusHints);
} catch (RemoteException e) {
}
}
}
void setAddress(String callId, Uri address, int presentation) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setAddress(callId, address, presentation);
} catch (RemoteException e) {
}
}
}
void setCallerDisplayName(String callId, String callerDisplayName, int presentation) {
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setCallerDisplayName(callId, callerDisplayName, presentation);
} catch (RemoteException e) {
}
}
}
/**
* Sets the video state associated with a call.
*
* Valid values: {@link VideoProfile#STATE_BIDIRECTIONAL},
* {@link VideoProfile#STATE_AUDIO_ONLY},
* {@link VideoProfile#STATE_TX_ENABLED},
* {@link VideoProfile#STATE_RX_ENABLED}.
*
* @param callId The unique ID of the call to set the video state for.
* @param videoState The video state.
*/
void setVideoState(String callId, int videoState) {
Log.v(this, "setVideoState: %d", videoState);
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setVideoState(callId, videoState);
} catch (RemoteException ignored) {
}
}
}
void setConferenceableConnections(String callId, List<String> conferenceableCallIds) {
Log.v(this, "setConferenceableConnections: %s, %s", callId, conferenceableCallIds);
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setConferenceableConnections(callId, conferenceableCallIds);
} catch (RemoteException ignored) {
}
}
}
/**
* Informs telecom of an existing connection which was added by the {@link ConnectionService}.
*
* @param callId The unique ID of the call being added.
* @param connection The connection.
*/
void addExistingConnection(String callId, ParcelableConnection connection) {
Log.v(this, "addExistingConnection: %s", callId);
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.addExistingConnection(callId, connection);
} catch (RemoteException ignored) {
}
}
}
/**
* Sets extras associated with a connection.
*
* @param callId The unique ID of the call.
* @param extras The extras to associate with this call.
*/
void setExtras(String callId, Bundle extras) {
Log.v(this, "setExtras: %s", extras);
for (IConnectionServiceAdapter adapter : mAdapters) {
try {
adapter.setExtras(callId, extras);
} catch (RemoteException ignored) {
}
}
}
}
|