| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.telecom; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SuppressLint; |
| 22 |
import android.annotation.SystemApi; |
| 23 |
import android.annotation.TestApi; |
| 24 |
import android.net.Uri; |
| 25 |
import android.os.Bundle; |
| 26 |
import android.os.Parcel; |
| 27 |
import android.os.ParcelFileDescriptor; |
| 28 |
import android.os.Parcelable; |
| 29 |
|
| 30 |
import java.util.ArrayList; |
| 31 |
import java.util.List; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class ConnectionRequest implements Parcelable { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
@TestApi |
| 44 |
public static final class Builder { |
| 45 |
private PhoneAccountHandle mAccountHandle; |
| 46 |
private Uri mAddress; |
| 47 |
private Bundle mExtras; |
| 48 |
private int mVideoState = VideoProfile.STATE_AUDIO_ONLY; |
| 49 |
private String mTelecomCallId; |
| 50 |
private boolean mShouldShowIncomingCallUi = false; |
| 51 |
private ParcelFileDescriptor mRttPipeToInCall; |
| 52 |
private ParcelFileDescriptor mRttPipeFromInCall; |
| 53 |
private List<Uri> mParticipants; |
| 54 |
private boolean mIsAdhocConference = false; |
| 55 |
|
| 56 |
public Builder() { } |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public @NonNull Builder setAccountHandle(@NonNull PhoneAccountHandle accountHandle) { |
| 63 |
this.mAccountHandle = accountHandle; |
| 64 |
return this; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public @NonNull Builder setParticipants( |
| 72 |
@SuppressLint("NullableCollection") @Nullable List<Uri> participants) { |
| 73 |
this.mParticipants = participants; |
| 74 |
return this; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public @NonNull Builder setAddress(@NonNull Uri address) { |
| 83 |
this.mAddress = address; |
| 84 |
return this; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public @NonNull Builder setExtras(@NonNull Bundle extras) { |
| 92 |
this.mExtras = extras; |
| 93 |
return this; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public @NonNull Builder setVideoState(int videoState) { |
| 101 |
this.mVideoState = videoState; |
| 102 |
return this; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
public @NonNull Builder setTelecomCallId(@NonNull String telecomCallId) { |
| 110 |
this.mTelecomCallId = telecomCallId; |
| 111 |
return this; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public @NonNull Builder setShouldShowIncomingCallUi(boolean shouldShowIncomingCallUi) { |
| 122 |
this.mShouldShowIncomingCallUi = shouldShowIncomingCallUi; |
| 123 |
return this; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
public @NonNull Builder setIsAdhocConferenceCall(boolean isAdhocConference) { |
| 132 |
this.mIsAdhocConference = isAdhocConference; |
| 133 |
return this; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
public @NonNull Builder setRttPipeFromInCall( |
| 142 |
@NonNull ParcelFileDescriptor rttPipeFromInCall) { |
| 143 |
this.mRttPipeFromInCall = rttPipeFromInCall; |
| 144 |
return this; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public @NonNull Builder setRttPipeToInCall(@NonNull ParcelFileDescriptor rttPipeToInCall) { |
| 153 |
this.mRttPipeToInCall = rttPipeToInCall; |
| 154 |
return this; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
public @NonNull ConnectionRequest build() { |
| 162 |
return new ConnectionRequest( |
| 163 |
mAccountHandle, |
| 164 |
mAddress, |
| 165 |
mExtras, |
| 166 |
mVideoState, |
| 167 |
mTelecomCallId, |
| 168 |
mShouldShowIncomingCallUi, |
| 169 |
mRttPipeFromInCall, |
| 170 |
mRttPipeToInCall, |
| 171 |
mParticipants, |
| 172 |
mIsAdhocConference); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
private final PhoneAccountHandle mAccountHandle; |
| 177 |
private final Uri mAddress; |
| 178 |
private final Bundle mExtras; |
| 179 |
private final int mVideoState; |
| 180 |
private final String mTelecomCallId; |
| 181 |
private final boolean mShouldShowIncomingCallUi; |
| 182 |
private final ParcelFileDescriptor mRttPipeToInCall; |
| 183 |
private final ParcelFileDescriptor mRttPipeFromInCall; |
| 184 |
|
| 185 |
private Connection.RttTextStream mRttTextStream; |
| 186 |
private List<Uri> mParticipants; |
| 187 |
private final boolean mIsAdhocConference; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public ConnectionRequest( |
| 195 |
PhoneAccountHandle accountHandle, |
| 196 |
Uri handle, |
| 197 |
Bundle extras) { |
| 198 |
this(accountHandle, handle, extras, VideoProfile.STATE_AUDIO_ONLY, null, false, null, null); |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
public ConnectionRequest( |
| 208 |
PhoneAccountHandle accountHandle, |
| 209 |
Uri handle, |
| 210 |
Bundle extras, |
| 211 |
int videoState) { |
| 212 |
this(accountHandle, handle, extras, videoState, null, false, null, null); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
public ConnectionRequest( |
| 228 |
PhoneAccountHandle accountHandle, |
| 229 |
Uri handle, |
| 230 |
Bundle extras, |
| 231 |
int videoState, |
| 232 |
String telecomCallId, |
| 233 |
boolean shouldShowIncomingCallUi) { |
| 234 |
this(accountHandle, handle, extras, videoState, telecomCallId, |
| 235 |
shouldShowIncomingCallUi, null, null); |
| 236 |
} |
| 237 |
|
| 238 |
private ConnectionRequest( |
| 239 |
PhoneAccountHandle accountHandle, |
| 240 |
Uri handle, |
| 241 |
Bundle extras, |
| 242 |
int videoState, |
| 243 |
String telecomCallId, |
| 244 |
boolean shouldShowIncomingCallUi, |
| 245 |
ParcelFileDescriptor rttPipeFromInCall, |
| 246 |
ParcelFileDescriptor rttPipeToInCall) { |
| 247 |
this(accountHandle, handle, extras, videoState, telecomCallId, |
| 248 |
shouldShowIncomingCallUi, rttPipeFromInCall, rttPipeToInCall, null, false); |
| 249 |
} |
| 250 |
|
| 251 |
private ConnectionRequest( |
| 252 |
PhoneAccountHandle accountHandle, |
| 253 |
Uri handle, |
| 254 |
Bundle extras, |
| 255 |
int videoState, |
| 256 |
String telecomCallId, |
| 257 |
boolean shouldShowIncomingCallUi, |
| 258 |
ParcelFileDescriptor rttPipeFromInCall, |
| 259 |
ParcelFileDescriptor rttPipeToInCall, |
| 260 |
List<Uri> participants, |
| 261 |
boolean isAdhocConference) { |
| 262 |
mAccountHandle = accountHandle; |
| 263 |
mAddress = handle; |
| 264 |
mExtras = extras; |
| 265 |
mVideoState = videoState; |
| 266 |
mTelecomCallId = telecomCallId; |
| 267 |
mShouldShowIncomingCallUi = shouldShowIncomingCallUi; |
| 268 |
mRttPipeFromInCall = rttPipeFromInCall; |
| 269 |
mRttPipeToInCall = rttPipeToInCall; |
| 270 |
mParticipants = participants; |
| 271 |
mIsAdhocConference = isAdhocConference; |
| 272 |
} |
| 273 |
|
| 274 |
private ConnectionRequest(Parcel in) { |
| 275 |
mAccountHandle = in.readParcelable(getClass().getClassLoader(), android.telecom.PhoneAccountHandle.class); |
| 276 |
mAddress = in.readParcelable(getClass().getClassLoader(), android.net.Uri.class); |
| 277 |
mExtras = in.readParcelable(getClass().getClassLoader(), android.os.Bundle.class); |
| 278 |
mVideoState = in.readInt(); |
| 279 |
mTelecomCallId = in.readString(); |
| 280 |
mShouldShowIncomingCallUi = in.readInt() == 1; |
| 281 |
mRttPipeFromInCall = in.readParcelable(getClass().getClassLoader(), android.os.ParcelFileDescriptor.class); |
| 282 |
mRttPipeToInCall = in.readParcelable(getClass().getClassLoader(), android.os.ParcelFileDescriptor.class); |
| 283 |
|
| 284 |
mParticipants = new ArrayList<Uri>(); |
| 285 |
in.readList(mParticipants, getClass().getClassLoader(), android.net.Uri.class); |
| 286 |
|
| 287 |
mIsAdhocConference = in.readInt() == 1; |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
public PhoneAccountHandle getAccountHandle() { return mAccountHandle; } |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
public Uri getAddress() { return mAddress; } |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
public @Nullable List<Uri> getParticipants() { return mParticipants; } |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
public Bundle getExtras() { return mExtras; } |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
public int getVideoState() { |
| 322 |
return mVideoState; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
@SystemApi |
| 332 |
public @Nullable String getTelecomCallId() { |
| 333 |
return mTelecomCallId; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
public boolean shouldShowIncomingCallUi() { |
| 345 |
return mShouldShowIncomingCallUi; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
public boolean isAdhocConferenceCall() { |
| 352 |
return mIsAdhocConference; |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
public ParcelFileDescriptor getRttPipeToInCall() { |
| 366 |
return mRttPipeToInCall; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
public ParcelFileDescriptor getRttPipeFromInCall() { |
| 381 |
return mRttPipeFromInCall; |
| 382 |
} |
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
public Connection.RttTextStream getRttTextStream() { |
| 391 |
if (isRequestingRtt()) { |
| 392 |
if (mRttTextStream == null) { |
| 393 |
mRttTextStream = new Connection.RttTextStream(mRttPipeToInCall, mRttPipeFromInCall); |
| 394 |
} |
| 395 |
return mRttTextStream; |
| 396 |
} else { |
| 397 |
return null; |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
public boolean isRequestingRtt() { |
| 406 |
return mRttPipeFromInCall != null && mRttPipeToInCall != null; |
| 407 |
} |
| 408 |
|
| 409 |
@Override |
| 410 |
public String toString() { |
| 411 |
return String.format("ConnectionRequest %s %s isAdhocConf: %s", |
| 412 |
mAddress == null |
| 413 |
? Uri.EMPTY |
| 414 |
: Connection.toLogSafePhoneNumber(mAddress.toString()), |
| 415 |
bundleToString(mExtras), |
| 416 |
isAdhocConferenceCall() ? "Y" : "N"); |
| 417 |
} |
| 418 |
|
| 419 |
private static String bundleToString(Bundle extras){ |
| 420 |
if (extras == null) { |
| 421 |
return ""; |
| 422 |
} |
| 423 |
StringBuilder sb = new StringBuilder(); |
| 424 |
sb.append("Bundle["); |
| 425 |
for (String key : extras.keySet()) { |
| 426 |
sb.append(key); |
| 427 |
sb.append("="); |
| 428 |
switch (key) { |
| 429 |
case TelecomManager.EXTRA_INCOMING_CALL_ADDRESS: |
| 430 |
case TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE: |
| 431 |
sb.append(Log.pii(extras.get(key))); |
| 432 |
break; |
| 433 |
default: |
| 434 |
sb.append(extras.get(key)); |
| 435 |
break; |
| 436 |
} |
| 437 |
sb.append(", "); |
| 438 |
} |
| 439 |
sb.append("]"); |
| 440 |
return sb.toString(); |
| 441 |
} |
| 442 |
|
| 443 |
public static final @android.annotation.NonNull Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () { |
| 444 |
@Override |
| 445 |
public ConnectionRequest createFromParcel(Parcel source) { |
| 446 |
return new ConnectionRequest(source); |
| 447 |
} |
| 448 |
|
| 449 |
@Override |
| 450 |
public ConnectionRequest[] newArray(int size) { |
| 451 |
return new ConnectionRequest[size]; |
| 452 |
} |
| 453 |
}; |
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
@Override |
| 459 |
public int describeContents() { |
| 460 |
return 0; |
| 461 |
} |
| 462 |
|
| 463 |
@Override |
| 464 |
public void writeToParcel(Parcel destination, int flags) { |
| 465 |
destination.writeParcelable(mAccountHandle, 0); |
| 466 |
destination.writeParcelable(mAddress, 0); |
| 467 |
destination.writeParcelable(mExtras, 0); |
| 468 |
destination.writeInt(mVideoState); |
| 469 |
destination.writeString(mTelecomCallId); |
| 470 |
destination.writeInt(mShouldShowIncomingCallUi ? 1 : 0); |
| 471 |
destination.writeParcelable(mRttPipeFromInCall, 0); |
| 472 |
destination.writeParcelable(mRttPipeToInCall, 0); |
| 473 |
destination.writeList(mParticipants); |
| 474 |
destination.writeInt(mIsAdhocConference ? 1 : 0); |
| 475 |
} |
| 476 |
} |