ConnectionRequest.java revision 6b3714939f31779d746c4f293cd55d5a9b09a0b9
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 17package android.telecom; 18 19import android.net.Uri; 20import android.os.Bundle; 21import android.os.Parcel; 22import android.os.Parcelable; 23 24/** 25 * Simple data container encapsulating a request to some entity to 26 * create a new {@link Connection}. 27 */ 28public final class ConnectionRequest implements Parcelable { 29 30 // TODO: Token to limit recursive invocations 31 private final PhoneAccountHandle mAccountHandle; 32 private final Uri mAddress; 33 private final Bundle mExtras; 34 private final int mVideoState; 35 36 /** 37 * @param accountHandle The accountHandle which should be used to place the call. 38 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect. 39 * @param extras Application-specific extra data. 40 */ 41 public ConnectionRequest( 42 PhoneAccountHandle accountHandle, 43 Uri handle, 44 Bundle extras) { 45 this(accountHandle, handle, extras, VideoProfile.VideoState.AUDIO_ONLY); 46 } 47 48 /** 49 * @param accountHandle The accountHandle which should be used to place the call. 50 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect. 51 * @param extras Application-specific extra data. 52 * @param videoState Determines the video state for the connection. 53 */ 54 public ConnectionRequest( 55 PhoneAccountHandle accountHandle, 56 Uri handle, 57 Bundle extras, 58 int videoState) { 59 mAccountHandle = accountHandle; 60 mAddress = handle; 61 mExtras = extras; 62 mVideoState = videoState; 63 } 64 65 private ConnectionRequest(Parcel in) { 66 mAccountHandle = in.readParcelable(getClass().getClassLoader()); 67 mAddress = in.readParcelable(getClass().getClassLoader()); 68 mExtras = in.readParcelable(getClass().getClassLoader()); 69 mVideoState = in.readInt(); 70 } 71 72 /** 73 * The account which should be used to place the call. 74 */ 75 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; } 76 77 /** 78 * The handle (e.g., phone number) to which the {@link Connection} is to connect. 79 */ 80 public Uri getAddress() { return mAddress; } 81 82 /** 83 * Application-specific extra data. Used for passing back information from an incoming 84 * call {@code Intent}, and for any proprietary extensions arranged between a client 85 * and servant {@code ConnectionService} which agree on a vocabulary for such data. 86 */ 87 public Bundle getExtras() { return mExtras; } 88 89 /** 90 * Describes the video states supported by the client requesting the connection. 91 * Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, 92 * {@link VideoProfile.VideoState#BIDIRECTIONAL}, 93 * {@link VideoProfile.VideoState#TX_ENABLED}, 94 * {@link VideoProfile.VideoState#RX_ENABLED}. 95 * 96 * @return The video state for the connection. 97 */ 98 public int getVideoState() { 99 return mVideoState; 100 } 101 102 @Override 103 public String toString() { 104 return String.format("ConnectionRequest %s %s", 105 mAddress == null 106 ? Uri.EMPTY 107 : Connection.toLogSafePhoneNumber(mAddress.toString()), 108 mExtras == null ? "" : mExtras); 109 } 110 111 public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () { 112 @Override 113 public ConnectionRequest createFromParcel(Parcel source) { 114 return new ConnectionRequest(source); 115 } 116 117 @Override 118 public ConnectionRequest[] newArray(int size) { 119 return new ConnectionRequest[size]; 120 } 121 }; 122 123 /** 124 * {@inheritDoc} 125 */ 126 @Override 127 public int describeContents() { 128 return 0; 129 } 130 131 @Override 132 public void writeToParcel(Parcel destination, int flags) { 133 destination.writeParcelable(mAccountHandle, 0); 134 destination.writeParcelable(mAddress, 0); 135 destination.writeParcelable(mExtras, 0); 136 destination.writeInt(mVideoState); 137 } 138} 139