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 private final String mTelecomCallId; 36 37 /** 38 * @param accountHandle The accountHandle which should be used to place the call. 39 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect. 40 * @param extras Application-specific extra data. 41 */ 42 public ConnectionRequest( 43 PhoneAccountHandle accountHandle, 44 Uri handle, 45 Bundle extras) { 46 this(accountHandle, handle, extras, VideoProfile.STATE_AUDIO_ONLY, null); 47 } 48 49 /** 50 * @param accountHandle The accountHandle which should be used to place the call. 51 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect. 52 * @param extras Application-specific extra data. 53 * @param videoState Determines the video state for the connection. 54 */ 55 public ConnectionRequest( 56 PhoneAccountHandle accountHandle, 57 Uri handle, 58 Bundle extras, 59 int videoState) { 60 this(accountHandle, handle, extras, videoState, null); 61 } 62 63 /** 64 * @param accountHandle The accountHandle which should be used to place the call. 65 * @param handle The handle (e.g., phone number) to which the {@link Connection} is to connect. 66 * @param extras Application-specific extra data. 67 * @param videoState Determines the video state for the connection. 68 * @param telecomCallId The telecom call ID. 69 * @hide 70 */ 71 public ConnectionRequest( 72 PhoneAccountHandle accountHandle, 73 Uri handle, 74 Bundle extras, 75 int videoState, 76 String telecomCallId) { 77 mAccountHandle = accountHandle; 78 mAddress = handle; 79 mExtras = extras; 80 mVideoState = videoState; 81 mTelecomCallId = telecomCallId; 82 } 83 84 private ConnectionRequest(Parcel in) { 85 mAccountHandle = in.readParcelable(getClass().getClassLoader()); 86 mAddress = in.readParcelable(getClass().getClassLoader()); 87 mExtras = in.readParcelable(getClass().getClassLoader()); 88 mVideoState = in.readInt(); 89 mTelecomCallId = in.readString(); 90 } 91 92 /** 93 * The account which should be used to place the call. 94 */ 95 public PhoneAccountHandle getAccountHandle() { return mAccountHandle; } 96 97 /** 98 * The handle (e.g., phone number) to which the {@link Connection} is to connect. 99 */ 100 public Uri getAddress() { return mAddress; } 101 102 /** 103 * Application-specific extra data. Used for passing back information from an incoming 104 * call {@code Intent}, and for any proprietary extensions arranged between a client 105 * and servant {@code ConnectionService} which agree on a vocabulary for such data. 106 */ 107 public Bundle getExtras() { return mExtras; } 108 109 /** 110 * Describes the video states supported by the client requesting the connection. 111 * Valid values: {@link VideoProfile#STATE_AUDIO_ONLY}, 112 * {@link VideoProfile#STATE_BIDIRECTIONAL}, 113 * {@link VideoProfile#STATE_TX_ENABLED}, 114 * {@link VideoProfile#STATE_RX_ENABLED}. 115 * 116 * @return The video state for the connection. 117 */ 118 public int getVideoState() { 119 return mVideoState; 120 } 121 122 /** 123 * Returns the internal Telecom ID associated with the connection request. 124 * 125 * @return The Telecom ID. 126 * @hide 127 */ 128 public String getTelecomCallId() { 129 return mTelecomCallId; 130 } 131 132 @Override 133 public String toString() { 134 return String.format("ConnectionRequest %s %s", 135 mAddress == null 136 ? Uri.EMPTY 137 : Connection.toLogSafePhoneNumber(mAddress.toString()), 138 mExtras == null ? "" : mExtras); 139 } 140 141 public static final Creator<ConnectionRequest> CREATOR = new Creator<ConnectionRequest> () { 142 @Override 143 public ConnectionRequest createFromParcel(Parcel source) { 144 return new ConnectionRequest(source); 145 } 146 147 @Override 148 public ConnectionRequest[] newArray(int size) { 149 return new ConnectionRequest[size]; 150 } 151 }; 152 153 /** 154 * {@inheritDoc} 155 */ 156 @Override 157 public int describeContents() { 158 return 0; 159 } 160 161 @Override 162 public void writeToParcel(Parcel destination, int flags) { 163 destination.writeParcelable(mAccountHandle, 0); 164 destination.writeParcelable(mAddress, 0); 165 destination.writeParcelable(mExtras, 0); 166 destination.writeInt(mVideoState); 167 destination.writeString(mTelecomCallId); 168 } 169} 170