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